Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include #include #include using namespace std; int determineNumRecords(string fname); //function to populate the inventory from file bool readInventory(string fname, string *pluPtr, string *namePtr, int

image text in transcribedimage text in transcribedimage text in transcribed

#include #include #include #include using namespace std; int determineNumRecords(string fname); //function to populate the inventory from file bool readInventory(string fname, string *pluPtr, string *namePtr, int *typePtr, double *pricePtr, int *inventoryPtr, int numRecords); //this function is to does the check out double checkout(string *pluPtr, double *pricePtr, int *inventoryPtr, int numRecords); //function to search the products int searchProduct(string varPLU, string *pluPtr, int numRecords); //Method to diaply the inventory void display(string message, string *pluPtr, string *namePtr, int *typePtr, double *pricePtr, int *inventoryPtr, int numRecords); //The main int main() { //declare the local variables string inputFile; int numOfRecords; string *pluPtr, *namePtr; int *typePtr, *inventoryPtr; double *pricePtr; double totalVal; //take the file name input from user cout > inputFile; //determine the number of records numOfRecords = determineNumRecords(inputFile); //if file open failed if(numOfRecords == -1) cout > userCho; switch(userCho) { case 1: totalVal = checkout(pluPtr, pricePtr, inventoryPtr, numOfRecords); cout

return 0; } //function to determine number of records in the file int determineNumRecords(string fname) { ifstream infile(fname.c_str()); if(infile.fail()) return -1; else { int numRec = 0; string fileLine; while(getline(infile, fileLine)) numRec++; infile.close(); return numRec; } } //function to populate the inventory from file bool readInventory(string fname, string *pluPtr, string *namePtr, int *typePtr, double *pricePtr, int *inventoryPtr, int numRecords) { ifstream infile(fname.c_str()); if(infile.fail()) return false; else { for(int itr = 0; itr > pluPtr[itr] >> namePtr[itr] >> typePtr[itr] >> pricePtr[itr] >> inventoryPtr[itr]; } return true; } } //this function is to does the check out double checkout(string *pluPtr, double *pricePtr, int *inventoryPtr, int numRecords) { string varPLU = ""; int prodQnty; double totalVal = 0;

while(true) { cout > varPLU;

if(varPLU == "0") break;

cout > prodQnty;

while(prodQnty > prodQnty; }

int prodIndex = searchProduct(varPLU, pluPtr, numRecords); if(prodIndex == -1) cout

} cout

Actual Problem:

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 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 Pointer to PLU array Pointer to product name array Pointer to product sales type array Pointer to price array Pointer to inventory array Number of records

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 when it terminates.

c) Outline of main

Prompt the user for the file name. Determine the number of records in the file Dynamically allocate the parallel arrays of the right size, to hold the product data items 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 

d) Style Make sure you follow the style requirements, especially regarding the comment header for functions, to avoid losing points.

2. Grading criteria

  • Source code inspection (grader) *Style: 5 points (refer to the Homework Notes for the style requirements) *Request dynamic memory allocation for the arrays: 15 points *Release dynamic memory at the end: 5 points
  • Code compilation and execution (zylabs) *Output test-1 - Print inventory read from file and print menu Output starts like output-1: 10 points. Use testInput1.txt, downloadable from zylabs *Output test-2 - Read users choice with input validation - Output contains output-2: 15 points. Use testInput2.txt, downloadable from zylabs *Output test-3 - Print updated inventory when the user chooses quit Output ends like output-3: 20 points. Use testInput3.txt, downloadable from zylabs *Unit test-1 - readInventory: 15 points *Unit test-2 - checkout: 15 points
tocalculate the ar y 2.2. HW2 2.3 damo ths is in C.ar zyBooks My library CE 1337/CS 1337/TE 1337: Compuler Science I hone 2.2: Hw2 ryBooks caalog ) Help/FAQ safan all Output test-3 Output differs. See highlights below Special character legend productData.txt A008 10 Input A006 e name There ar Inventory read from filed PT.: A00, App les PLU: A002, Peaches PTU: A004, Oranges PLU: A006, Avocados PLU: A0C8, Mangos PLU: A009, Strawberries_Case, type: 0, unit price: 12.5, inventory: 8 type: 1, unit price: 0.9, inventory: 21 , type: 1, unit price: 0.82, inventory: 11 , type:, unit price: 0.98, inventory: 31 , type: 0, unit price: 1.51, inventory: 27 , type: 0, unit pricc: 1.69, inventory: 19 Your output ends PLU: 4261, Rice_1_LB_Bag , type: 0, unit price: 0.49, inventory: 10 with CheckouL -Print current invenLorye Quite Ente r PT.t" it done : Rnte r Tuant ity: O lype hene to search zyBooks My library > CE 1337/CS 1337/TE 1337: Cornpuler Science l home > 2.2: HW2 ryBooks caalog ) Help/FAQ safari all , type: unit price: r i nventory: 4: Unit test-1 - readlnventoryn 15/15 Your output Passed 5: Unit test-2 - checkout 0/15 Your unction should retur a total price of $563, but it returned $23 Incorrect value ot inventory at. index 3:40, correct value is 0 Your output Input test file is inputTest.txt The user chose a quantity of 2 and 41 for PT.U DFF, and KTM respectively Failed 5 previous submissions 12:24 PM on 2/1/19 12:11 PM on 2/1/19 12:10 PM on 2/1/19 11:52 AM on 2/1/19 25 75 25 75 15 75 15/75 Viewv View View ViewM O lype hene to search tocalculate the ar y 2.2. HW2 2.3 damo ths is in C.ar zyBooks My library CE 1337/CS 1337/TE 1337: Compuler Science I hone 2.2: Hw2 ryBooks caalog ) Help/FAQ safan all Output test-3 Output differs. See highlights below Special character legend productData.txt A008 10 Input A006 e name There ar Inventory read from filed PT.: A00, App les PLU: A002, Peaches PTU: A004, Oranges PLU: A006, Avocados PLU: A0C8, Mangos PLU: A009, Strawberries_Case, type: 0, unit price: 12.5, inventory: 8 type: 1, unit price: 0.9, inventory: 21 , type: 1, unit price: 0.82, inventory: 11 , type:, unit price: 0.98, inventory: 31 , type: 0, unit price: 1.51, inventory: 27 , type: 0, unit pricc: 1.69, inventory: 19 Your output ends PLU: 4261, Rice_1_LB_Bag , type: 0, unit price: 0.49, inventory: 10 with CheckouL -Print current invenLorye Quite Ente r PT.t" it done : Rnte r Tuant ity: O lype hene to search zyBooks My library > CE 1337/CS 1337/TE 1337: Cornpuler Science l home > 2.2: HW2 ryBooks caalog ) Help/FAQ safari all , type: unit price: r i nventory: 4: Unit test-1 - readlnventoryn 15/15 Your output Passed 5: Unit test-2 - checkout 0/15 Your unction should retur a total price of $563, but it returned $23 Incorrect value ot inventory at. index 3:40, correct value is 0 Your output Input test file is inputTest.txt The user chose a quantity of 2 and 41 for PT.U DFF, and KTM respectively Failed 5 previous submissions 12:24 PM on 2/1/19 12:11 PM on 2/1/19 12:10 PM on 2/1/19 11:52 AM on 2/1/19 25 75 25 75 15 75 15/75 Viewv View View ViewM O lype hene to search

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

Recommended Textbook for

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

More Books

Students also viewed these Databases questions

Question

If b 0, orthogonally diagonalize a b A %3!

Answered: 1 week ago

Question

LO2 Describe the human resource planning process.

Answered: 1 week ago