UMBC CMSC 202
UMBC CMSC 202 CSEE | 202 | current 202

CMSC 202 Spring 2005
Project 4

Polymorphic Cars

Economy Midsize Luxury

Assigned April 11,2005
Design Due 11:59pm on April 17, 2005
Program Due 11:59pm on April 24, 2005
Updates


Objectives


Project Description

In this project you will learn about inheritance and polymorphism by implementing a small set of classes in an inheritance hierarchy and by writing and using (pure) virtual functions.

All previous projects were centered on the calculations of rental and insurance charges. In project 2, there was just one generic car so one set of functions was sufficient. Project 3 expanded the car rental system to have multiple types of cars, but each car type used the same calculations for rental and insurance charges, so again, one set of functions was enough. In this project, we again expand the functionality of the car rental system by adding the concept of car maintenance - washing, waxing, changing the oil, rotating the cars, etc. As you'll see, all cars have some common type of maintenance, but different types of cars also have different types of maintenance. So unlike projects 2 and 3, you will not able to use the same functions for different car types. Given the need for different functions for different cars and the possibility or more car types in the future, the best design and implementation for this project must use inheritance and polymorphism.

To implement this project, you will create a hierarchy of cars as shown in the figure below. Each car subclass will override the necessary function(s) to perform the required car maintenance. Car maintenance in this project will be "performed" by simply printing an appropriate message indicating what kind of maintenance was performed.

The car rental system

The car rental system must maintain information about each car the company owns, each customer who can rent a car, and information about which cars are currently rented. The basic functional requirements of the car rental system are detailed below.
  1. Add a new car to the rental system -- self explanatory.
    All cars added to the rental system come directly from the car dealer with no mileage recorded on the odometer
  2. Add a new customer to the rental system - self explanatory
  3. Rent a car to a customer -- associate the car and the customer.
  4. Return a car.
    When a renter returns a car, 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 all car rental information, all renter information and the breakdown of the rental cost. Required car maintenance is performed on the car.
  5. Print a list of all cars.
    All available information about each car is printed. If a car is currently rented, all customer information for the renter is also printed.
  6. Print a list of customers
    All information about each customer (including balance due and the license tag numbers of cars currently rented) is printed.
  7. Remove a customer -- self explanatory
    It is an error to attempt to remove a customer who is currently renting a car.
  8. Remove a car -- self explanatory
    It is an error to attempt to remove a car that is currently rented.
The R & W Car Rental Company has the following policies
  1. You must be 18 years old to rent a car.
  2. PLATINUM car holders may rent multiple cars simultaneously. GOLD card members may rent just one car at a time.

Cars

Cars rented by the R & W Car Rental Company for this project are identical to those described in project 3. 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 now specified by type as economy, mid-size or luxury. The calculations for car rental and insurance are the same as project 3, 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
  1. The license tag number of the car
  2. The type of car
  3. The type of maintenance performed
  4. 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

Customers

Customers who rent cars from the R & W Car Rental Company in this project are identical to the customers in project 3. 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 car 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 car or customer, renting a car, returning a car, producing some output).

You will implement C++ class which will be used by the main portion of your program.

Code from project 3 should be reusable in project 4.

Program Requirements

General Requirements

  1. Your program must echo each command and command parameter read from the command file.
  2. The name of the command file will be the one and only command line argument.
  3. In keeping with course standards, main( ) will be implemented in a file named Proj4.cpp. The prototypes for any helper functions called from main( ) will be located in Proj4Aux.h and the functions themselves implemented in Proj4Aux.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 Proj4. Your executable must be named Proj4.
  4. Polymorphism is only possible when pointers (or references) to bases classes are used. Therefore, your rental system class MUST use a vector of pointers to the car base class to represent the cars..
  5. Separate vectors of car objects (one for each car type) are NOT permitted anywhere in your code.
  6. Dynamic memory allocation for the private data members of the car and customer classes is no longer required, but not prohibited.

Programming Hints

  1. Car objects will have to be dynamically allocated.
  2. When a pointer goes out of scope, the dynamically allocated memory it points to is NOT deallocated.
  3. Look carefully for potential memory leaks.

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 car 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.

Program Output

Your program's output must adhere to the following requirements.
  1. Customer membership card numbers must be displayed in the form 12-3456.
  2. All monetary values must be displayed with 2 decimal places.
  3. When displaying a list of cars or customers, data must be aligned in columns.
  4. 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.
  1. The renter's first and last name total no more than 20 characters.
  2. The car's model is no more than 20 characters.
  3. The car's license tag number is no more than 8 characters.
  4. Days rented and miles driven are less than 10000.
  5. The total rental charge is less than $100000.
  6. A customer will not rent more than 2 cars at a time.

The Command File

The command file has the identical format as in project 3, repeated below. 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.


Sample Output

With the exception of the new messages for car maintenance, the output for project 4 is the same as project 3, therefore no sample output is provided.

10 Points Extra Credit

As any car owner knows, keeping a log of maintenance that has been performed is good habit that insures the proper car maintenance is performed at the right time and can be used as proof that the car's warranty is still valid.

For 10 points of extra credit, add the following functionality to your program.

  1. Design and implement a class to model car maintenance data. Use good OO principles and remember that less can be more. It's not necessary (and usually undesirable) to provide a mutator and an accessor for every data member of your class.
  2. Make whatever changes are necessary to existing classes to model the maintenance log.
  3. Implement the modified PRINT command as shown above that directs your program to print the maintenance log for a specified car. The output from this new command should include all data that is printed in a the maintenance message, in a reasonable tabular format.
Please submit a "read me" file to alert the grader to your intent to recieve extra credit.

Free Advice and Information

  1. 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.
  2. Consider using the overloaded operator<< to output your classes. Even if not necessary in your code, you may find it helpful when debugging.
  3. Functions called from main( ) that are not part of any class are permitted. If you create new functions, their prototypes must be found in Proj4Aux.h and they must be implemented in Proj4Aux.cpp.
  4. Your program must provide adequate error checking as described above.
  5. 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.
  6. Review the class notes on the different methods of passing parameters. Each is best for a different situation.
  7. Be sure your function header comments list the pre- and post-conditions and handle each pre-condition that is not met.
  8. Your program will be tested with a variety of conditions.
  9. Use incremental development.
  10. Expect to use/modify code from this project in project 5. Design and code accordingly.

Project Design Assignment

Your project design document for project 4 must be named p4design.txt. Be sure to read the
design specification carefully. Submit your design in the usual way: submit cs202 Proj4 p4design.txt

Project Makefile

You must provide the makefile for this project. Use the makefile you submitted for project 3 and modify it appropriately. If you don't change the names of the files from project 3, the changes will be minimal.

The graders will be typing the command make Proj4 when they grade your project. This command must cause all .cpp files to be compiled and the executable named Proj4 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, Proj4, 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.

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.
  1. Your class implementation and class usage
  2. Proper use of const
  3. Your function header comments (particularly pre- and post-conditions)
  4. In-line comments
  5. 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 Proj4

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.


Last Modified: Tuesday, 12-Apr-2005 00:00:19 EDT