Project 3

Due: Friday, June 19 (11:59 PM)

Objective

Upon completion of this program, you should be able to use objects from more than one class, using the composition ("has-a") relationship.

Task

You will be writing classes that simulate sales at a store that sells books, DVDs, and software, as well as the accounting of the day's sales on one cash register. The register will keep track of a list of the most recent sales. You will need to finish the writing of two classes:  Sale and Register.  The full header file for the Sale class has been provided in a file called sale.h.  The Register class is described below. You can get a copy of sale.h here

Program Details and Requirements:

Sale class

Using the Sale class declaration, write the sale.cpp file and define all of the member functions that are declared in the file sale.h.   (Do not change sale.h in any way.  Just take the existing class interface and fill in the function definitions).  Notice that there are only four kinds of items:  BOOK, DVD, SOFTWARE, and CREDIT.  The sale.h file contains the descriptions of how the functions should work and what the member data variables represent.  Make sure that the member functions only do their intended tasks (i.e. no extraneous inputs, outputs, or results that are not specified).
 

Register class

Write a class called Register (filenames are register.h and register.cpp).  A Register object should store at least the following information:  an identification number (an integer) for the cash register object, the amount of money in the cash register object, and a list (array) of sales. All member data must be private.

You may assume the maximum number of sales within a register to be 100.

You can add any private data and functions into the Register class that you feel are useful, but your Register class must have at least the following functions (names and descriptions provided here) in its public interface. These functions should not do extraneous input, output, or other non-specified tasks (i.e. they do only what is specified).

(Hint: keep in mind that inside the register, you are keeping an array of Sale objects. This means that most of these functions will be using this array to do their work -- and they can also call upon Sale class member functions).

Constructor
The constructor should take in two parameters, which allow the ID number and starting amount in the register to be initialized when the Register object is created. To create a Register object, this data must be passed in.

the destructor
The destructor should produce output a summary of sales and the final ammount in the register.

- GetID
- GetAmount
These accessor functions should return the current ID number and current amount in the register, respectively, to the caller.

- RingUpSale
This function allows the item type and base price of a sale to be passed in as parameters. This function should store the sale in the sale list, and it should update the amount of money in the cash register appropriately. Items that are bought will add money to the register.  Remember that sales tax must be added to the base price of any item sold. If the sale type is CREDIT, then you should deduct the amount from the register.

- ShowLast       // display the last sale made
- ShowAll        // display entire sale list
These functions will display information about sales to the screen.  ShowLast should display only the information about the last sale that was made.  ShowAll should show all of the sales currently in the sale list, one per line.  This display should be in the order oldest to newest.  (i.e. the most recent sale is displayed last).  If there are no sales currently in the list, then output an appropriate message instead (like "No sales have been made").

- Cancel
This function should cancel the last sale in the list.  This means that the amount in the cash register, as well as the data in the sale list, should be adjusted accordingly (as if the sale had never happened).  This simulates the idea that a sale rung up incorrectly can be voided out by the cashier.  If the sale list is empty, print an appropriate error message and abort the cancel operation.

- SalesTax
This function should calculate and return the total amount of sales tax for the last n sales (i.e. the most recent ones), where n is an integer passed in as a parameter. If n is higher than the number of sales currently stored, just calculate the total tax for all sales currently in the sale list. If n is invalid (a negative number), print an appropriate error message and return 0.
 


Test Program

I've created a menu program that will help you interactively test the features of your Register class. You can get a copy of menu4.cpp here.

This menu program will start by prompting the user to input a cash register ID and the starting amount in the register. Then it will create a Register object and enter a menu loop -- the menu options will work with both lower and upper case inputs:

  S:   Show current amount in the cash register 
  R:   Ring up a sale 
  D:   Display the last sale 
  L:   Display the entire sale List 
  C:   Cancel the last stored sale 
  T:   Find the Total sales tax for recent sales 
  M:   Show this Menu 
  X:   eXit the program 
Some of the menu options will prompt for other inputs. Each will allow you to interactively test the behavior of your Register class public interface. The code in menu4.cpp also demonstrates appropriate calls to the Register class member functions.



Submit the following files (using blackboard):
  sale.cpp 
  register.h 
  register.cpp