logo Use CA10RAM to get 10%* Discount.
Order Nowlogo
(5/5)

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

 

(5/5)
Attachments:

Expert's Answer

855 Times Downloaded

Related Questions

. Introgramming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma

. The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

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. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

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

. SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

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

. 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 Sea Ports. Here are the classes and their instance variables we wish to define:

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

855 Times Downloaded

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

expert
Um e HaniScience

518 Answers

Hire Me
expert
Muhammad Ali HaiderFinance

893 Answers

Hire Me
expert
Husnain SaeedComputer science

851 Answers

Hire Me
expert
Atharva PatilComputer science

606 Answers

Hire Me