Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

***I need help with this assignment. for some reason my code does not have the same output as the picture below. in the picture where

***I need help with this assignment. for some reason my code does not have the same output as the picture below. in the picture where it says $67.9 I keep getting $49. and also just like in the picture provided when I put in A001 and then 22 for the quantity it tells me not enough quantity. I know I don't have enough quantity but why in the picture it doesn't say that. because for some reason in the picture it shows the updated inventory and it says Apples is 0 which means it went through. these are the things I need help with.

image text in transcribed

productData.txt:

A001 Apples 1 0.90 0 A002 Peaches 1 0.82 11 A004 Oranges 1 .98 31 A006 Avocados 0 1.54 27 A008 Mangos 0 1.69 19 A009 Strawberries_Case 0 12.50 8 4261 Rice_1_LB_Bag 0 0.49 107

inputfile:

1

A001

0

-2

22

4260

20

4261

100

0

2

1

A008

10

A004

20

0

5

4

3

My code:

#include #include #include #include using namespace std; //function prototypes same as given //function to determine number of records in the file 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

cin >> userCho; switch(userCho) { case 1: totalVal = checkout(pluPtr, pricePtr, inventoryPtr, numOfRecords); cout

return 0; } //The function definitions //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

Reading product data from file: productData.txt PLU: A001 Apples PLU: A002 Peaches PLU: A006.Avocados PLU: A008 Mangos PLU: AG09 Strawberries_case type:.unit price: 12.50.inventory: 8 PLU: 4261.Rice_1_Lb_bag 1-Checkout .type: 1.unit price 0.90.inventory: 21 type: 1.unit price .82.inventory: 11 .type: .unit price 1.54.inventory: 27 type: .unit price 1.69.inventory: 19 type: .unit price .49.inventory: 10? 2-Close and exit Enter PLU, zero if done A001 Enter quantity: 22 Enter PLU. zero if done 4261 Enter quantity:0 Reenter. quantity must be positive-2 Reenter quantity must be positive 100 Enter PLU. zero if done: 0 Total is $67.9 Checkout 2Close and exit Enter PLU. zero if done: AG09 Enter quantity: 2 Enter PLU. zero if done: A004 Enter quantity: 1 PLU not found Enter PLU, zero if done: A008 Enter quantity: 10 Enter PLU, zero if done:0 Total is $41.9 L Checkout 2- Close and exit Updated Product Information: PLU: A01Apples PLU: A002 Peaches PLU: A006 Avocados PLU: AG08. Mangos PLU: A009 Strawberries_ca PLU: 4261.Rice_1_Lb_bag type 1.unit price: 0.90.inventory:0 type 1.unit price: 0.82.inventory: 11 type 0.unit price 1.54.inventory: 2? type 0.unit price: 1.69.inventory: ase type 0.unit price: 12.50.inventory: 6 .type 0.unit price: 0.49.inventory: Updated product data written into file: updatedProductData.txt Process returned(Gx execution tine: 398.693 s Press any key to continue

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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