CMSC 202 Spring 2005
Project 5
Car and Motorcycle Rental Systems
Assigned |
April 25,2005
|
Design Due |
11:59pm on May 1, 2005
|
Program Due |
11:59pm on May 8th, 2005
|
Updates |
|
Objectives
- To gain experience using C++ objects in a simple application
- To gain experience implementing and using a class template
- To gain experience using C++ exceptions
Project Description
Thanks in no small part to your efforts in previous projects, R & W has decided to expand
their rental system. Not only will R & W be renting cars, but they plan to start renting
motorcycles, small airplanes, 4-wheel off-road vehicles, scooters, rollerblades,
sailboats, motorboats and just about any kind of "vehicle" imaginable.
For accounting and tax purposes, each different type of vehicle will be handled by a
different rental system. However, your application must perform the same functions
(such as calculating rental/mileage/insurance cost, printing customer list, printing
vehicle list, printing rental reciepts, and perfoming vehicle maintenance)
regardless of what kind of vehicle is being rented.
Your software company has correctly decided that the best way to
implement this "one size fits all" rental system is to use a C++ class template.
This decision is based on the observation that the functionality
of the rental system is the same regardless of the vehicle being rented.
Project 5 is the pilot program for this new concept. In project 5 you will be implementing the
rental system class template and testing it by creating rental systems for cars and for motorcycles.
Each rental system object rents out just one kind of vehicle.
The rental system must maintain information about each vehicle it rents,
each customer who can rent a vehicle, and information about which vehicles are currently rented.
The basic functional requirements of the rental system are detailed below.
- Add a new vehicle to the rental system -- self explanatory.
All vehicles added to the rental system come directly from the dealer with no mileage
recorded on the odometer.
- Add a new customer to the rental system - self explanatory.
- Rent a vehicle to a customer -- associate the vehicle and the customer.
- Return a vehicle.
When a renter returns a vehicle, the number of days and mileage driven are specified.
The total rental cost is calculated and added to the customer's balance due to the company.
A "receipt" is printed for the renter which contains the vehcicle tag number,
all renter information and the breakdown of the rental cost.
Required vehichle maintenance is performed.
Note that only the vehicle tag number must be printed in the receipt.
This is less information than in project 4.
- Print a list of all vehicles.
Each vehicle tag number is printed (this is less information than project 4).
If a vehicle is currently rented, all customer information for the renter is also printed.
- Print a list of customers
All information about each customer (including balance due and the license tag numbers of
vehicles currently rented) is printed.
- Remove a customer -- self explanatory
It is an error to attempt to remove a customer who is currently renting a vehicle.
- Remove a vehicle -- self explanatory
It is an error to attempt to remove a vehicle that is currently rented.
All R & W Rental Companies have the following policies
- You must be 18 years old to rent a vehicle..
- PLATINUM car holders may rent multiple vehicles simultaneously.
GOLD card members may rent just one vehicle at a time.
Cars
Cars rented by the R & W Car Rental Company for this project are identical to those described in projects 3 and 4.
Each car is described by its model (a string which may contain spaces) and uniquely identified by
its license tag ( a string without spaces ).
In addition, each car is specified by type as economy, mid-size or luxury.
The calculations for car rental and insurance are the same as project 3 and 4,
and are duplicated in the tables below.
See the project 1 specification for sample calculations.
Car Rental Schedule
Car Type
| Card Type
| Weekly Charge
| Daily Charge
| Mileage Charge
|
Economy
| GOLD
| $90.00
| $20.00
| First 100 miles FREE
$0.20 per mile over 100 miles
|
PLATINUM
| $80.00
| $15.00
| First 200 miles FREE
$0.12 per mile over 200 miles
|
Mid-Size
| GOLD
| $150.00
| $30.00
| First 200 miles FREE
$0.20 per mile over 200 miles
|
PLATINUM
| $100.00
| $20.00
| First 250 miles FREE
$0.12 per mile over 250 miles
|
Luxury
| GOLD
| $200.00
| $40.00
| First 250 miles FREE
$0.20 per mile over 250 miles
|
PLATINUM
| $150.00
| $25.00
| First 300 miles FREE
$0.12 per mile over 300 miles
|
Weekly Car Insurance Premiums
Car Type
| Card Type
| Under 25
| 25 and Over
|
Economy
| GOLD
| $12.00
| $9.00
|
PLATINUM
| $6.00
| $4.00
|
Mid-Size
| GOLD
| $15.00
| $12.00
|
PLATINUM
| $8.00
| $6.00
|
Luxury
| GOLD
| $18.00
| $14.00
|
PLATINUM
| $10.00
| $8.00
|
Note - A full weekly premium must be paid for a partial week.
Insurance premiums are NOT prorated.
|
Car Maintenance
When a car is returned by a customer, the following maintenance must be performed.
Your program should output an appropriate message which must include the following
information
- The license tag number of the car
- The type of car
- The type of maintenance performed
- The car's current mileage
Car Maintenance Schedule
Maintenance Task
| Car Type
| Frequency
|
Wash, Wax, Vacuum
| All Cars
| Every Rental
|
Replace Air Freshener
| Economy
| Every Rental
|
Exterior Detailing
| Luxury
| Every 5th Rental
|
Shampoo Upholstery
| Luxury
| Every 2nd Rental
|
Oil Change
| Economy
| Every 9000 Miles
|
MidSize
| Every 6000 Miles
|
Luxury
| Every 3rd Rental
|
Tire Rotation
| Midsize
| Every 5000 miles
|
Refill Hot Tub
| Luxury
| Every Rental
|
Disinfect Interior
| Economy
| Every 4th Rental
|
Midsize
| Every 2nd Rental
|
Motorcycles
Like cars, motorcycles are uniquely identified by their license tag number.
Motorcycles are described by their manufacturer (e.g. Honda, Harley),
and the size of the motor in cubic centimeters ("cc"s). The tag number and manufacturer
are string with no spaces. The motor size is an integer.
The motorcycle rental schedule is given by the table below. Customers under the age of 30
are charged $20.00 per day for insurance. Customers 30 and over are charged $10.00 per day
for insurance.
Motorcycle Rental Schedule
Motor Size
| Card Type
| Daily Rental Charge
| Mileage Charge
|
less than 1000cc
| GOLD
| $12.00
| $0.05
|
PLATINUM
| $8.00
| no charge
|
1000 - 2000cc
| GOLD
| $15.00
| $0.06
|
PLATINUM
| $10.00
| $0.03
|
Over 2000cc
| GOLD
| $18.00
| $0.06
|
PLATINUM
| $12.00
| $0.04
|
Motorcycle maintenance
Motorcycle maintenance is performed according to the table below. When maintenance
is performed, a message is output containing the motorcycle's tag number, the current
mileage and a description of the maintenance task performed. All motorcycles follow
the same maintenace schedule.
Motorcycle Maintenance
Maintenance Task
| Frequency
|
Grease Drive Chain
| Every Rental
|
Wash and Wax
| Every Rental
|
Change Oil
| Every 2000 miles
|
Align Tires
| Every 3rd Rental
|
Customers
Customers who rent vehicles from the R & W Car Rental Company in this project are
identical to the customers in project 4. Each customer has a name, age and membership card.
Membership cards currently come in only two types, "GOLD" and "PLATINUM" and are imprinted with
a unique 6-digit membership number in the form 12-3456.
Program Description
Your assignment is to write a program that simulates the rental company reservation system described above.
The main portion of your program will read commands from a file
and perform the requested action (i.e. adding a vehicle or customer, renting a vehicle,
returning a vehicle, producing some output).
You will implement C++ classes which will be used by the main portion of your program.
Code from project 4 should be reusable in project 5.
Program Requirements
General Requirements
-
The rental system class must be implemented as a class template which can be used
to rent any kind of vehicle. As a template, the rental
system class must be written to accomodate a generic rental vehicle.
By its very nature, the rental system class template will have the following restrictions
- The rental system may have no knowledge of the type of vehicle being rented.
For this project which rents cars and motorcycles, this means that no code in the rental
system class template may make any reference to "car", "car type", "motorcycle" , "car rental schedule",
"motorcycle maintenance schedule", or anything else specific to car or motorcycle.
- Because the rental system must be able to rent any kind of vehicle, it may not
invoke any member function of any vehicle class that is not common to all vehicle classes.
- The rental system may require that vehicles being rented support specific member
functions (e.g. GetTagNumber( ), GetMileage( ), CalculateRentalCost( ), etc)
but these functions must be defined with identical signatures in all vehicle classes
Implement this class template so that if project 6 was a rental system for airplanes (or trucks,
or sailboats, etc, etc, etc),
your rental system class template could be used with no modifications whatsoever.
If even one line of code in your rental system needs to be changed, or even one line of code needs to be added,
then you have not implemented this template correctly.
-
Your program will be invoked with two command line arguments. The first will indicate
what type of rental system is being tested. This argument will be either "cars" or
"motorcycles". The second command line argument is the name of the command file to process.
- Since the car classes are still designed as derived classes (future vehicles for rent may
as well) and polymorphism is only possible when pointers (or references) to bases classes
are used, your rental system class must use a vector of pointers to vehicles.
- Separate vectors of car objects
(one for each car type) are not permitted anywhere in your code.
- Your program must echo each command and command parameter read from the command file.
- In keeping with course standards, main( ) will be implemented in a file named Proj5.cpp.
The prototypes for any helper functions called from main( ) will be located in Proj5Aux.h and
the functions themselves implemented in Proj5Aux.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 Proj5. Your executable must be named Proj5.
- Dynamic memory allocation for the private data members of any class is no longer required.
Programming Hints
- Vehicle objects will have to be dynamically allocated.
- When a pointer goes out of scope, the dynamically allocated memory it points to is NOT deallocated.
- Look carefully for potential memory leaks.
- It's most likely that all exceptions will eventually be caught in main( ).
Note that not all of the programming details have been spelled out for you.
For example, the project description indicates that a customer balance due the company must be printed, but
there's no specification about where that data should be stored. Also, the reservation system must
keep track of which car 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.
Program Error Checking
Your program must provide adequate error checking in support of the policies
of the rental system listed above. In addition, invalid commands and any commands which
cannot be carried out (i.e. trying to rent a car to a non-existent customer, trying to junk a car that is
currently rented to someone) must also result in an appropriate error message.
All error conditions detected by your classes must result in the throwing of an exception
class (you may not throw ints, chars, strings, etc).
You may design your exception class(es) to be as elaborate or as simple as your code requires.
All appropriate code must be contained in a "try block" and all execptions must be caught
where appropriate.
Program Output
Your program's output must adhere to the following requirements.
- Customer membership card numbers must be displayed in the form 12-3456.
- All monetary values must be displayed with 2 decimal places.
- When displaying a list of vehicles or customers, data must be aligned in columns.
- Renter names must be displayed last name first.
For purposes of formatting output only, you may make the following assumptions
which are the same as project 3.
- The renter's first and last name total no more than 20 characters.
- The car's model is no more than 20 characters.
- All vehicle license tag numbers are no more than 8 characters.
- Days rented and miles driven are less than 10000.
- The total rental charge is less than $100000.
- A customer will not rent more than 2 vehicles at a time.
The Command File
The command file has the identical format as in project 4 with the exception of the
new command to add MOTORCYCLES. Note that depending on the type of rental system
being tested, not all commands are valid. Note also that command descriptions are now
written in terms of "vehicles" rather than "cars".
Each command and all of its parameters appear on one line. You may assume that valid commands
are properly formatted and all data elements are the appropriate type.
You may not assume all commands are valid. Blank lines may be found anywhere in the file
and should be ignored.
- JUNK <tag number> -- removes the specified vehicle from the rental system where
<tag number> is a string with no spaces
- REVOKE <card number> -- removes the specified customer from the rental system where
<card number> is an integer between 1 and 999999, inclusive
- CAR <type> <license tag> <model> -- adds a new car to the reservation system where
<type> is one of "ECONOMY", "MIDSIZE" or "LUXURY" (without the quotes)
<license tag> is a string with no spaces
<model> is a string which may contain spaces
This command is only valid for car rental systems
- CUSTOMER <first name> <last name> <age> <card type> <card number>
-- adds a new customer to the reservation system where
<first name> and <last name> are strings with no spaces
<age> is an integer
<card type> is one of "GOLD" or "PLATINUM" (without the quotes)
<card number> is an integer between 1 and 999999, inclusive.
- RENT <tag number><card number> -- rents the specified vehicle to the
specified customer with this membership card number where
<tag number> is a string with no spaces
<card number> is an integer between 1 and 999999, inclusive
- RETURN <tag number> <number of days> <number of miles driven> --
specified vehicle is returned
<tag number> is a string with no spaces
<number of days> and <number of miles driven> are positive integers
- PRINT <what> -- Prints the specified list where
<what> is one of "VEHICLES" or "CUSTOMERS" or "MAINTENANCE".
If "what" is "MAINTENANCE" then there will be an additional string parameter which is
the tag number of the car whose maintenance log should be printed.
"MAINTENANCE" was for project 3 extra credit only.
If you did not seeking extra credit in project 3, or you removed your extra credit code,
then "PRINT MAINTENANCE <tag number>" should be considered
an invalid command and an appropriate error message should be produced. Test files will
contain these commands.
- MOTORCYCLE <manufacturer> <tag number> <motor size> where
<manufacturer> and <tag number> are strings with no spaces
<motor size> is a positive integer
This command is only valid for motorcycle rental systems
Sample Output
Sample output is provided for motorcycles only. The output for
cars is essentially the same as project 4, except as noted above.
This command file
CUSTOMER Jimmy Jones 44 GOLD 123456
MOTORCYCLE HONDA XYZZY 300
RENT XYZZY 123456
RETURN XYZZY 30 1000
RENT XYZZY 123456
RETURN XYZZY 25 1500
RENT XYZZY 123456
RETURN XYZZY 20 600
produced this output
CMD: CUSTOMER, Jimmy, Jones, 44, GOLD, 123456
CMD: MOTORCYCLE, HONDA, XYZZY, 300
CMD: RENT, XYZZY, 123456
CMD: RETURN, XYZZY, 30, 1000
Rental Return Receipt
------ ------ -------
R & W Car Rental hereby acknowledges that the vehicle with license plate tag XYZZY
has been returned to the company by the renter
Jones, Jimmy (12-3456 / GOLD )
who agrees to pay the following charges
Daily Charge: 360.00 Mileage Charge: 50.00
Insurance Charge: 300.00 Total Charge: 710.00
Maintenace performed for HONDA motorcycle with license XYZZY, motor size 300, with 1000 miles
GREASE DRIVE CHAIN
WASH AND WAX
CMD: RENT, XYZZY, 123456
CMD: RETURN, XYZZY, 25, 1500
Rental Return Receipt
------ ------ -------
R & W Car Rental hereby acknowledges that the vehicle with license plate tag XYZZY
has been returned to the company by the renter
Jones, Jimmy (12-3456 / GOLD )
who agrees to pay the following charges
Daily Charge: 300.00 Mileage Charge: 75.00
Insurance Charge: 250.00 Total Charge: 625.00
Maintenace performed for HONDA motorcycle with license XYZZY, motor size 300, with 2500 miles
GREASE DRIVE CHAIN
WASH AND WAX
OIL CHANGE
CMD: RENT, XYZZY, 123456
CMD: RETURN, XYZZY, 20, 600
Rental Return Receipt
------ ------ -------
R & W Car Rental hereby acknowledges that the vehicle with license plate tag XYZZY
has been returned to the company by the renter
Jones, Jimmy (12-3456 / GOLD )
who agrees to pay the following charges
Daily Charge: 240.00 Mileage Charge: 30.00
Insurance Charge: 200.00 Total Charge: 470.00
Maintenace performed for HONDA motorcycle with license XYZZY, motor size 300, with 3100 miles
GREASE DRIVE CHAIN
WASH AND WAX
ALIGN TIRES
Free Advice and Information
- Carefully consider your class design. In general, a minimal class interface
is best. Consider how best to reuse code. Plan for the future reuse of code
you write in this project.
- Consider using the overloaded operator<< to output your classes.
Even if not necessary in your code, you may find it helpful when debugging.
- Functions called from main( ) that are not part of any class are permitted.
If you create new functions,
their prototypes must be found in Proj5Aux.h and they must be implemented in Proj5Aux.cpp.
- Your program must provide adequate error checking as described above.
- Think carefully about the proper use of const for parameters and member functions.
Doing const correctly from the beginning can save lots of effort and frustration later.
- Review the class notes on the different methods of passing
parameters. Each is best for a different situation.
- Be sure your function header comments list the pre- and post-conditions and handle each
pre-condition that is not met.
- Your program will be tested with a variety of conditions.
- Use incremental development.
Project Design Assignment
Your project design document for project 5 must be named p5design.txt.
Be sure to read the design specification
carefully. Submit your design in the usual way:
submit cs202 Proj5 p5design.txt
Project Makefile
You must provide the makefile for this project. Use the makefile you submitted
for project 4 and modify it appropriately. If you don't change the names of the
files from project 5, the changes will be minimal.
Note that it is not necessary to compile your rental system class template. That code
will get compiled as part of Proj5.cpp when rental system classes are used.
The graders will be typing the command make Proj5 when they grade your project.
This command must cause all .cpp files to be compiled and the executable named
Proj5 to be created.
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, Proj5 executable
and backup files created by the editor. More information about these
commands can be found at the bottom of the makefile.
Grading
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.
85% - Correctness
This list may not be comprehensive, but everything on this list will be
verified by the graders.
- Command line error checking is provided
- Your project produces all required output
- The output produced is correct
- The output is in an acceptable format.
- All function parameters are passed using the appropriate method
- const is used wherever appropriate
- All unmet function pre-conditions are handled.
- All project requirements are met
- No project restrictions have been violated
- Your class designs and implementations follow good OO principles.
15% - Coding Standards
Your code adheres to the
CMSC 202 coding standards as discussed
and reviewed in class.
In particular, since this is your first C++ program using classes, pay attention to
the list below. Graders will check all applicable items in the coding standards.
- Your class implementation and class usage
- Proper use of const
- Your function header comments (particularly pre- and post-conditions)
- In-line comments
- Code readability
Project Submission
Submit all your files in the usual way.
You must make
sure that all files necessary to compile and link your project (using the makefile)
are listed. You need not submit all files at the same time. You may resubmit
your files as often as you like, but only the last submittal will be graded and
will be used to determine if your project is late. For more information,
see the projects page on the course website.
You can check to see what files you have submitted by typing
submitls cs202 Proj5
More complete documentation for submit and related commands can be found
here.
Remember -- if you make any change to your program, no matter how
insignificant it may seem, you should recompile and retest your program before
submitting it. Even the smallest typo can cause compiler errors and a reduction
in your grade.
Avoid unpleasant surprises!
Be sure to use the submitmake and submitrun utilities provided
for you to compile, link and run your program after you've submitted it.