Project Description
In this third phase of the project you will be experimenting with different
forms of representing data as well as overloading operators to enhance the
readability of your code.
The DVD rental system
The DVD Rental System manages a list of customers who want to rent DVDs,
a list of available DVDs, and a list of desired DVDs for each customer (the
customer's "queue"). The system also reacts to the following commands:
OPEN
- Open and read a DVD stock file that represents the DVDs that are currently
in-stock.
- If the file does not exist - display an error
- If the file is empty - display an error
- You may assume all data is correct in stockfile.
CUSTOMER
- Add a customer to the system
- If customer already exists, display an error.
RENT
- Rents DVDs to a customer.
- Until the customer's quota is full, finds the first DVD on the customer's
queue that is also in-stock, removes it from the stock, and adds it to the
customer's rented list.
- Once the quota is full, a receipt is printed.
- If the quota cannot be filled and a DVD was rented, a receipt is printed.
- If no DVD was rented, then no receipt is printed.
RETURN
- Return the DVD for the customer.
- Removing it from the customer's rented
list and returning it to the stock.
- If the DVD was not rented by the customer, display an error.
QUEUE
- Add a DVD to a customer's queue (list of DVDs they want to rent).
- If customer does not exist, display an error.
- If DVD is in the system (it is either in-stock or rented by another
customer) - allow it to be queued.
- If DVD does not exist in the system, display an error
- The same DVD can be queued multiple times.
PRINT_DVDS
- Prints a list of in-stock DVDs (DVDNumber, NbrOfDiscs, Title)
PRINT_CUSTOMERS
- Prints all customers and their current rentals -
all personal information (name, username, CC#, address, city, state, zip)
followed by all currently rented DVDs (DVDNumber, NbrOfDiscs, Title)
PRINT_USER
- Prints the queue for a particular user
- If username does not exist, display an error.
If there are no
rentals for username, then leave rental area blank.
- If the user has no DVDs in their queue, then leave the queue area blank.
Data
Rental System
The Rental System manages the collection of Customers and in-stock DVDs. You
may also have the Rental System manage other components according to your
design. However, for this project, your Rental System class MUST have at the
minimum:
- a collection of Customers
- a collection of DVDs
Customers
Customers who rent DVDs are essentially the same as in Project 1. There
are multiple customers allowed in the system. Each customer is
charged $0.99 per disc to rent a DVD. Customers are limited to a MAXIMUM
of 3 rentals at a time.
Customers each have the following information, you may represent these in
a variety of ways and are not limited to this exact representation:
- First name - sequence of any characters without spaces
- Last name - sequence of any characters without spaces
- Username - sequence of alphabetic, numerical, or the underscore ('_')
characters - each username is unique
- Credit Card number - sequence of digits
[0 - 9999999999999999], displayed as 16 digits
- Street Address - sequence of any characters with spaces
- City - sequence of any characters with spaces
- State - sequence of 2 characters (upper or lower) that match the 50 US
states
- Zip - sequence of digits [1000 - 99999], displayed as 5 digits
- Queue - a list of DVDs the user would like to rent
- Rented List - a list of DVDs the user is currently renting
DVDs
DVDs are essentially the same as described in Project 1. Multiple copies of
the same DVD are allowed. It can be assumed that the first DVD added to
the system has the correct Number of Discs and Title information.
DVDs each have the following information:
- DVD Number - unique identifier, sequence of digits [1 - 999999]
- Number of Discs - sequence of digits that represents the number of
disc [1 - 100]
- Title - sequence of any characters with white space
Program Requirements
Dynamic Memory UPDATED!
You are required to declare all instances of user-defined
classes of type RentalSystem, Customer and DVD as dynamic memory
(pointers!). You a re not required to declare strings and vectors as
dynamic objects (vectors may, however, be built of dynamic objects,
example: a vector of pointers to Customers). If you have other user-defined
classes, they need not by dynamically allocated - this is your choice.
You are required to overload the "Big Three" methods for each class that uses
dynamic memory to create, manage, and delete all dynamic memory.
Operator Overloading
You will extend your classes from Project 2 to accomodate the following:
- DVD rental system
- Overloaded << operator - prints the current list of customers (first
name, last name, username) followed by the current list of in-stock DVDs
- Customer
- Overloaded += operator - adds the DVDs (parameter) to the customer's queue.
Works the same as the queue method (hint, hint).
- Overloaded -= operator - performs a return of a particular DVD (parameter).
Works the same as the return command.
- Overloaded << operator - prints all personal information (name,
username, etc.) followed by the customer's current rentals. Does NOT print
the user's queue.
- DVD
- Overloaded << operator - prints all 3 pieces of dvd data (DVD number,
number of discs, title)
You may include any other classes that you feel are necessary or reasonable -
these represent the minimum set of classes that you must use.
Utility Class
You have been provided with a "Utility" class that has one static method that
you may use to correctly parse the command file. If you choose not
to use the Utility class, then you will have to rely upon the correctness of
your own implementation. You have been provided with the .h and .o files.
You will not be supplied with the Utility class code, you do not need it.
You can find Utility.o and Utility.h in the following location:
/afs/umbc.edu/users/d/a/dana3/pub/CMSC202/p3/
The one public method of the Utility class is:
static bool GetCommand(istream& sin, vector& command);
The GetCommand method makes the following guarantees:
- Returns true if the command was correctly formatted and the data was of
the correct type (digits versus strings)
- Returns false otherwise
- Parses the data, pushing each individual item onto a vector
- First item in the vector is the command name
- Each parameter to a command is a single entry in the vector
- Validates that all numbers are composed of digits
- Validates that the state in the address is one of the 50 states
- Validates the username by verifying that all characters are alphabetical,
numerical or the underscore ('_')
- Stock file is not read, nor tested for existence
- The state of the vector is undefined if GetCommand fails
- The command as read from the file will be printed to the standard output
stream
Although you do not have the actual code, you should be able
to easily modify your code to use this in place of your own implementation.
There are constants for each command included in the Utility.h so you do not
have to declare those in your own code.
Extra Credit
Utility Class (Possible 10 pts)
As a professional developer, you will often have to use code developed by
other individuals both within your company and without. This is the purpose
of introducing the Utility Class at this point - Code Reuse. One of the
problems with using code written by others is that it might have bugs in it.
You have the opportunity to earn up to 10 extra credit points by finding a
bug in the Utility class. It is not guaranteed that one exists, but if
you are the first to point it out to Ms. Wortman, and provide the test
case in which the bug was found, you will receive up to 10 points. The first
person to point out each individual error will receive the points. Ms. Wortman
will ensure that the graders give you the appropriate points.
PRINT SORTED CUSTOMERS (Possible 10-20 pts)
Add support in your system for the command PRINT SORTED that will print the
list of customers in alphabetical order by username. There are a variety of
sorting algorithms that you can use from easy to hard. The four that we will
give credit for are:
- 10 pts - Insertion sort (iterative)
- 10 pts - Bubble sort (iterative)
- 15 pts - Merge sort (recursive, usually)
- 20 pts - Quick sort (recursive, usually)
Calling the PRINT_SORTED_CUSTOMERS command cannot make a permanent
change to the original printing order of the customers (i.e. a call to
PRINT_CUSTOMER before and after the PRINT_SORTED_CUSTOMERS command should
print out the customers in exactly the same order as before.
In order to get credit for this, you must submit a README file for the graders
describing your implementation. Describe your strategy and which sort you used.
Also describe which data-structure decisions that you made (i.e. How did you
store the customers to prevent change?). You may only select one algorithm
to implement and get credit for.
Command File Requirements
The name of the command file will be read from the command line. You should
thoroughly test your program by developing your own command file. You do not
need to submit your command file. We will test your program using our own
command file(s).
Your program is required to repeat the command as read from the file. The
Utility class will take care of this for you, if you use it.
Commands
Please note that there have been minor changes to the command parameters
Valid commands for the system are as follows:
- OPEN <stock filename>
- CUSTOMER <first name> <last name> <username>
<card number>
<address>
<city> <state> <zip code>
- RENT <username>
- RETURN <dvd number> <username>
- QUEUE <dvd number> <username>
- PRINT_DVDS
- PRINT_CUSTOMERS
- PRINT_USER <username>
- PRINT_SORTED_CUSTOMERS [optional]
Command File Error Checking
- If a command is incorrect in any way (format or content), it shall be
discarded and processing of the command file shall continue. Must include
an error message.
- If a command cannot be executed (like queueing a DVD for a non-existant
customer), a message shall be printed and processing of the command file
shall continue.
- Data must be validated. Utility takes care of this.
- Names, addresses, and other "word" based items, unless
specifically limited - they may contain any printable character.
- Printable characters are defined as any character that can be typed on the
keyboard. You need not validate these characters at all.
Sample Command File
OPEN stock.txt
CUSTOMER Fred Flintstone fflint0 1234123456785678
123 Bedrock LN Apt. 7
Rock Vegas NV 12345
QUEUE 12345 fflint0
QUEUE 928173 fflint0
QUEUE 32145 fflint0
QUEUE 759203 fflint0
RENT fflint0
CUSTOMER Barney Rubble brubblerubble 1234567812345678
123 Bedrock LN Apt. 8
Rock Vegas NV 12345
QUEUE 927833 brubblerubble
QUEUE 12345 brubblerubble
RENT brubblerubble
PRINT_USER brubblerubble
RETURN 826918 fflint0
RETURN 12345 fflint0
PRINT_DVDS
PRINT_CUSTOMERS
PRINT_USER fflint0
Stock File
You can assume that any stock file that we test with your program is
properly formatted and that all DVD data is valid. You need not perform ANY
error checking on the DVD file. The stock file represents all the DVDs that
are currently "in-stock" (since the inventory is taken every evening).
For now, you will assume that another file processes the inventory every
evening and provides your system with an up-to-date copy of the stock every
morning.
Sample Stock File
12345 2 Harry Potter and the Chamber of Secrets
423644 1 Matrix: Reloaded
826918 4 Lord of the Rings: The Fellowship of the Ring
759203 1 Dumbo
927833 3 Hunt for Red October
32145 1 Pi
928173 1 Hitchhiker's Guide to the Galaxy
General Requirements
- In keeping with course standards, main( ) will be implemented in a file
named Proj3.cpp.
- Prototypes for any helper functions called from main will be located in
Proj3Aux.h and the functions themselves implemented in Proj3Aux.cpp.
- Each class will be defined in a separate header (e.g. Customer.h) file
and implemented in a similarly named .cpp file (e.g. Customer.cpp).
- You must provide a makefile for this project which compiles and
links all files when the grader types
make Proj3.
- Your executable must be named Proj3.
Note that not all of the programming details have been spelled out for you.
For example, the rental system must keep track of which DVD is rented by whom,
but there's no indication about how that should be done.
This is intentional....you are required to give the project design
serious thought before writing code. Remember to think ahead to what might
be assigned in future projects and design your classes so that they are
easily modifiable.
Program Output
Your program's output must adhere to the following requirements:
- Customer credit card numbers must be displayed in the form
1234-5678-9012-3456.
- All monetary values must be displayed with 2 decimal places.
- When displaying a list of DVDs or customers, data must be aligned in
columns.
- Lists of DVDs/customers shall be displayed in the order DVDs/customers
are added to the rental system.
- As the stock file is processed, messages informing the user of each DVD
that is being added shall be displayed
For purposes of formatting output only, you make the following
assumption:
- The renter's first and last name total no more than 20 characters.
- The renter's username totals no more than 20 characters.
You must provide the makefile for this project. Use the makefile provided to
you for project 1 and modify it appropriately. If you don't change the
names of the files (much) from project 1, the changes will be minimal.
The make utility can also be used for compiling a single program without
linking.
For example, to compile Box.cpp, type make Box.o.
In addition to compiling and linking your files, make can be used
for maintaining your directory. Typing make clean will remove any
extraneous files in your directory, such as .o files and core files.
Typing make cleanest will remove all .o files, core, Proj3,
and backup files created by the editor. More information about these
commands can be found at the bottom of the makefile.
The grade for this project will be broken down as follows. A more detailed
breakdown will be provided in the grade form you receive
with your project grade.