Project 1
Assigned |
29 August 2001 |
Due |
16 Sep 2001 |
Updated:
| 05 Sep 2001 -- default constructors for PerishableGoods
and EquipmentGoods added
|
Background
Abstract Data Types (ADT) are a central idea of this course and of Object-oriented
programming in general. Recall that an ADT has two parts: (1) a description
of the elements that make up the type, and (2) a description of the operations
allowed on instances of the type. The ADT idea is implemented in C++ as
a class.
The ADT is one of the most powerful and important ideas in computer
science. This project will give you some exercise in using ADTs.
Another important OOP idea, parametric polymorphism, is implemented
in C++ by templates. This project will give you some practice with C++
templates.
You will be given a Makefile, include headers from multiple directories,
and compile code from multiple directories. These are commonly used techniques
in industry, so they're worth learning for future reference. You will be
responsible for creating your own makefiles for all other projects.
Description
This program simulates the activity of trucks owned by the UMBC trucking
company. Each truck may carry only one type of deliverable goods
at a time. This program will read activities from a file which will
load goods onto the truck, deliver goods by removing them from the truck
and move the truck from site to site.
This program introduces you to the author's vector template class,
described in appendix B of the text
and to the author's string class, also described in appendix
B.
The ADTs described in the Exercises are expanded on in the "ADT"
section, below. Use these expanded versions to design your classes.
Please remember that you must provide good documentation as described in
the "Project Organization"
handout.
Here are your tasks:
-
Read and understand the text description of the vector
ADT and its C++ implementation in Appendix B. Code for vector
is available to you in the GL directory:
/afs/umbc.edu/users/d/e/dennis/pub/CMSC341/
-
Read and understand the text description of the string
ADT and its C++ implementation in Appendix B. Code for string
is available to you in the GL directory:
/afs/umbc.edu/users/d/e/dennis/pub/CMSC341/
-
Implement the Truck class as a C++ template class. Your class must
use a vector to store the current contents of the truck.
-
Implement two classes to represent deliverable goods -- perishable goods
and equipment.
-
Use the main function provided in the file:
/afs/umbc.edu/users/d/e/dennis/pub/CMSC341/Proj1/Proj1.C
Use main() as-is, no changes.
Note: There is no need to copy Proj1.C to your own directory.
Your makefile must access the file from the directory in which it is provided.
Do not submit Proj1.C.
- Write the set of auxiliarly functions as required by Proj1.C -- getCmdLine( ),
DeliveryGoods( ), etc. and put them in the file Proj1_aux.C. Their protoypes belong
in Proj1_aux.H.
-
Copy the makefile from
/afs/umbc.edu/users/d/e/dennis/pub/CMSC341/Proj1/Makefile
to your own directory and modify it as needed.
It can be used without modification if you follow the file names in the
makefile.
-
Answer the questions posed in 341-Fall01-proj1_questions.txt. Copy the
file
/afs/umbc.edu/users/d/e/dennis/pub/CMSC341/Proj1/341-Fall01-p1_questions.txt
to your own directory and edit it to provide your answers to the questions.
Don't forget to submit the edited file; it is 10% of this project's grade.
Definition of the ADT
Truck:
A Truck carries a homogeneous collection of goods. Duplicates are NOT allowed.
Every Truck has essentially unlimited capacity, the number of goods
it is capable of holding. Its size, the actual number of goods it
currently holds at a given time, increases as goods are loaded and decreases
as they are delivered. A truck has three required attributes -- list
of goods currently on the truck, the total miles driven so far, and the
trucks current location. If other private attributes are helpful,
feel free to include them.
The operations allowed on a Truck are:
-
Construction of an empty Truck (constructor of no arguments). An
empty truck starts at location "Depot" and has driven zero miles.
-
Construction of a Truck as a copy of another Truck (copy constructor).
-
Destruction of a Truck (destructor).
-
Assignment operator (operator =)
-
load( const item &)
that loads the specified item into the truck. Note that NO duplicate
items may be loaded into the truck, although an item may be loaded, then
delivered and an identical item reloaded.
-
deliver (const item &)
that removes the specified item from the truck.
-
drive (string destination, int miles) that
moves the truck from its current location to the specified location which
is "miles" away.
-
bool isEmpty() const returns true
if the truck is empty.
-
void MakeEmpty() causes the size of the Truck
to become zero.
-
An overloaded non-member function operator <<
This operator outputs the current inventory of the truck, it's current
location and the total number of miles driven so far.
Note: Your implementation must use the print idiom described
in the Weiss text on page 35 (in the Employee class). This means
you must write both the print method of the
Truck class and a non-class, non-friend function
Perishable goods:
Perishable goods are items such as fruit and vegetables
that have a short, limited shelflife. A perishable good has three
attributes -- type (a string), color (a string) and weight (an integer).
The operations on perishable goods are
- Default construction of a perishable good. You choose the appropriate
default values (if any).
-
Construction of a perishable good, given the type, color and weight.
-
Construction of a persihable good as a copy of an existing perishable good
(copy constructor)
-
Destruction of a perishable good
-
Assignment operator (operator = )
-
An equality operator (operator ==)
-
An overloaded non-member function operator <<
This operator outputs the attributes of the perishable good.
Note: Your implementation must use the print idiom described
in the Weiss text on page 35 (in the Employee class). This means
you must write both the print method of the
perishable goods class and a non-class, non-friend function
Equipment:
Equipment is items such as bulldozers, lawn mowers,
etc. that are used to do work. Equipment has two attributes -- type
(a string), and weight (an integer).
The operations on equipment are
-
Default constructor -- you choose the appropriate default values if any
-
Construction of equipment, given the type, and weight.
-
Construction of equipment as a copy of an existing equipment object (copy
constructor)
-
Destruction of equipment
-
Assignment operator (operator = )
-
An equality operator (operator == )
-
An overloaded non-member function operator <<
This operator outputs the attributes of the equipment.
Note: Your implementation must use the print idiom described
in the Weiss text on page 35 (in the Employee class). This means
you must write both the print method of the
equipment goods class and a non-class, non-friend function
The Command Line
Project 1 will be invoked with a command line that consists
of two arguments.
The first argument will be "perishable" or "equipment",
telling the program what kind of goods to deliver.
The second arguement will be the name of the file
that contains the trucks delivery instructions as described in the command
file section below.
The Command File
Commands in the file tell the truck what to do -- load
goods, deliver goods, print its current status, or drive to
the next destination (with the number of miles). Each line in
the file represents one command. Blank lines may appear anywhere
in the file and should be ignored.
The command file format follows:
-
DRIVE <destination> <miles> -- tells the truck to drive to the given
"destination" (a string). The distance to the destination is given
by "miles", which is a positive integer.
-
PRINT -- tells the truck to print it's current inventory, it's current
location and the total number of miles it has driven so far. You are free
to choose any reasonable format for the truck's output that
you like.
-
LOAD <goods attributes> -- tells the truck to load the specified goods
onto the truck. If the goods are already on the truck, an appropriate
error message should be displayed.
-
DELIVER <goods attributes> -- tells the truck to deliver the specified
goods at the current location. If the goods are not on the truck,
an appropriate error message should be displayed.
The attribute of the goods for the LOAD and DELVER commands
will vary depending on the type of goods being deliverd by the truck.
For perishable goods, the attributes appear
in the following order
-
a string which is the name of the goods
-
a string which represents the color of the goods
-
an integer which represents the weight of the goods in pounds
For equipment, the attributes appear in the following
order
-
a string which is the name of the equipment
-
an integer which represents the weight of the equipment in pounds
Main Function Definition
The file containing the main function is on the GL machine:
/afs/umbc.edu/users/d/e/dennis/pub/CMSC341/Proj1/Proj1.C
Remember, there is no need for you to copy this to your own directory.
Use the main function as is; no changes, please. Reference it with your
makefile.
Sample Output
Sample output is available for your study at
/afs/umbc.edu/users/d/e/dennis/pub/CMSC341/Proj1/341-Fall01-p1-sample_output.txt
Note that this output was NOT created by executing any program,
but generated artificially by hand.
Note also that it is required that every command that is read from
the command file is echoed as part of the output.
Files To Be Submitted
You should submit only the files you have written, a makefile, and the
file containing your answers to the questions. The files to be submitted
are:
-
Files for implementing the Truck, PerishableGoods and
EquipmentGoods classes
-
Auxiliary files which contain the prototypes and defintions of auxiliary
functions such as getCmdLine( ), deliverPerishableGoods(
) and deliverEquipment( ).
-
your makefile.
-
341-Fall01-proj1_questions.txt - containing
your answers to the questions.
Please do not submit any of the files provided to you such as Proj1.C,
string.c, string.h, vector.c or vector.h
Submit the files using the procedure given to you for your section of
the course.
If your makefile is set up correctly, you should be able to excute
the command make submit.
Submit Tools
There are a number of tools available to you to check on your submittal.
It is your responsibility to ensure that the submittal is correct and will
result in a successful
compilation of your project. Do not wait till the last minute to submit
your files. Give yourself enough time to check that your submittal is correct.
If you don't submit a project correctly, you will not get credit
for it. Why throw away all that hard work you did to write the project?
Check your
submittals. Make sure they work. Do this before the due date.
Documentation for the submit program is on the web at http://www.gl.umbc.edu/submit/.
One of the tools provided by the submit program is
submitls. It lists the names of the files you have submitted.
Additionally, there are two programs for use only by CMSC-341 students
(not part of the UCS submit program). They are in the directory
/afs/umbc.edu/users/d/e/dennis/pub/CMSC341/ and are
named submitmake and submitrun. You can
use these programs to
make or run your submitted projects.
The syntax is similar to that for submit:
submitmake <class> <project>
Example: submitmake cs341 Proj1
This makes the project, and shows you the report from the make utility.
It cleans up the directory after making the project (removes .o and ii_files),
but leaves the
executable in place.
submitrun <class> <project> [command-line args]
Example: submitrun cs341Proj1 checkers checkfile.dat
This runs the project, assuming there is an executable (i.e. submitmake
was run successfully).
Grading and Academic Integrity
Your project will be tested using a variety of command lines, some of which
will be invalid.
Your project will also be tested using a variety of command files which
will test various conditions which your code should handle.
Project grading is described in the Project
Policy handout.
Your answers to 341-Fall01-proj1_questions.txt
are worth 10% of your project grade.
Cheating in any form will not be tolerated. Please re-read the Project
Policy handout for further details on honesty in doing projects for
this course.
Remember, the due date is firm. Submittals made after midnight of the
due date will not be accepted. Do not submit any files after that time.