[Solved] CSE1142 Assignment # 4- Market simulator

$25

File Name: CSE1142_Assignment_#_4-_Market_simulator.zip
File Size: 376.8 KB

SKU: [Solved] CSE1142 Assignment # 4- Market simulator Category: Tag:
5/5 - (1 vote)

In this homework, you will simulate a market. The market buys food from a set of firms. It keeps track of firms and bought food in txt files which makes it difficult to store and manage records systematically. Therefore, the owner of the market needs a program which can read txt files and store/manage information as he/she wants.

Your program should read two files: firms.txt and products.txt. The details of both files are given below.

  1. Each firm with a unique id and name is recorded in the firms.txt file and format of the file is given below:

[id of the firm] [name of the firm] For example; ▪ 101 eti

▪ 102 ulker etc.

  1. You will read id and name of the firms from the txt file and store in a linked list. To create the linked list, you will use the Firm struct with the following data fields:
    • firmID (int) : id of the firm
    • firmName (char array of size 100) : name of the firm struct Firm *nextfirm : pointer to next firm.
    • Typedef struct Firm to firm.
  2. To read the file you will write a function with name

firm *readFirms(char filename[])

filename[] : name of the file to be read

This function should be called by your main function with the firms.txt file.

In this function, you will read the file whose name is given as argument filename.

You will create a linked list of the firms by using firm struct. Each time you read a firm from the file you will create a firm struct by using malloc and store read values in it.

Then, you should add it as a new member to the linked list.

While adding a new member to the linked list, id fields of the firms should be arranged in descending order. For example,

▪ Firstly, you read 101 eti and this firm becomes the first element of the linked list.

▪ Secondly, you read 300 ulker. At this point, ulker becomes the first element of the linked list and eti becomes the second element of the linked list because of having smaller id than ulker.

▪ Then, if you read 273 pinar, pinar should be placed between ulker and eti. Consequently, ulker becomes the first, pinar becomes the second and eti becomes the third element of the linked list.

This function returns a pointer that points to the beginning of the linked list.

  1. After constructing the linked list of the firms, you will print all firms in the linked list and their alldata fields by using printFirms

void printFirms(firm *firmptr)

  • This function takes a pointer of type firm (firmptr) and prints all firms and their all data fields in the linked list pointed by
  • For example, if the content of the firms.txt file is as given below

101 eti

300 superfresh

502 pinar 91 banvit then, the output is

502 pinar

300 superfresh

101 eti

91 banvit

  1. Information about bought food is stored in txt file and format of the file is given below: [name of the firm] [name of the food] [type of the food] [amount of food]
    • For example, if the market buys 5 packages of a food of type biscuit with name burcak from firm eti, this purchase is written in the file as

eti burcak biscuit 5

  • You will read the products from the txt file and store read values in a linked list.
  1. To create a linked list, you will use the FoodStock struct FoodStock contains another struct inside it which is struct Food. Food will be used to keep name and expire date of each food since they are kept by the market also. Expire date will be stored in day, month and year format. Create a Food struct with following data fields :

prod_name (char array of size 400) : name of the food

exp_day (int) : day of expire date

exp_month (int) : month of expire date exp_year (int) : year of the expire date Typedef struct Food to food.

  1. Content of the FoodStock struct is given below
    • struct Food ffood : struct to store information about a specific food struct FoodStock *nextfood : pointer to the next food Typedef struct FoodStock to foodstock.
  1. c) To read the txt file you will use the readFoods function. This function should be called by your main function. foodstock *readFoods(char filename[])
  • filename[] : name of the file to be read
  • In this function you will create a linked list of read products. For example,

Firstly, you read eti burcak biscuit 5 from the file. You will create a linked list with 5 foodstock elements (you will use malloc to create structs) and prod_name of these elements will be eti burcak biscuit. For expire date information of each ffood field of foodstock struct, you will assign 2018 or 2019 to exp_year randomly. You will assign 1,2,3 or 4 randomly for exp_month and a number created randomly between 1 and 14 will be assigned to exp_day.

Then, if you read ulker golf ice_cream 4, you will add 4 foodstock elements to the end of the linked list (immediately after the eti burcak biscuits). Each of them will have prod_name of ulker golf ice_cream and you will assign random day, month and year values for the expire date as explained above.

After adding above items, you should have a linked list with 9 foodstock structs.

Each time you read a new food from products.txt file you will add them to the end of the linked list.

You will return a pointer that points to the beginning of the linked list.

  1. To print information about food, you will use the printFood

void printFood(foodstock *foodptr, char filename[])

  • foodptr : pointer to a linked list
  • filename[] : name of the file to which the output will be written.
  • This function reads all elements and their data fields in a linked list pointed by foodptr and writes this information to a txt file whose name is taken as argument
  1. The market periodically controls expired products and expired products should be removed from the list of foods. To remove expired products, you will use the stockOut

foodstock *stockOut(foodstock *foodptr, int day, int month, int year)

  • foodptr : pointer to linked list of foods
  • day, month, year : day, month and year of the expire date according to which the expired foods are detected. These values will be given by the user.
  • For example, if day = 3, month = 1 and year = 2019, the products that have expire date before 3/1/2019 will be deleted from the linked list.
  • Pointer to the new state of the linked list is returned.
  1. In the main function of your program, implement the following scenario.
    • Create a firms pointer of type firm.
    • Read the firms by using the readFirms function from txt file and update the value of firms pointer as the return value of readFirms function.
    • Print firms by using the printFirms
    • Create a stocks pointer of type foodstock.
    • Read the products from the txt file by using the readFoods function and update the value of stocks pointer as the return value of readFoods function.
    • Print the initial situation of the linked list pointed by stocks by calling printFoods function and name of the output file will be initial_stock.txt Print the following message on console display:

Please enter the day, month and year to be checked

Then, take the day, month and year from the user that will be used as the expire date for the stockOut function.

  • Call the stockOut function with stocks pointer and the expire date entered by the user. The updated version of the linked list will be pointed by stocks
  • Print the updated version of the linked list pointed by stocks pointer by using printFoods function and the name of the output file will be final_stock.txt for the second time.
  1. Sample output:
    • Assume that content of the txt file is as given below

101 eti

300 superfresh

502 pinar

91 banvit

  • Assume that content of the txt file is as given below eti burcak biscuit 4 ulker golf ice_cream 2 sutas kaymakli yoghurt 3
  • Your program should print the firms to the screen and requests an expire date from the user as shown below:

Firms :

firm no 502 firm name pinar firm no 300 firm name superfresh firm no 101 firm name eti

firm no 91 firm name banvit

Please enter the day, month and year to be checked:

1 4 2019

  • Content of the txt file will become as shown below eti burcak biscuit EXP : 2/3/2019 eti burcak biscuit EXP : 6/2/2019 eti burcak biscuit EXP : 11/1/2019 eti burcak biscuit EXP : 4/3/2019 ulker golf ice_cream EXP : 7/4/2019 ulker golf ice_cream EXP : 1/1/2018 sutas kaymakli yoghurt EXP : 3/1/2019 sutas kaymakli yoghurt EXP : 1/4/2019 sutas kaymakli yoghurt EXP : 3/3/2018
  • Content of the txt file will become as shown below ulker golf ice_cream EXP : 7/4/2019 sutas kaymakli yoghurt EXP : 1/4/2019

This is a simple scenario to test your implementation. There might be other test cases too. Therefore, please pay attention to use the same function and variable names in your implementations. You can not decrease the number of functions.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] CSE1142 Assignment # 4- Market simulator
$25