In this exercise you must create a program that deals with


THIS IS A FIRST SEMESTER ELECTRICAL AND COMPUTER ENGINEERING COURSES' PROGRAMMING ASSIGNMENT TO BE DONE IN THE C
PROGRAMMING LANGUAGE.
This exercise involves:

1. Structures, arrays and strings (char arrays) with dynamic memory allocation (use of malloc)
2. Functions from libraries and function defined by the user, including recursive ones.
3. Reading and writing text files.

Description
In this exercise you must create a program that deals with material information so as to calculate the supply need for raw materials and to organize( program ) the production of intermediate and final products in order to satisfy some orders. The distinction and categorization of materials follows the rules mentioned:

• Raw materials: Purchased from external suppliers
• Intermediate products: Produced by other intermediate products and/or raw materials
• Final products: Destined for sale but NOT for the production of others

Every product (intermediate or final) has a specific synthesis that relates to the types of raw materials and/or intermediate products necessitated for its construction. The synthesis of a product also includes the quantity of every ingredient needed for the construction of one unit of product.

Your program must read an input file that includes info for every item type (materials and products).

The file will also have information for uncompleted/waiting orders of the final products. All this information will be saved using arrays of structures (struct) in the main memory which you'll design and implem ment.

The user will have the choice to view the available items and also the ingredients of an item of his desire. In addition, he we also have the chance to get, in an output file, information regarding every type of item (quantity of available units and quantity of necessitated units for the completion of orders).

Format of the input file (datain.txt)

The input file has two parts. In the first part: the types of the items and in the second part: uncompleted/waiting orders. Every part begins with a line that includes an unsigned integer that relates to the quantity of lines as depicted below:
...

...
Every line of the first part relates to an item type and includes the elements below:
1. The number code of the type (unsigned integer).
2. The name of the type (string without sp aces).
3. The quantity of units of the item type in storage (unsigned integer).
4. The quantity of ingredient item types that make up the item (unsigned integer). If the item is a raw material the quantity equals zero (0).
5. As long as the quantity n of ingredient item types (element 4) is greater than zero (0), the synthesis is also given as a series of n pairs. The first member of every pair is the number code (unsigned integer) of an item type needed for the construct of the synthetic item ( for example: a Car whose synthesis consists of glass, wheels and engine is a synthetic item ). The second member is the quantity of units (unsigned integer) of the type that are needed for the synthesis of one unit of a synthetic item.

(Next, an input file example is given). This example describes the raw materials, the inter products and the final product for car manufacturing procedure. In this example there is only one type of final product. Your program must also function correctly and analogously for the possibility that the input file contains more ( than 1 ) types of final products. The only type of final products
included in this example is the one named Car.

Intermediate products are of two types ( Wheel and Engine). The raw materials are of five types ( Glass, Tire, Rim, Piston, Belt).
The synthesis of the final product and the intermediate products can be depicted in the above diagram. In this diagram, on the left of the name of every item type is its number code. The numbers on the arrows show how many units are necessary for product synthesis. For example, for the synthesis of an Engine, 4 Pistons are required and 2 Belts. The numbers in the small embedded on the upper-left describe the available units i n storage. In this particular example, every one of the raw material types and intermediate products is used for the synthesis of only one type of product. Your program must function even whenever there is a possibility that some of the raw materials or intermediate products are used to synthesize more than one type of products like in the additional example ( at the end ) The first part of the input file contains the information of the above diagram and also the quantity of available units of every item type in storage. For example, the line that describes the type of items Car is:

8 Car 5 3 6 4 7 1 1 6
Meaning, this type has a number code 8, name Car, there are 5 available units in storage and for the synthesis of one unit of this type 3 other item types are required. Specifically, 4 units of type with number code 6, 1 unit of type with number code 7 and 6 units of type with number

code 1. The rest of the lines of the first part of the file are analogously interpreted.
The second part of the file includes information for uncompleted/waiting orders. More specifically, there is an uncompleted/waiting order of 10 units of type with number code 8.

Output format (dataout.txt)

The output file begins with a line that contains the total quantity of lines that are to be followed. Next, it includes a line for every item type. Every such line describes one item type and contains:
• the number code of item types
• its name
• the quantity of units available in storage,
• the quantity of units required for the completion of the uncompleted/waiting orders (based upon information for its synthesis).
Number of material types:
/ - units in stock - orders> units needed.
... Output example (dataout.txt):

Number of material types: 8

1/Glass - 3 units in stock - 60 units needed.
2/Tire - 5 units in stock - 40 units needed.
3/Rim - 3 units in stock - 40 units needed.
4/Piston - 3 units in stock - 40 units needed.
5/Belt - 2 units in stock - 20 units need 6/Wheel - 10 units in stock - 40 units needed.
7/Engine - 2 units in stock - 10 units needed.
8/Car - 5 units in stock - 10 units needed
Structures and arrays
The first step for the solution of this exercise is to write the appropriate structures (struct). After that you must read the contents of the input file and save them in appropriate arrays of structures in memory which will have to be created dynamically. The name of the input file must be datain.txt. Use dynamic memory allocation (using malloc) and for the names
of item types.

To help out in writing the necessary structures and arrays in your compiler, we mgive you this diagram (on your left). Their interconnections are applied using pointers. This diagram depicts a part of the input file example. The structure for every type of item
contains, besides others, the 'needed' field. This helps the calculation of the needed units of every type of item for the completion of the uncompleted/waiting orders: Firstly, 'needed' has the value zero (0) for every type of item except from final products for which there are
uncompleted/waiting orders ( 10 units of type Car in the example diagram ).

Use a recursive function wh hich, given one type of item with a known quantity of required units, will calculate the quantity of the required units for its ingredient items, nas long as it is not a raw material.How the program will work

Your program must support:
1. Reading an input file meeting the credentials mentioned above. The file must be named datain.txt.
2. Printing on screen all item types. Next to every name must appear the quantity that is available in storage.
3. Printing on screen the synthesis of one item type which must determined by the user through its name. Next to every name must appear the quantity available in storage.
4. Creating an output file meeting the credentials mentioned above. The file must be named dataout.txt

The program must prompt the user with the appropriate choice menu for the implementation of the above workings, plus a choice for terminating. For the implementation of the program it is mandatory that you create your own functions and to use recursion for the calculation of the  necessary units of item types. ( global ), ( extern ) and ( static ): NOT A

Request for Solution File

Ask an Expert for Answer!!
Basic Computer Science: In this exercise you must create a program that deals with
Reference No:- TGS01246000

Expected delivery within 24 Hours