Question
Write a C program to automate the online purchasing of product items. The online store has a data file which stores information about all the
Write a C program to automate the online purchasing of product items. The online store has a data file which stores information about all the products that exist in the online store. For example, the "store.txt" file stores many products, where each product has the following information: 1. Product ID: an integer number that represents a product. 2. Quantity: an integer number that represents the number of items for this product in the online store. 3. Unit price: the price of each item of this product (real number of type double). An example of "store.txt" file is shown below: Each product appears on a separate line and consists of a product ID, quantity, and unit price. The product lines can appear in any order. You program should read all the products in the "store.txt" file into three different arrays. It should also count the total number of products in the file. Limit the maximum number of products and the size of the three arrays to 100. If there are more 100 products in the file then stop reading when the count reaches 100. Your program should process online purchase requests placed by customers and generate online bills. An online purchase request is a file having the product ID and the quantity purchased. An example of an online purchase request is the file "order.txt", as shown below: Your program should generate a new file, for example, "bill.txt" for "order.txt" as follows: 1234 5 23.50 1235 10 19.20 1462 9 75.00 1477 26 15.50 1812 97 0.99 1235 3 1234 8 1900 4 1477 2 Product Quantity Unit Price Price ---------- ------------ ------------- ------- 1235 3 19.20 57.60 1234 5 23.50 117.50 1900 Sorry, product does not exist 1477 2 15.50 31.00 Total Price = 206.10 Sample file: "order.txt" Sample file: "bill.txt" Page 2 of 3 If the quantity in the store is less than the quantity in the order (for example, quantity of product 1234 is only 5 in the store) then limit the quantity in the bill to that in the store. If a product number does not appear in the store (for example, product 1900) then write an appropriate message in the bill, as shown above. After processing a bill, your program should update the quantities of all the products in the store after processing a purchase order. The new updated "store.txt" file is shown below: Your program should be menu driven and able to process more than one order and produce more than one bill. A sample run of the program is shown below: Online Purchase Program (written by your name) a) Read a store data file b) Read an order and generate a bill c) Exit program Enter choice: If the user chooses a then ask the user to enter the name of the store data file: Enter the name of the store data file: store.txt File store.txt was opened successfully: 5 products are read If the file "store.txt" cannot be opened (does not exist) then the program should display an error message "Failed to open store.txt", and then redisplay the menu. If the file "store.txt" contains invalid data (such as text) then the program should stop reading at the first line that contains invalid data. If there are no errors, it should continue reading data until the end-of-file is reached or at most 100 products are read and the three arrays are full. If the user chooses a more than once and enters a different filename, then the data from the file that was last entered should be read and should replace the data that was previously read. Write a function read_store_data that opens, reads data from a file into three arrays, and counts the number of products. The function should return the count of products that were read. This function can be called more than once on different store files as long as the user enters choice a. If the user choice is b then ask the user to enter the names of the order and bill data files. For example, "order.txt" can be used as an input file, while "bill.txt" can be used as an output file: Enter the name of the order file: order.txt Enter the name of the bill file: bill.txt 1234 0 23.50 1235 7 19.20 1462 9 75.00 1477 24 15.50 1812 97 0.99 Updated file: "store.txt" Page 3 of 3 Write a function read_order that opens an order file and reads its data into two arrays of at most 100 elements. The first array contains the IDs of the products to be ordered. The second array contains the quantity to be ordered. This function should return the count of products to be ordered. If the file fails to open the order file then an error message should appear and the menu should be displayed again. Failed to open order.txt Otherwise, this function should display a message indicating that the order was read successfully: File order.txt was opened successfully: 4 orders were read Write a function process_order that performs the search of products and the updates on the required arrays to perform a given order. You may use additional arrays if needed. Write a function generate_bill that produces an output bill file, such as "bill.txt", in the format shown above. After execution this function, your program should display on the screen a message indicating that an output bill file is generated. File bill.txt is generated Write a function store_update to update the store file, such as "store.txt", that contains the updated quantities of the products as shown above. The new store file should replace the old one after processing each order. File store.txt is updated The menu should be redisplayed until the user enters choice c (Exit Program). Any invalid choice should be detected and an error message should be displayed.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started