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:

  1. 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).
  2. 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)
  3. Implement the ToyBox class as described below.
  4. Use the main function provided in the file:
  5. /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.
  6. 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
  7. 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.
  8. 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


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:

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: 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.