CMSC 202 Fall 2004
Project 5
Templates and Exceptions
Assigned |
Mon Nov 29th, 2004 |
Design Due |
Sunday Dec 5th at 11:59pm |
Program Due |
Tuesday Dec 14th at 11:59pm |
Updates |
None |
Objectives
- To gain experience writing and using template classes and
functions
- To gain experience writing exception classes
- To gain experience writing code that will try/throw/catch
Class templates and function templates are basic
tools for writing generic, reusable code.
They are fundamental for implementing abstract data types (ADTs) using
C++. In this project
you will re-implement the Truck as a class template. You will use the
template to create
trucks which deliver boxes of toys (as in previous projects), cans of
paint and bottles
of glue.
Exceptions are an important part of any robust
application. In this project, you will be designing and using two
exception classes.
This project continues our simulation of tinker
toy manufacturing and assembling.
In this project, you will modify and extend project 4.
The tinker toy manufacturing plant now has the added responsibilities
of delivering
cans of paint and bottles of glue to the assembly plant. Your program
will create trucks
to carry the paint and glue (and the boxes of toys) by using the Truck
class template.
As in project 4, we will manufacture tinker toys and place them
in boxes for delivery to the assembly plant. The rules for
making each kind of tinker toy are the same as in projects 3 and 4.
A second truck will be loaded with cans of paint to be delivered to the
assembly plant.
A third truck will be loaded with bottles of glue to be delivered to
the assembly plant.
Unlike previous project, these trucks have limited capacity.
Also as in previous projects, commands will be read
and processed from a command file. The file will contain the same
commands that you processed in project 4, plus two new commands that direct your
program to load paint and glue onto their respective trucks.
All valid commands in the file are properly formatted,
but you may encounter
invalid commands. See the
command file
section below.
Rather than specify all classes from scratch, this description
highlights only the similarities and modifications to project 4.
The Classes
All data members of all classes must be private
Toy class hierarchy
The toy classes are unchanged from project 4.
It is not necessary to count the number of toys constructed and
destroyed as in project 4.
Box
The box class is unchanged.
Those who had trouble with the Box in project 4 may copy
Box.h and Box.cpp from Mr. Frey's public directory.
The Truck is modeled using a C++ class template named Truck.
The Truck's functionality is basically unchanged from project 4, but as
a template this class will be used to deliver boxes of toys, cans of paint and bottles of glue.
Truck Modifications
- Unfortunately our trucks now have limited capacity in terms of
the number of items which may be delivered. The maximum number of
boxes, cans of paint, and bottles of glue will be read from the command
file.
- The Truck will throw an exception if an attempt is made to
overload the truck or to deliver an empty truck.
- The Truck's output is now more generic
- Current Load - the number of items and brief description of
the items currently on the truck waiting for delivery.
- Delivery Log - A list of all deliveries, including the
assembly plant name, the number of miles, the number of items delivered, and a brief description of the
items.
DeliveryRecord
Since this class must now record the delivery of boxes, paint, and glue,
it's necessary that a description of what was delivered be added to
this class.
You may choose to use or remove the dynamically allocated data members and
associated member functions that were required in project 3.
DeliveryLog
This class is unchanged from project 4.
Can of Paint
Implement a new class that models a can of paint which has the
attributes of color (a string) and size (an int; in gallons). The only public
method allowed is the constructor.
Cans of paint are loaded onto a truck for delivery to the assembly
plant.
Bottle of Glue
Implement a new class that models a bottle of
glue which has only the attribute of type (a string; e.g. wood glue, super glue, Elmer's glue).
The only public method allowed is the constructor.
Bottles of glue are loaded onto a truck for delivery to the assembly
plant.
Exception Classes
The truck class now detects two errors for which it throws exceptions.
You must design and implement an exception class for each error. Your
classes may contain as much or as little information as you deem
necessary
as long as the user may handle the exceptions in the manner described
below.
- An attempt to overload the truck
- An error message is displayed indicating the maximum number of
items allowed on the truck and the details of the item which was trying
to be loaded on the truck.
- Processing of the current command ends.
- If a box of toys does not fit in the truck
- the toys in the box are NOT counted in the production summary
- unused boxes are destroyed
- An attempt to deliver an empty truck results in an error message
indicating the intended destination and the mileage.
The command file has the following format. 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.
- The first line of the command file contains three integers which
are the maximum number of boxes, cans of paint and bottles of glue that
a truck can deliver, in that order.
- The second line of the command file contains an
integer (let's call it N), which tells how many
colors of TinkerToys we'll be manufacturing.
- The next N lines contain the names of the
colors (one per line without spaces). Color names are guaranteed to be
unique.
- Each non-blank line thereafter contains one of the
following commands. Any command may
appear in the file multiple times (or not at all) and the commands may
appear in any order.
- TOYS type count color <other
attributes>
This command directs your program to produce the specified tinker toy
where type is one of "Round", "Square" or "Rod", count
is an integer, and color is a string. You may assume that the
color matches on of the N colors read previously from the file.
If type is "Round", then <other attributes> will be the
number of holes (integer) and the diameter (float)
If type is "Square", the <other attributes> will be the
number of holes (integer) and the length of each side (integer)
If type is "Rod", the <other attributes> will be the
length of the RodToy (integer). Recall that all rods are 1/4 inch
in diameter.
- BOXES count length width height
Where all parameters are integers. This command informs your program
that count boxes with the specified dimensions have been
delivered and are ready to be filled with Toys
- PAINT count gallons color
where count is an integer, gallons is an integer and color
is an arbitrary string which may contain spaces.
This command instructs your program to load count cans of paint
onto the paint truck
for delivery.
- GLUE count type
where count is an integer and type is an arbitrary
string which may contain spaces.
This command instructs your program to load count bottles of
glue onto the glue truck
for delivery.
- PRINT
This command instructs your program to print the detailed information
for each truck.
- DELIVER what miles destination
where what is one of "BOXES", "PAINT" or "GLUE", indicating
which truck should deliver its load, miles is an integer and destination
is the name
of an assembly plant (which may contain spaces).
This command instructs your program to drive the specified truck the
specified number of miles to the specified destination, then unload its
contents and return
to the manufacturing site to be loaded again.
- In the event that a command file contains
consecutive BOXES commands, boxes must be filled
in the order delivered (i.e. first in, first out).
- In addition to the toy summary produced in
projects 3 and 4, your summary should include
the total number of cans of paint and the total number of bottles of
glue loaded onto their respective trucks for delivery.
- As in previous projects, the output for each box (box number, number of toys and toy
color) must appear in right-justified columns.
No sample output is provided for this project. Examples of new output
for this project are provided below to indicate the required data.
You may format your output in any reasonable way that is consistent
with past projects.
- When an attempt is made to overload the truck, the error message
produced must contain the following information -- the max number of items
allowed on the truck and full details of the item that was trying to be loaded.
For example --
Box Truck Full (max 20 items) trying to load a box containing
9 DkBlue Round Toy(s) with diameter 3.5 and 2 holes
- When an attempt is made to deliver an empty truck, the error
message produced must contain the following information -- the type of truck
(box, paint, glue), the destination and the mileage. For example --
Attempted to deliver an empty glue truck 6 miles to somewhere
- When details of a can of paint are displayed, the color and
number of gallons must be shown.
- For bottles of glue, only the glue type must be displayed.
- THINK about this project before coding. Be
sure
you understand the relationships
among the objects.
- 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 new files.
- Use incremental development !!!!!
- Mr. Frey's public directory for this project
is /afs/umbc.edu/users/d/e/dennis/pub/CMSC202/p5.
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.
You must provide the makefile for this
project.
Use
the makefile from project 4
and modify it appropriately. If you don't change the names of the
files from project 4, 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.
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 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.
- 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 your project in the usual way.
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.