This content is controlled by your instructor, and is not zyBooks content. Direct questions or concerns about this content to your instructor. If you have any technical issues with the zyLab submission system, use the Trouble with lab button at the bottom of the lab.
This homework assignment gives you the opportunity to practice classes, member variables, member functions and array of objects. There is an extra credit version worth an additional 10 points.
Design a grocery product class named Product that has the following private member variables:
and the following public member functions (do not write a constructor. The compiler will automatically generate an implicit constructor):
Demonstrate the class in a program, as specified below.
Your should turn in the following files:
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.
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.
The file contains product records. Each grocery product record consists of the following 5 items:
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.
Make sure you follow the style requirements, especially regarding the comment header for functions, to avoid losing 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.
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.
Style: 10 points (refer to the “Homework Notes” for the style requirements)
To test on your IDE, you may copy and paste from the “testX-keyboard-input.txt” files to save on typing the user’s input at the keyboard.
Test-1 – Basic case, no error – Output starts like output-1: 15 points. Test-2 – PLU not found – Output starts like output-2: 15 points.
Test-3 – Subtract more than inventory – Output starts like output-3: 15 points. Test-4 – Amounts not > 0 – Output starts like output-4: 15 points
Test-5 - Extra credit-1 – 5 transactions or less – Output matches output-5: 5 points Test-6 - Extra credit-2– More than 5 transactions – Output matches output-6: 5 points Test-7 - setProductAttributes unit test: 30 points
DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma
Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t
Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th
1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of
1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of