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.
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 programSome 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.
sale.cpp register.h register.cpp