Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Design a grocery product class named Product that has the following private member variables: PLU of type string name of type string type of type

Design a grocery product class named Product that has the following private member variables: PLU of type string name of type string type of type int price of type double inventory of type int

and the following public member functions (do not write a constructor. The compiler will automatically generate an implicit constructor): setProductAttributes: mutator to set the PLU, name, type, price and inventory of a Product. The arguments should be in that order setInventory: mutator to set the inventory getPLU: accessor to get the PLU getName: accessor to get the name getType: accessor to get the type getPrice: accessor to get the price getInventory: accessor to get the inventory

Demonstrate the class in a program, as specified below.

1. Additional Requirements

a) What to turn in

Your should turn in the following files: Product.cpp which contains the function description of all the member functions main.cpp file which contains the main function. You should write Product.h, but do not turn it in. It is already on zylabs. Product.h contains the class definition and the function prototypes of all the member functions (no in-line functions).

If the user chooses 1, user will be prompted for the PLU and the amount to be added. The program then adds the amount to the inventory and displays the menu again. If the user chooses 2, user will be prompted for the PLU and the amount to be subtracted. The program then subtracts the amount from the inventory and displays the menu again. If the user chooses 3, the program prints the attributes of all the Products. The attributes are the member variable values. If the user chooses 4, the program terminates.

Input validation: The program prints an error message if the user tries to add or subtract from a product whose PLU cannot be found, then displays the menu again. if the user tries to subtract more than what is in the inventory, the program only subtracts what is in the inventory. The menu is displayed again. The program prints an error message if the subtraction or addition amount is not positive. The transaction should not be made in that case. The menu is displayed again.

c) File

The file contains product records. 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.

You may assume the records are properly formatted, and therefore there is no need for input validation when reading from the file.

d) Style

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

2. Extra credit (20 points)

For the extra credit, your main function should implement, in addition to the basic version, the following feature. If the user chooses 4, the program does not terminate immediately, but prints the history of the past transactions up to 5, then terminates. A transaction is an addition to the inventory level or a subtraction from the inventory level. Transactions that are not made due to invalid input should not be printed. The program should print the transaction #, the PLU, the transaction type (addition or subtraction), and the actual amount added or subtracted. The transaction # is a sequence number assigned to each transaction that is actually executed, starting from 1 for the first transaction. The transactions should be printed from most recent to least recent. If more than 5 transactions were executed, only the 5 most recent transactions are printed.

3. Suggestions for implementation

a) File management

You may read the file twice: the first time to determine the number of records, and the second time to read the content. After the first read, to reposition the read pointer at the beginning of the file, you can close the file and reopen it.

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

.......

Thanks, will give a thumbs up.

5. Screen Outputs Ente: a file name: p=od.ctDat -1..xt LU: A001. Appiea L: AD02, Paahea . typa: . t prica: 0.9. inventory: 21 typa: 1. ani: prica: 0.82, in-entory: 11 typa: 1. nt prica: 0.58. inventory: 3 LU: A0E.angoa ypa: 0. anit prica: 1.E9. inventory: 19 : 42 Rice e pa:nit pricn: 0.49 nantory: 107 -A te nantory -Ad te nantory -A te nantory L:A001. Appiea PLU: A004, 0:anges ELU: A00, Mangoa ELT: 4261, Rica 1 LB Bag ypa: 1. nit prica: 0.3. inventory: 21 . typa: . t prica: 0.82, inventory: 21 typa: 1. ani: prica: 0.98. inventory: a typa: 0 t prica: 1.54. inventory: 27 , typa: 0, unitCzca : 0.49, inrentosy : 107 -Add te rantory 3->P.int info to: ali p=odi.cta, 4-2Exit class Product private: string PLU: string name; int type: double price; int inventory: public: void setProductAttributes (string, string, int, double, int); void setInventory (int) string getPLU) const string getName ) const: int getType() const; double getPrice ) const; int getInventory) const; b) Outline of main Prompt the user for a file name Read the file to determine the number of records in the file. If the file open is unsuccessful, print an error message and terminate Dynamically allocate an array of Prduct objects, with a size equal to the number of records, and populate the array with the items read fro the file by using the appropriate mutator (s) Then print the array. Loop on displaying the following menu of choices: Add to inventory Subtract from inventory Print info for all products Exit 3. 4. Output- Enter the file name: productData-2.txt There are 5 records in the file Content of object array PLU: A002, Peaches PLU: A004, Oranges PLU: A006, Avocados PLU: A008, Mangos PLU: 4261, Rice_1_LB Bag , 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 0.49, inventory 107 Menu 1->Add to inventory 3->Print info for all products, 4->Exit , 2->Subtract from inventory Enter the PLU: AO PLU not found Menu 1->Add to inventory 3->Print info for all products, 4->Exit , 2->Subtract from inventory Enter the PLU: A002 Enter amount to add: 10 1->Add to inventory 3->Print info for all products, 4->Exit , 2->Subtract from inventory Enter the PLU : #$ PLU not found Menu 1->Add to inventory 3->Print info for all products, 4->Exit , 2->Subtract from inventory Enter the PLU: A008 Enter amount to subtract: 19 Menu 1->Add to inventory 3->Print info for all products, 4->Exit , 2->Subtract from inventory Current inventory PLU: A002, Peaches PLU: A004, Oranges PLU: A006, Avocados PLU: A008, Mangos PLU: 4261, Rice_1_LB_Bag type: 1, unit type: 1, unit p type: 0, unit p ype: 0, unit p type: 0, unit p price: 0.82, inventory: 21 rice: 0.98, inventory: 31 rice: 1.54, inventory: 27 rice 1.69, inventory: 0 rice: 0.49, inventory: 107 Output-2 Enter the file name : productData-.txt There are 8 records in the file Content of object array 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 PLU: A011, Kiwis type: 1, unit price: , 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 0.9, inventory: 21 , type: 0, unit price 0. 49, inventory: 107 type: 1, unit price: 1.2, inventory: 50 Menu 1->Add to inventory 3->Print info for all products, 4->Exit , 2->Subtract from inventory Enter the PLU: A002 Enter amount to add 200 Menu 1->Add to inventory 3->Print info for all products, 4->Exit , 2->Subtract from inventory Menu 1-Add to inventory 3->Print info for all products, 4->Exit , 2->Subtract from inventory Current inventory PLU: A001, Apple:s 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 PLU: A011, Kiwis , type: 1, unit price .9, inventory: 21 , type: 1, unit price 0.82, inventory: 211 , type: 1, unit price: 0.98, inventory: 31 , type: 0, unit price: 1.54, inventory: 27 , type: 0, unit price: 1.69, inventory: 0 , type: 0, unit price 0.49, inventory 107 , type: 1, unit price 1.2, inventory: 50 Menu 1-Add to inventory 3->Print info for all products, 4->Exit , 2->Subtract from inventory

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

Upgrading Oracle Databases Oracle Database New Features

Authors: Charles Kim, Gary Gordhamer, Sean Scott

1st Edition

B0BL12WFP6, 979-8359657501

More Books

Students also viewed these Databases questions

Question

Presentation Aids Practicing Your Speech?

Answered: 1 week ago