Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C++ please make sure that the output is the same and the code works! Thank you. HW2 (Graded out of 100) Write a program

In C++ please make sure that the output is the same and the code works! Thank you.

HW2 (Graded out of 100)

Write a program that reads grocery product records from a file, then store the information in parallel arrays. Each grocery product record consists of the following 5 items: - PLU code: Product Look Up Code. Unique for each product, stored as a string. - Product Name, stored as a string - Product Sales Type: 0 = per unit, 1 = per pound - Price per Pound or price per unit, - Current Inventory Level (pounds or units). Below is an example of file content. In this example, there are four records, and each line corresponds to a record.

A001 Apples 1 0.90 21 A002 Peaches 1 0.82 11 A006 Avocados 0 1.54 27 A008 Mangos 0 1.69 19 

Your program should: Read the file to determine the number of records in the file Dynamically allocate the necessary parallel arrays, with the appropriate size, and populate the arrays with the items from the file. There should be one array for each item in the product record. Then the program should print the inventory as read from the file, and loops over displaying a menu for the user to choose from: 1 Checkout 2 Print current inventory 3 Quit

Checkout If the user chooses checkout, the user can purchase multiple products in each checkout. The user is asked to enter the PLU code, then the quantity (weight or # of units, depending on the sales type) for each product. The program keeps up with the total cost ($). The user can enter 0 for a PLU to indicate the end of checkout. The program then displays the total price, and displays the menu again. The program should do input validation (quantity must be > 0) and ask the user to reenter if the input is invalid. Your program should make sure the quantity bought is not more than the inventory level. For example, if the user wants to buy 10 apples, but only 5 apples are in the inventory, the program will sell only 5 apples. The inventory level should be automatically updated with each purchase.

Print current inventory If the user chooses this option, the program should print the inventory, updated with all the purchases made so far.

Quit If the user chooses this option, the program exits the menu loop and automatically print the updated inventory, which is the current inventory. Then the program prints Exiting and terminates.

1. Additional Requirements Make sure you meet all the requirements to avoid losing points

a) Functions You are required to implement your program with these functions. You may implement more functions to make your program more modular. readInventory: This function reads from a file and populates parallel arrays. It takes as arguments the file name, and the pointers to the parallel arrays, as well as the number of records. It returns true if file open is successful, false otherwise. The parameters in the parameter list must be in this order: File name Number of records Pointer to PLU array Pointer to price array Pointer to product name array Pointer to product sales type array Pointer to inventory array

You need to follow the above conventions (function name, parameter list, return type) to pass the unit test. Note: The function should close the file when done.

checkout: This function does the checkout. It takes as arguments the pointers to the parallel arrays, and the number of records in the inventory. It reads the PLU and quantity from the user, updates the data in the arrays to reflect the user's purchase, does input validation on the purchased quantity (> 0), asks the user to reenter as long as the quantity is

You need to follow the above conventions (function name, parameter list, return type) to pass the unit test.

b) Dynamic memory management Your program should release all the dynamic memory at the end.

c) Outline of main

Prompt the user for the file name. Read the file to determine the number of records in the file. Close the file Dynamically allocate the parallel arrays to hold the product data items. The array sizes should be equal to the number of records in the file Call readInventory to populate the arrays. You may assume the data records in the file are correct (no need to do input validation) Display menu and get users choice. Ask the user to reenter as long as the choice is invalid (assume the user only types an integer) While (users choice is not Quit) Call checkout if user chooses Checkout Print current inventory if user chooses Print current inventory Display menu and get users choice. Ask the user to reenter as long as the choice is invalid (assume the user only types an integer) End while Print current inventory Print Exiting  and terminate 

d) Style Make sure you follow the style requirements, especially regarding the comment header for functions, and use function prototypes for all your functions, to avoid losing points.

2. Grading criteria

Source code inspection (grader) *Style: 10 points (refer to the Homework Notes for the style requirements) *Required: Use function prototypes for all functions. 10 points will be deducted for non conformance *Required: the program should dynamically allocate memory for parallel arrays, and the array sizes should be equal to the number of records in the file. 20 points will be deducted for non conformance *Required dynamic memory release: If any of the arrays is not released at the end, 10 points will be deducted *Required use of pointers in parameter lists: If there is one or more square bracket ([ ]) in the parameter list of readInventory or checkout, 20 points will be deducted

Code compilation and execution (zylabs) *Test-1: Print inventory read from file and print menu Output starts like output-1: 15 points. Your program will read from the productData1.txt file. To test on an external IDE, for the users keyboard input, you may copy and paste from test1-keyboard-input *Test-2: Read users choice with input validation - Output contains output-2: 15 points. Your program will read from the productData2.txt file. To test on an external IDE, for the users keyboard input, you may copy and paste from test2-keyboard-input *Test-3: Print updated inventory when the user chooses quit Output ends like output-3: 20 points. Your program will read from the productData3.txt file. To test on an external IDE, for the users keyboard input, you may copy and paste from test3-keyboard-input *Test-4: readInventory unit test: 20 points *Test-5: checkout unit test: 20 points

3. Screenshots

Here are the expected screenshots when the program is executed on an external IDE.

Enter the file name: productData1.txt There are 6 records in the file Inventory read from file ------------------------ PLU: A001, Apples , type: 1, unit price: 0.9, inventory: 20 PLU: A002, Peaches , type: 1, unit price: 0.82, inventory: 110 PLU: A004, Oranges , type: 1, unit price: 0.98, inventory: 21 PLU: A006, Avocados , type: 0, unit price: 1.54, inventory: 27 PLU: A008, Mangos , type: 0, unit price: 1.69, inventory: 9 PLU: A009, Strawberries_Case, type: 0, unit price: 12.5, inventory: 8 1 - Checkout 2 - Print current inventory 3 - Quit 

Output-1

1 - Checkout 2 - Print current inventory 3  Quit 1 Enter PLU, 0 if done: A001 Enter quantity: 0 Quantity must be positive, reenter: -2 Quantity must be positive, reenter: 22 Enter PLU, 0 if done: 4260 Enter quantity: 20 PLU not found Enter PLU, 0 if done: 4261 Enter quantity: 100 Enter PLU, 0 if done: 0 Total is: $67.9 1 - Checkout 2 - Print current inventory 3  Quit 2 Current inventory ----------------- PLU: A001, Apples , type: 1, unit price: 0.9, inventory: 0 PLU: A002, Peaches , type: 1, unit price: 0.82, inventory: 11 PLU: A004, Oranges , type: 1, unit price: 0.98, inventory: 31 PLU: A006, Avocados , type: 0, unit price: 1.54, inventory: 27 PLU: A008, Mangos , type: 0, unit price: 1.69, inventory: 19 PLU: A009, Strawberries_Case, type: 0, unit price: 12.5, inventory: 8 PLU: 4261, Rice_1_LB_Bag , type: 0, unit price: 0.49, inventory: 7 1 - Checkout 2 - Print current inventory 3 - Quit 1 Enter PLU, 0 if done: A008 Enter quantity: 10 Enter PLU, 0 if done: A004 Enter quantity: 20 Enter PLU, 0 if done: 0 Total is: $36.5 1 - Checkout 2 - Print current inventory 3 - Quit 5 Invalid choice, reenter: 4 Invalid choice, reenter: 3 

Output-2

1 - Checkout 2 - Print current inventory 3  Quit 3 Updated inventory ----------------- PLU: A001, Apples , type: 1, unit price: 0.9, inventory: 21 PLU: A002, Peaches , type: 1, unit price: 0.82, inventory: 11 PLU: A004, Oranges , type: 1, unit price: 0.98, inventory: 31 PLU: A006, Avocados , type: 0, unit price: 1.54, inventory: 0 PLU: A008, Mangos , type: 0, unit price: 1.69, inventory: 9 PLU: A009, Strawberries_Case, type: 0, unit price: 12.5, inventory: 8 PLU: 4261, Rice_1_LB_Bag , type: 0, unit price: 0.49, inventory: 107 PLU: A020, Kumquats , type: 1, unit price: 1.2, inventory: 50 Exitingimage text in transcribed
File Edit Format View Help A001 Apples 10.9020 A002 Peaches 10.82110 A004 Oranges 1.9821 A006 Avocados 01.5427 A008 Mangos 01.699 A009 Strawberries_Case 012.508

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions