CMSC-341 Spring 2007
Project 1
Assigned |
Monday, 05 February 2007 |
Due |
Sunday, 18 February 2007, 11:42pm |
Background
Abstract Data Types (ADTs) 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,
compile code from multiple directories, and use a set of class
libraries. 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
Young children love to play with toys of all shapes and sizes.
Parents like to keep the toys organized.
To assist parents, you will implement a ToyBox class which can be
used to store toys and provide the parents with information about
the contents of the ToyBox. For simplicity, a ToyBox will hold
only one kind of toy at a time and hence can be implemented as
a C++ template.
In this project you will implement classes for two different toys
which will be stored in the toy box The toys for this class
are TinkerToys and Legos.
TinkerToys are small wooden objects of various shapes and colors which are connected
by dowels (short, round sticks) to create large toy structures.
Legos are small plastic rectangluar pieces of various lengths and
colors which can be interconnected to build large toy buildings, cars, etc.
Here are your tasks:
- Implement a C++ class to model a single TinkerToy.
The attributes of a TinkerToy are its shape (round, rectangle)
and its color (red, blue, green, orange).
The operations for a TinkerToy are construction, destruction,
comparison for equality, and printing (listing its color and shape).
- Implement a C++ class to model a single Lego.
The attributes of a Lego are its length (an integer) and color
(blue, red, white, black).
The operations of a Lego are construction, destruction,
comparison for equality, and printing (listing its color and length)
- Implement the ToyBox class as described
below.
- Use the main function provided in the file:
/afs/umbc.edu/users/f/r/frey/pub/CMSC341/Proj1/Proj1.cpp
Use Proj1.cpp without making any changes to it. Note: There is no
need to copy Proj1.cpp to your own directory. Your makefile must access the
file from the directory in which it is provided. Do not submit Proj1.cpp.
Grading scripts will delete Proj1.cpp if found in your submittal directory.
- Implement the functions which are required by Proj1.cpp
(GetCmdLine ( ), ProcessTinkerToyCommands( ) and
ProcessLegoCommands( )) in a separate
file named Proj1Aux.cpp. Their prototypes must be found in Proj1Aux.h.
The functionality of Process...Commands is described in
the command file section
-
Copy the makefile from
/afs/umbc.edu/users/f/r/frey/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-Sproing07-proj1_questions.txt. Copy the
file
/afs/umbc.edu/users/f/r/frey/pub/CMSC341/Proj1/341-Spring07-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's 10% of this project's
grade.
Definition of a ToyBox
A ToyBox is a fixed-size collection of possibly duplicate homogeneous objects.
The size of the ToyBox is the maximum number of items the ToyBox can hold.
For example, a ToyBox of TinkerToys of size 10 can contain up to 10 TinkerToys
of any shape and color.
There could be 10 red, round TinkerToys
in the ToyBox; or 5 blue, square TinkerToys; or 3 orange, round and 5 green, rectangluar
TinkerToys; or 10 TinkerToys that are each a different shape and color.
Because the ToyBox can contain any kind of object,
it must be implemented as a template. The type of object in the ToyBox
is the template parameter. The fixed size of the ToyBox is specified when
the ToyBox is constructed.
The operations allowed on a ToyBox are
- Construction of a ToyBox that specifies the fixed size.
- Destruction of a ToyBox
- Add an item to the ToyBox (e.g., add a round, red TinkerToy). Duplicate items are permitted in the ToyBox.
- Remove one item from the ToyBox (e.g. remove an orange, rectangluar TinkerToy).
If the ToyBox contains more than one of the specified item,
only one is removed.
- ItemCount( ) -- returns the total number of items in the ToyBox (e.g the
number of TinkerToys in the ToyBox).
- ItemCount( ItemType ) -- Returns the number of items of the specified type in the ToyBox
(e,g, the number of round, blue TinkerToys in the ToyBox).
- NumDistinctItems -- Returns the number of distinct items in the ToyBox
(e.g. Returns the number of different kinds of TinkerToys in the ToyBox).
- MaxItem -- Returns the specific item (e.g. blue, round TinkerToy)
which occurs the most times in the ToyBox.
If more than one item occurs most, any of the items may be returned.
- Print the contents of the ToyBox.
Note: Your implementation of the ToyBox class must use the print
idiom described in the Weiss text on page 33 (in the Employee class).
This means you must write both the public Print
method of the ToyBox class and a non-class, non-friend function.
The Command Line
Project 1 will be invoked with a command line that consists of three
arguments. The first argument specifies the type item to be stored
in the ToyBox and will be either "TinkerToy" (without the quotes),
or "Lego" (without the quotes).
The second argument is the size of the ToyBox (the maximum number of items it can hold).
The third argument will be the name of a file that
contains a set of operations that must be performed on a ToyBox of the
appropriate type. The format of this file is described in the command file section below.
Note that you must check command line arguments to ensure that they are
valid, e.g. that the command file can be opened, and print an appropriate
message if an error is found.
The Command File
Commands in the file specify operations to be performed on ToyBoxs. Each
line in the file represents one command. Blank lines may appear anywhere
in the file and should be ignored. Lines in which the first character
is '#' are comments and should also be ignored.
Otherwise, you can assume that any line containing a command is
syntactically well-formed. We make this assumption
so you don't have to spend lots of time making the command file parser
bullet proof.
Note that there are two routines for processing the command file
depending on the type of item specified on the command
line. These two routines should be very similar. It is probably a good
idea to write, test, and debug one of them completely before starting on
the other.
The command file format follows:
- ADD <item> -- Adds the item to the ToyBox. If the ToyBox is full,
an error message is printed.
- REMOVE <item> -- Removes the item from the ToyBox.
If the specified item is not in the ToyBox or the ToyBox is empty, an error
message is printed.
- OCCURS <item> -- Prints the number of times the specified item
is stored in the ToyBox
- COUNT -- Prints the total number of items in the ToyBox
- MAX -- Prints the item which occurs most frequently in the ToyBox
and the number of times it occurs. If the ToyBox is empty,
an error message is printed.
- DISTINCT -- Prints the number of distinct items in the ToyBox
- PRINT -- Prints the contents of the ToyBox
The following information is required for PRINT
- total number of items in the ToyBox
- number of distinct items in the ToyBox
- each item in the ToyBox and the number of times it occurs
In this description <item> refers to the attributes of a toy.
For the TinkerToy command file, <item> means the color
("red", "blue", "green", or "orange" without quotes) followed by the
shape ("round" or "rectangle" without the quotes).
For the Lego command file, <item> refers to the color
("red", "blue", "white", or "black" without quotes) followed by the
length (an integer).
Main Function Definition
The file containing the main function at the following location:
/afs/umbc.edu/users/f/r/frey/pub/CMSC341/Proj1/Proj1.cpp
You may copy this file when developing your project, but
you must use Proj1.cpp as is; no changes are permitted.
DO NOT submit Proj1.cpp. Instead, reference it with your
makefile. The grading scripts will delete Proj1.cpp if found in your
submittal directory.
Sample Output
Sample output is available for your study at
/afs/umbc.edu/users/f/r/frey/pub/CMSC341/Proj1/341-Spring07-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:
- ToyBox.h -- the definition and implementation of the ToyBox class template.
- Proj1Aux.h -- the prototypes for auxiliary functions you may
write such as GetCommandLine()
- Proj1Aux.cpp -- the implemenation of your auxiliary functions
- TinkeryToy.h -- the definition of the TinkerToy class
- TinkerToy.cpp -- the implemenation of the TinkerToy class
- Lego.h -- the definition of the Lego class
- Lego.cpp -- the implemenation of the Lego class
- your makefile
- 341-Spring07-proj1_questions.txt - containing
your answers to the questions.
Please do not submit any of the files provided to you such as Proj1.cpp.
The grading scripts will delete Proj1.cpp if found in your submittal directory.
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/f/r/frey/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 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). Any data files used by your project must be in your local directory.
Grading and Academic Integrity
Your project will 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-Spring07-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.