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

CMSC 202 Fall 2005
Project 5

Netflux - Multiple Object-types in an Internet-based Rental System

Assigned November 28, 2005
Design Due 11:59pm on Sunday, December 4, 2005
Program Due 11:59pm on Tuesday, December 13, 2005
Updates

Objectives


Project Description

In this fifth and final phase of the project you will be experimenting with C++ templates and exceptions in your application.

The Rental System

The Rental System manages a list of customers who want to rent items, a list of available items, and a list of desired items for each customer (the customer's "queue"). The system also reacts to the following commands:

OPEN

CUSTOMER

RENT

RETURN

QUEUE

PRINT_ITEMS

PRINT_CUSTOMERS

PRINT_USER

PRINT_SORTED_CUSTOMERS

PRINT_LOG

Data

Rental System

The Rental System manages the collection of Customers and in-stock items. 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:

Customers

Basic Functionality

Customers who rent items are essentially the same as in previous projects. There are multiple customers allowed in the system. Extensions to the representation of a Customer are described in the next section.

Customers each have the following information, you may represent these in a variety of ways and are not limited to this exact representation:

Polymorphic Functionality

There are three different kinds of customers in the Rental System. Your project must use Inheritance and Polymorphism to implement a Customer class Hierarchy. Each kind of Customer has a unique cost associated with renting their items as well as a unique limit to the number of items that they can rent. Customers may not change types - once added to the system, they will remain the same type of Customer.

Notice that all items in the rental system have the same charges - so renting a DVD for a Basic customer costs the same as renting a Book for a Basic customer. This is to simplify your code changes. If this were the final production system, this simplification may or may not be reasonable.

Your Customer class hierarchy should look essentially like this:

Items

Your Rental System must be template based in order to support objects of various types. Your system need only support ONE of these types at a time. You must modify your system to rent Books in addition to renting DVDs. Any type that your system can support must support the following operations:

Books

Books are very similar to DVDs, they have a title and a number, but instead of a number of discs, they have a number of volumes. Multiple copies of the same Book are allowed. It can be assumed that the first Book added to the system has the correct Number of Volumes and Title information.

Books each have the following information:

You should take the maximum advantage of the similarities between Books and DVDs in order to support your templated Rental System.

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:


Program Requirements

Templates

Your Rental System must be able to be created (using templates) to allow creation of a "Rental System for DVDs" or a "Rental System for Books". Do not attempt to support BOTH DVDs and Books within the same instance of a Rental System (i.e. using some strange inheritance). Do NOT manually create two different Rental Systems. You MUST use templates in your solution. There should be no references to "DVD" or "Book" WITHIN the Rental System. Obviously, your main() or auxiliary functions will at some point need to be able to parse the command line, and then will need to know what kind of Rental System you are creating. However, after that point in processing, there should be no reason for your code to know the difference (hint, hint: how will you create a new DVD/Book to add to the system using templates?).

Your application must support a second command line parameter indicating which type of system the user would like to create, one with "DVDS" or "BOOKS". You can assume that the capitalized version are the ONLY acceptable version of the parameter. This command line parameter will follow the command-file name. If some other command is supplied, the program should print an error and terminate (unless you implement the extra credit as described).

Examples:

Proj5 command.txt DVDS
Proj5 command.txt BOOKS

Exceptions

Your application must also support throwing exceptions instead of simply producing the error messages that are supported by your current system. You MUST throw exception objects (not just ints, chars, bools, or strings) that will be instantiations of your own exception classes.

All error conditions detected by your classes MUST result in the throwing of an exception. All appropriate code must be containted in a "try block". All exceptions must be caught where appropriate. All error messages that are currently required to be printed (i.e. improperly formatted commands) must continue to be printed.

All of your exception classes can (but don't have to) be in the same file (ex: Exceptions.h and Exceptions.cpp). You are encouraged (but not required) to use an inheritance hierarchy in defining your exception classes. You may design your exception classes as elaborately or simply as your code requires.

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 can find Utility.o, Utility.cpp and Utility.h in the following location:

/afs/umbc.edu/users/d/a/dana3/pub/CMSC202/p5/

The one public method of the Utility class is:

static bool GetCommand(istream& sin, vector& command);
The GetCommand method makes the following guarantees: There are constants for each command included in the Utility.h so you do not have to declare those in your own code.

If you would like to have the Utility class throw exceptions - you must add this functionality yourself (since everyone will have different exception classes, it was unreasonable to add this as a standard feature).

Extra Credit

In order to be considered for the extra credit, you must submit a README file to the graders describing what you did.

Supporting Arbitrary Costs - 10 pts

In general, a system like this should be able to support a variety of costs for each of the objects. If a library wanted to adapt the system to support book rental, then we should provide a facility for doing that. Also, objects will differ substantially in their rental cost. For example, if we rent Bicycles instead of DVDs, the cost should be significantly higher. Expand your template to support arbitrary costs.

Your system should expand the Book class to support the following cost structure:

You should not include any code (other than the main() or auxiliary functions) that know what type of object our Rental System stores. You must include all of these values in the templated instantiation of a Rental System object (hint, hint). You should NOT have two Books classes. Nor should your Books clas have any logic that decides which instantiation it has. Use templates.

Your system will be tested using the following command line:
Proj5 command.dat BOOKS_EC
Your system must continue to function normally with the BOOKS parameter in the normal test cases.

Supporting Arbitrary Types - 10 pts

In general, a system like this should be able to support a variety of objects. Expand your template so that it supports additional types.

Any type that can be used in this system must have 3 components:

Your program will be tested by supplying a third command-line parameter of a type that represents the type of object that will represent the Unique identifier. For simplicity - your code need only accept "STRING" and "INT".

In example:
Proj5 command.dat BOOKS INT
Indicates that we want a Rental System of Books that have an integer as their Unique identifier. You can assume that the correct type will be supplied in the command file. If this parameter is not supplied, then you can assume whatever type your current system supports - this will support "backwards compatibility" with the normal test suite. This should work for both Books and DVDs with strings and ints. You can safely assume that all integer identifiers will be positive. Do not worry about range-testing these identifiers, you can assume they are all valid. You need only assume that the operator==, operator<< and operator>> exist for the templated type.

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 command keywords are all uppercase.

Valid commands for the system are as follows:

Command File Error Checking

Sample Command File

Commands that have been tested and described in previous projects have been left off of this example to eliminate clutter. However, your program must still support the complete functionality of the system as described above. OPEN stock.txt CUSTOMER Fred Flintstone fflint0 1234123456785678 BASIC 123 Bedrock LN Apt. 7 Rock Vegas NV 12345 QUEUE 12345 fflint0 QUEUE 423644 fflint0 QUEUE 826918 fflint0 RENT fflint0 RETURN 12345 fflint0 RETURN 423644 fflint0 RETURN 826918 fflint0 PRINT_ITEMS

Stock File

You can assume that any stock file that we test with your program is properly formatted and that all data is valid. You need not perform ANY error checking on the stock file. The stock file represents all the items 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 6 Harry Potter Collection 423644 1 Absolute C++ 826918 3 Lord of the Rings Collection 759203 1 Timeline 927833 1 Ender's Game 32145 1 Chaos 928173 6 Hitchhiker's Guide to the Galaxy Anthology

General Requirements

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:
  1. Customer credit card numbers must be displayed in the form 1234-5678-9012-3456.
  2. All monetary values must be displayed with 2 decimal places.
  3. When displaying a list of DVDs or customers, data must be aligned in columns.
  4. Lists of DVDs/Books/customers shall be displayed in the order DVDs/Books/customers were added to the rental system.
  5. As the stock file is processed, messages informing the user of each item that is being added shall be displayed
For purposes of formatting output only, you make the following assumption:
  1. The renter's first and last name total no more than 20 characters.
  2. The renter's username totals no more than 20 characters.

Sample Output

This sample output was produced from the sample command file above paired with the sample stock file above. It is only a sample. It is not necessary that your output match the format exactly, but you must adhere to the program output requirements above. The customer type and "flat fee" representations should stay the same as in Project 4. CMD: OPEN stock.txt ADDED: 12345 6 Harry Potter Collection ADDED: 423644 1 Absolute C++ ADDED: 826918 3 Lord of the Rings Collection ADDED: 759203 1 Timeline ADDED: 927833 1 Ender's Game ADDED: 32145 1 Chaos ADDED: 928173 6 Hitchhiker's Guide to the Galaxy Anthology CMD: CUSTOMER Fred Flintstone fflint0 1234123456785678 BASIC CMD: 123 Bedrock LN Apt. 7 CMD: Rock Vegas NV 12345 CMD: QUEUE 12345 fflint0 CMD: QUEUE 423644 fflint0 CMD: QUEUE 826918 fflint0 CMD: RENT fflint0 ------------------------------------------------------------------ RENTAL RECEIPT --------------------- Customer Information --------------------- Name: Fred Flintstone Card: 1234-1234-5678-5678 Username: fflint0 Type: BASIC Address: 123 Bedrock LN Apt. 7 Rock Vegas NV 12345 --------------------- Rental Requests --------------------- Number Size Title ------- ----- -------------------------------------------- 012-345 6 Harry Potter Collection 423-644 1 Absolute C++ 826-918 3 Lord of the Rings --------------------- Charges Detail --------------------- Number Size Per Size Subtotal -------- -------- -------- -------- 012-345 6 $ .99 $ 5.94 423-644 1 $ .99 $ .99 826-918 3 $ .99 $ 2.97 -------- TOTAL $ 9.90 ------------------------------------------------------------------ CMD: RETURN 12345 fflint0 CMD: RETURN 423644 fflint0 CMD: RETURN 826918 fflint0

Free Advice and Information

  1. Every attempt has been made to highlight the changes in BLUE so that you can quickly and easily see what functionality has changed. Remember to build the new functionality slowly - use modular composition - add one new piece at a time, ensuring that the system still works correctly after adding each piece.
  2. DO NOT attempt to develop this entire application at once! We recommend adding the components in the following order to limit changes:
    • Change the PRINT_DVDS to PRINT_ITEMS
    • Write a single Exception class.
    • Convert all error messages into exception throws.
    • Add try/catch blocks to catch these exceptions.
    • Add additional exception classes to handle more specific errors.
    • Extend your try/catch blocks to handle these exceptions.
    • Modify the Customer class to handle templated types (if necessary). Start with only DVD objects.
    • Modify the Rental System class to handle templated types. Start with only DVD objects.
    • Build the Book class(es).
    • Hard-code the creation of a Rental System of Books.
    • Extend the command line to allow creation of Rental System using either Books or DVDs.
    • Create several testing command files to thoroughly test your system.
  3. Carefully consider your design. In general, a minimal class interface is best. Consider how best to reuse code.
  4. 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. You must modify the makefile provided to account for these files.
  5. Your program must provide adequate error checking as described above.
  6. Your program will be tested with a variety of conditions.
  7. Use incremental development. Add ~5 lines, save, compile, test. Use function/method stubs to develop a class incrementally.
  8. Don't procrastinate.

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 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 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, and backup files created by the editor. More information about these commands can be found at the bottom of the makefile.

Compiler:
Your makefile must provide a rule that forces the use of the /usr/local/bin/g++ compiler for every .cpp file that you have as part of your project. You will have 5 pts deducted for "Makefile errors" if your makefile does not use the /usr/local/bin/g++ with -Wall and -ansi flags for EVERY .cpp file that you have included.


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. The focus of this project is demonstrating understanding of templates and exceptions within C++, so much of the Correctness points will be dedicated toward your design and implementation of the Templated class(es) and exceptions.

15% - Coding Standards

Your code adheres to the CMSC 202 coding standards as discussed and reviewed in class.

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.


Last Modified: Tuesday, 29-Nov-2005 19:19:59 EST