logo Hurry, Grab up to 30% discount on the entire course
Order Now logo

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Sethh PowellHistory
(4/5)

747 Answers

Hire Me
expert
Angel MoralesLaw
(5/5)

555 Answers

Hire Me
expert
Mehar KhanNursing
(5/5)

579 Answers

Hire Me
expert
Elizabeth BachhSocial sciences
(5/5)

707 Answers

Hire Me
C++ Programming

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.

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

Students:

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.

1.9 HW6

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.

HW6 (Graded out of 100)

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:

  • cpp which contains the function description of all the member functions
  • 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).

b)  Outline of main

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.

c)  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.

d)  File

The file contains product records. Each grocery product record consists of the following 5 items:

  • PLU code: Product Look Up 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.

e)  Style

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

2.   Extra credit (10 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

  1. 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.

 

4.   Grading Criteria

  1. Source code inspection (grader)

 

Style: 10 points (refer to the “Homework Notes” for the style requirements)

 

b)  Program compilation and execution (zylabs)

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

 

Related Questions

. The fundamental operations of create, read, update, and delete (CRUD) in either Python or Java

CS 340 Milestone One Guidelines and Rubric  Overview: For this assignment, you will implement the fundamental operations of create, read, update,

. Develop a program to emulate a purchase transaction at a retail store. This  program will have two classes, a LineItem class and a Transaction class

Retail Transaction Programming Project  Project Requirements:  Develop a program to emulate a purchase transaction at a retail store. This

. The following program contains five errors. Identify the errors and fix them

7COM1028   Secure Systems Programming   Referral Coursework: Secure

. Accepts the following from a user: Item Name Item Quantity Item Price Allows the user to create a file to store the sales receipt contents

Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip

. The final project will encompass developing a web service using a software stack and implementing an industry-standard interface. Regardless of whether you choose to pursue application development goals as a pure developer or as a software engineer

CS 340 Final Project Guidelines and Rubric  Overview The final project will encompass developing a web service using a software stack and impleme