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

Project 5
Templates

Assigned April 28 2003
Program Due Sunday May 11, 2003, 11:59pm
Updates April 29, 12:45pm
In the Command File section, there was a naming inconsistency between UNLOAD-BOX and DELIVER-BOX (same for SACK). UNLOAD-BOX and UNLOAD-SACK have been changed to DELIVER-BOX and DELIVER-SACK. These are the commands which will be found in the command file.

In the Truck class template, special syntax is needed to declare operator<< a friend. Use the syntax

friend ostream& operator<< <T> (....); Note the <T>.
Note also that this applies ONLY to the friend declaration in the .H file, NOT to the function header in the .C file.

Objectives


Project Description

In this project you will implement a class to model a delivery truck. Since trucks can carry any type of cargo, it is appropriate to use a C++ class template for the truck. You will also implement classes to model boxes and sacks carried in the truck.

Your project will simulate exactly two trucks -- one containing boxes, the other containing sacks. Your truck will load boxes/sacks, drive from one destination to another, deliver boxes/sacks and print an inventory of the truck's contents. Commands read from a command file direct your trucks.
The command line will have three arguments

  1. The maximum number of boxes a truck can carry regardless of the box's size and weight.
  2. The maximum number of sacks a truck can carry, regardless of the sacks contents or weight.
  3. The name of the command file


Class Definitions

For this project you will implement the Truck class template, the Sack class and the Box class. The section on
exceptions will discuss exception classes.

The Truck Class Template

Since a truck can carry any kind of cargo, the truck will be implemented as a class template.

Our truck has the following minimum attributes. Other private attributes may be added if you find them helpful in your implementation

  1. Its capacity as read from the command line
  2. Its current location
  3. The number of miles driven
  4. A list of the current contents of the truck
Our truck supports the following public oprerations. No other public methods are permitted. You may define any private methods you wish. In these definitions, "T" is the template parameter. The return types and constness of the methods have been purposely omitted.
  1. Construction of an empty truck. A newly created empty truck has a user specified capacity (default capacity is 25), has been driven zero miles and begins its journey at a location specified as "Warehouse".
  2. Destruction of a truck.
  3. Load( const T& item);
    Load an item into the truck. Duplicate items are permitted.
  4. Unload( const T& item);
    Unload the specified item from the truck. If the item to be unloaded is one of a set of duplicates, unload any one of the duplicates.
  5. Drive( const string& where, int miles);
    Move the truck to the new location.
In addition, you must implement the overloaded operator<< for the truck as a non-member friend function. This operator will output the truck's current location, miles driven, and a list of items currently in the truck.

The Sack Class

The Sack class has just two attributes -- its contents (a case-sensitive string) and its weight in pounds. (a positive integer). A sack is uniquely identified by its attributes.

The Sack supports the following public operations. No other public methods are permitted. You may define any private methods you wish. The return types and constness of the methods have been purposely omitted.

  1. Construction of a Sack with user specified contents and weight. By default, a new Sack contains one pound of Air.
  2. Destruction of a Sack.
  3. operator==( const Sack& sack); to determine if two sacks are identical.
  4. operator!=( const Sack& sack); to determine if two sacks are different.
In addition, you must implement the overloaded operator<< for the Sack as a non-member friend function. This operator will output both attributes of the sack on a single line.

The Box Class

The Box class has the following minimum attributes which may be assumed to be positive integers -- length, width, height, and weight in pounds. A Box is uniquely identified by its attributes.

The Box class supports the following public operations. No other public methods are permitted. You may define any private methods you wish. The return types and constness of the methods have been purposely omitted.

  1. Construction of a box with user specified attributes. By default, a new box has length, width, height and weight = 1.
  2. Destruction of a box.
  3. operator==( const Box& box); to determine if two boxes are identical (e.g. have all the same attributes).
  4. operator!=( const Box& box); to determine if two boxes are different.
In addition, you must implement the overloaded operator<< for the Box as a non-member friend function. This operator will output all attributes of the box on a single line, clearly identifying the weight.


Exceptions

At a minimum, your project must detect the following exception conditions and throw an exception. You may choose to create and throw an exception class, or throw a string with an appropriate message.
  1. An attempt to load a box or sack into a truck that is full
  2. An attempt to unload a box or sack from a truck that is empty
  3. An attempt to deliver a non-existent box or sack
Exceptions should also be thrown for any other exceptional conditions which may occur in your particular implementation.

The Command File

The command file has the following format. Blank lines should be ignored. Any non-blank line may be assumed to be properly formatted and all data may be assumed to be valid. The attributes of the box for the LOAD-BOX and DELIVER-BOX commands are separated by white space and occur in the following order: length, width, height, weight.

The attributes of the sack for the LOAD-SACK and DELIVER-SACK commands are separated by white space and occur in the following order: contents (a string with no embedded spaces), weight in pounds.


Sample Output

Your program must produce two required outputs
  1. Each time a command is read from the command file the command and its parameters must be displayed.
  2. Each time the PRINT command is encountered, the current location, current mileage and list of current contents of both trucks must be printed. The attributes of each box and sack must be displayed.
This sample output was NOT produced by processing any command file. It is intended solely to provide an example of an acceptable output format. Any similar format is allowed as long as all required data is provided. Be sure the appropriate function is doing the appropriate output. linux1[5]% Proj5 50 40 command1.dat Processing File: command1.dat Cmd: PRINT BOX TRUCK The truck's current locations is: Warehouse The truck has driven 0 miles so far The truck is empty SACK TRUCK The truck's current locations is: Warehouse The truck has driven 0 miles so far The truck is empty Cmd: LOAD-BOX 2 3 4 9 Cmd: LOAD-BOX 2 4 5 12 Cmd: LOAD-SACK corn 50 Cmd: LOAD-BOX 3 5 7 9 Cmd: PRINT BOX TRUCK The truck's current locations is: Warehouse The truck has driven 0 miles so far The truck's contents 2 x 3 x 4 box weighing 9 lbs 2 x 4 x 5 box weighing 12 lbs 3 x 5 x 7 box weighing 9 lbs SACK TRUCK The truck's current locations is: Warehouse The truck has driven 0 miles so far The truck's contents 50 pound sack of corn Cmd: DRIVE-SACK Baltimore 30 Cmd: DRIVE-BOX Catonsville 10 Cmd: DELIVER-BOX 2 4 5 12 Cmd: PRINT BOX TRUCK The truck's current locations is: Cantonsville The truck has driven 10 miles so far The truck's contents 2 x 3 x 4 box weighing 9 lbs 3 x 5 x 7 box weighing 9 lbs SACK TRUCK The truck's current locations is: Baltimore The truck has driven 30 miles so far The truck's contents 50 pound sack of corn Cmd: DELIVER-BOX 3 5 7 10 Error: There is no such box

Hints, Suggestions and Free advice

  1. Mr. Frey's public directory for this project is
    /afs/umbc.edu/users/d/e/dennis/pub/CMSC202/proj5
  2. Use incremental development
  3. Use a simple approach to reading the file. Using getline( ) is NOT recommended. A simple approach also makes EOF detection easier.
  4. Visit the discussion board
  5. Since Truck.H and Truck.C are templates, there are special considerations
    1. Remember to guard both files
    2. Remember to #include Truck.C at the end of Truck.H
    3. DO NOT list Truck.o as an object file in your makefile; Truck.C gets included in Proj5.C (via Truck.H) and compiled as part of Proj5.C

Project Design Assignment

Since we have specified the class interface, there is no design assignment for project 5.

Project Make File

You are required to submit a make file with this project. The grader should simply need to type "make Proj5" and your project should compile and link to an executable called Proj5. The grader should also have the ability to do a "make clean" and "make cleanest."

See the make tutorial for more help on make and makefiles.


Project 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. This list should not be considered comprehensive, but rather a suggested list of things you should consider before turning in your project.

85% - Correctness -- 85%

  1. Have you verified the command line and its parameters?
  2. Are all appropriate member functions "const"?
  3. Are all return values being returned in the appropriate way (by value, by reference, by const reference)?
  4. Are all function parameters being passed into the function in the appropriate way (by value, by reference, by const reference)?
  5. Does your output meet all output requirements? Is all output produced by the appropriate function?
  6. Do all appropriate functions have the proper PreConditions? If so, are all PreConditions handled?
  7. Are you throwing exceptions wherever required?
  8. Are all exceptions being caught and handled properly? I.e. being thrown by the appropriate methods, caught by the caller and dealt with appropriately?
  9. Did you remember to delete all dynamically allocated memory (if any)?
  10. Are your classes implemented using appropriate OOP principles -- encapsulation and abstraction.
  11. Does your implementation maximize code reuse?
  12. Does your Truck load/unload/print duplicate items correctly?

15% - Coding Standards

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

Project Submission

You should submit the following files.

Submit as follows:

submit cs202 Proj5 <list of files> A complete guide to submit tools is available on the course website.

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.


Last Modified: Wednesday, 30-Apr-2003 14:12:47 EDT