Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

***my output needs to look just like the picture provided but for some reason everytime i type the number "22" for the quantity of apples it wont let me. it says not enough quantitity so what i need to do is modify my code to where it lets me type in the number 22 and it still only takes out 21 apples. ive tried altering my code to say that but everytime i do it gives me a negative number in my inventory for apple.*****image text in transcribed

nter the file name: product Data.txt There are 7 records in the file Inventory read from file PLU: A001, Apples PLU: A002, Peaches PLU: A004, Oranges PLU: A006, Avocados PLU: A008, Mangos PLU: A009, Strawberries_Case. type: 0, unit price 12.5, inventory: 8 PLU: 4261, Rice_ 1_LB_Bag , type: 1, unit price: 0.9, inventory: 21 , type: 1, unit price: 0.82, inventory: 11 , type: 1. unit price: 0.98, inventory: 31 , type: 0, unit price: 1.54, inventory: 27 , type: 0, unit price: 1.69, inventory: 19 , type: , unit price: 0.49, inventory: 107 -Print current inventory Quit nter PLU, 0 if done: A001 nter quantity: O Quant ity must be posttive: reenter: 22 positive, reenter: nter PLU, O if done: 4260 nter quant ity: PLU not found nter PLU, 0 if done: 4261 Enter quantity: 100 21% done : 0 Enter PLU ot ar Total is: $67 -Checkout -Print current inventory -Quit Current inventory PLU: A001, Apples PLU: A002, Peaches PLU: A004, Oranges PLU: A006, Avocados PLU: A008, Mangos PLU: A009, Strawberries_Caset PLU: 4261, Rice 1_LB_Bag , type: 1 unit price: .9, inventory: 0 , type: 1, unit price: 0.82, inventory:11 , type: 1, unit price: 0.98, inventory: 31 , type: 0, unit price: 1.54, inventory:27 , type: 0, unit price: 1.69, inventory: 19 type: 0, unit price: 12.5, inventory:8 , type: 0, unit price: 0.49, inventory:7

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

Advances In Knowledge Discovery In Databases

Authors: Animesh Adhikari, Jhimli Adhikari

1st Edition

3319132121, 9783319132129

More Books

Students also viewed these Databases questions

Question

a. Did you express your anger verbally? Physically?

Answered: 1 week ago