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

CMSC 202 Fall 2004
Project 2

Your First C++ Program with Classes

Assigned Mon Sept 27, 2004
Design Due Sunday Oct 3 at 11:59pm
Program Due Wed Oct 13 at 11:59pm
Updates 02 Oct The sample output originally provided was NOT produced from Proj2Cmds.dat found in Mr. Frey's public directory. The sample output has been replaced with output the WAS produced from Proj2Cmds.dat

30 Sept The description of the Truck class now contains a necessary service for loading Boxes

28 Sept The description of RoundToy constructor indicates that it uses the specified "height, length and width". Clearly these attributes should be diameter, color and number of holes. The project description has been modifed accordingly.


Objectives


Project Description

This project continues our simulation of tinker toy manufacturing and assembling. In this project, you will modify and extend project 1. Boxes and RoundToys which were modeled using structs in project 1 will now be modeled using C++ classes. You will also design and implement a new class which models a Truck that delivers the Boxes of RoundToys to the assembly plant. We've attempted to highlight the functional differences between project 1 and project 2 using blue text. It's possible we missed some, but we're confident you'll point them out to us :-)

In this project you will be filling boxes (plural) with round tinker toys and shipping them to the assembly plant in a truck. As in project 1, we will make round tinker toys with various diameters and colors. We will be filling multiple boxes with varying dimensions, placing them in the truck and driving the truck to the assembly plant. Our truck is especially made for UMBC -- it has unlimited capacity and never gets full.

There two significant functional differences between the projects with respect to manufacturing and packing toys in a box.

  1. Instead of just packing one box, you will be packing multiple boxes. These boxes may have varying dimensions. Boxes will be delivered to you via a new command (BOXES) in the command file.
  2. When making toys, one of three things may happen
    1. If a toy does not fit in the box currently being packed, the box is sealed and placed on the Truck for delivery. The toy is then placed in the next available box. Yes, it's possible that we will be shipping empty boxes.
    2. If you run out of boxes, two messages are displayed. One message tells how many toys were packed and the second indicates how many toys could not be delivered. Both messages give the toy details (color, diameter, number of holes).
    3. If all requested toys have been manufactured, the current box being packed is sealed and placed on the truck. A messages is displayed listing how many boxes (regardless of dimensions) could not be used and had to be recycled. These boxes are no longer available for future deliveries.

As in project 1, commands will be read and processed from a command file. The file will contain new commands and modified commands that you processed in project 1. As in project 1, Your program will open the command file and loop until all commands found in the file have been executed. All valid commands in the file are properly formatted, but you may encounter invalid commands. See the Command File section below.

As you will see, many of the operations listed below appear to be quite similar to functions that were specified in project 1. This is not a coincidence. One of our goals is for you to see the value of writing reusable and/or easily modifiable code. This project gives you a chance to reuse and/or modify code from project 1.

The Classes

In this project, you will be implementing three C++ classes -- RoundToy, Box and Truck. The RoundToy and Box are similar to those of project 1. The Truck is new.

The operations of each class are described below. Each operations is implemented as a single public member function of the class. It's up to you to provide complete prototypes (name, parameters (and how they are passed), return types and "constness") for each public member function. No other public member functions are allowed, but you may implement whatever private member functions you deem necessary. None of the operations listed below read the command file. All data members of all classes must be private

Spherical (Round) Tinker Toys

Spherical (aka Round) tinker toys are modeled using a C++ class named RoundToy. A round tinker toy has the following attributes.
  1. diameter - a floating point value
  2. color - restricted to red, white, blue orange, and green for this project
  3. number of holes - an integer
The RoundToy class supports the following operations
  1. The RoundToy constructor that initializes the specified toy with the specified diameter, colors and number of holes
  2. An accessor that returns the diameter of the round tinker toy
  3. An accessor that returns a string which is the color of the round tinker toy
  4. An accessor that returns the number of holes in the round tinker toy
  5. A service that returns the volume of the round (spherical) tinker toy

Box

A box is modeled using a C++ class named Box. A box has the obvious attributes of length, width and height which are integer values. The Box class supports the following public operations
  1. The Box constructor that initializes the box with the specified length, width and height.
  2. A service that prints the box summary to the specified stream. The summary lists the number of round toys of each color in the box.
  3. An accessor that returns the unused volume (available space) in the box.
  4. A service that stores the specified round tinker toy in the box.

Truck

The Truck is modeled using a C++ class named Truck. Our specially made truck has infinite capacity and never gets full. You should decide what attributes are appropriate for the Truck based on the project description. The Truck supports the following operations.
  1. The Truck constructor that initializes the truck's attributes.
  2. A service that delivers the Truck's contents to an assembly plant.
  3. A service that loads a box onto the truck.
  4. A service that prints the Truck's current load and delivery log. This output contains the following information. See the sample output below.
    1. Current Load - the number of boxes and summary of the contents of each box currently on the truck waiting for delivery.
    2. Delivery Log - How many trips were made to the assembly plant, how many boxes were delivered and the total miles driven to and from the assembly plant; a summary of the contents of each box previously delivered.

The Command File

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.

Sample Output

This sample output is provided to show you a reasonable output format which satisfies the project requirements. It is not necessary that you follow this format exactly, but whatever format you choose must provide all required information. Toy details must be in tabular format. Note that the use of tabs will make the columns left-justified. This output was created from the command file Proj2Cmds.dat found in Mr. Frey's public directory. CMD PRINT Current Load: 0 boxes Delivery Log ------------ 0 deliveries made to Bob's TinkerToy Plant 0 total miles driven 0 boxes delivered CMD BOXES: 5, 15, 2, 20 CMD TOYS: 75, 3.50, Orange, 2 All toys made and shipped 2 boxes recylced CMD PRINT Current Load: 3 boxes Box # 1 -------- 0 Red 0 White 0 Blue 0 Green 26 Orange Box # 2 -------- 0 Red 0 White 0 Blue 0 Green 26 Orange Box # 3 -------- 0 Red 0 White 0 Blue 0 Green 23 Orange Delivery Log ------------ 0 deliveries made to Bob's TinkerToy Plant 0 total miles driven 0 boxes delivered CMD BOXES: 13, 12, 30, 4 CMD TOYS: 50, 4.50, Red, 3 All toys made and shipped 11 boxes recylced CMD PRINT Current Load: 5 boxes Box # 1 -------- 0 Red 0 White 0 Blue 0 Green 26 Orange Box # 2 -------- 0 Red 0 White 0 Blue 0 Green 26 Orange Box # 3 -------- 0 Red 0 White 0 Blue 0 Green 23 Orange Box # 4 -------- 30 Red 0 White 0 Blue 0 Green 0 Orange Box # 5 -------- 20 Red 0 White 0 Blue 0 Green 0 Orange Delivery Log ------------ 0 deliveries made to Bob's TinkerToy Plant 0 total miles driven 0 boxes delivered CMD TOYS: 10, 2.50, Green, 2 0 Green toys with diameter 2.50 and 2 hole(s) packed 10 Green toys with diameter 2.50 and 2 hole(s) not packed CMD DELIVER CMD PRINT Current Load: 0 boxes Delivery Log ------------ 1 deliveries made to Bob's TinkerToy Plant 88 total miles driven 5 boxes delivered Box # 1 -------- 0 Red 0 White 0 Blue 0 Green 26 Orange Box # 2 -------- 0 Red 0 White 0 Blue 0 Green 26 Orange Box # 3 -------- 0 Red 0 White 0 Blue 0 Green 23 Orange Box # 4 -------- 30 Red 0 White 0 Blue 0 Green 0 Orange Box # 5 -------- 20 Red 0 White 0 Blue 0 Green 0 Orange CMD BOXES: 10, 10, 20, 30 CMD TOYS: 10, 12.00, Orange, 5 All toys made and shipped 8 boxes recylced CMD PRINT Current Load: 2 boxes Box # 1 -------- 0 Red 0 White 0 Blue 0 Green 6 Orange Box # 2 -------- 0 Red 0 White 0 Blue 0 Green 4 Orange Delivery Log ------------ 1 deliveries made to Bob's TinkerToy Plant 88 total miles driven 5 boxes delivered Box # 1 -------- 0 Red 0 White 0 Blue 0 Green 26 Orange Box # 2 -------- 0 Red 0 White 0 Blue 0 Green 26 Orange Box # 3 -------- 0 Red 0 White 0 Blue 0 Green 23 Orange Box # 4 -------- 30 Red 0 White 0 Blue 0 Green 0 Orange Box # 5 -------- 20 Red 0 White 0 Blue 0 Green 0 Orange CMD BOXES: 4, 10, 10, 10 CMD TOYS: 5, 2.80, White, 2 All toys made and shipped 3 boxes recylced CMD PRINT Current Load: 3 boxes Box # 1 -------- 0 Red 0 White 0 Blue 0 Green 6 Orange Box # 2 -------- 0 Red 0 White 0 Blue 0 Green 4 Orange Box # 3 -------- 0 Red 5 White 0 Blue 0 Green 0 Orange Delivery Log ------------ 1 deliveries made to Bob's TinkerToy Plant 88 total miles driven 5 boxes delivered Box # 1 -------- 0 Red 0 White 0 Blue 0 Green 26 Orange Box # 2 -------- 0 Red 0 White 0 Blue 0 Green 26 Orange Box # 3 -------- 0 Red 0 White 0 Blue 0 Green 23 Orange Box # 4 -------- 30 Red 0 White 0 Blue 0 Green 0 Orange Box # 5 -------- 20 Red 0 White 0 Blue 0 Green 0 Orange CMD DELIVER CMD PRINT Current Load: 0 boxes Delivery Log ------------ 2 deliveries made to Bob's TinkerToy Plant 176 total miles driven 8 boxes delivered Box # 1 -------- 0 Red 0 White 0 Blue 0 Green 26 Orange Box # 2 -------- 0 Red 0 White 0 Blue 0 Green 26 Orange Box # 3 -------- 0 Red 0 White 0 Blue 0 Green 23 Orange Box # 4 -------- 30 Red 0 White 0 Blue 0 Green 0 Orange Box # 5 -------- 20 Red 0 White 0 Blue 0 Green 0 Orange Box # 6 -------- 0 Red 0 White 0 Blue 0 Green 6 Orange Box # 7 -------- 0 Red 0 White 0 Blue 0 Green 4 Orange Box # 8 -------- 0 Red 5 White 0 Blue 0 Green 0 Orange

10 Points Extra Credit

Implement the project with the following alternative description.

When a toy does not fit in the box, the box is sealed and placed on the Truck for delivery. The toy is then placed in the next available box. If there are no more available boxes, the Truck is sent to the assembly plant to deliver the boxes that have been filled. (Yes, it's conceivable that we'll be shipping empty boxes.) Once the truck arrives at the assembly plant the boxes are unloaded and the truck immediately returns. When more boxes are delivered (BOXES command), packing toys in the boxes will automatically begin again.

Similarly, when all requested toys have been produced, the box being packed is sealed and placed on the Truck. The Truck is sent to the assembly plant to deliver the boxes that have been filled. Once the truck arrives at the assembly plant the boxes are unloaded and the truck immediately returns. Once an order is given to make more toys (TOYS command), packing toys in boxes will automatically begin again.

Summary -- if you ever run out of boxes or toys, seal the current box being packed and deliver the boxes to the assembly plant. Once more boxes or toys are available, continue packing. Your program should ignore the DELIVER command from the file (do not print an error).

When your program ends, display the number of unused boxes and unpacked toys (one or both of these should be zero), along with the box or toy details.

Be sure to submit a text file named ExtraCredit.txt telling the grader that you have implemented the extra credit version of the project. Extra Credit projects will have different "correctness" criteria than regular projects.


Free Advice and Information

  1. Functions called from main that are not part of any class are permitted. If you create new functions, their prototypes must be found in Proj2Aux.h and they must be implemented in Proj2Aux.cpp; you must modify the makefile provided to account for these new files.
  2. Your program must provide adequate error checking similar to project 1.
  3. Think carefully about the proper use of const for parameters and member functions. Doing const correctly from the beginning can save lots of effort and frustration later.
  4. Review the class notes on the different methods of passing parameters. Each is best for a different situation.
  5. Be sure your function header comments list the pre- and post-conditions and handle each pre-condition that is not met.
  6. Your program will be tested with a variety of conditions.
  7. Use incremental development.
    One possible sequence of activities
    1. Change Box and RoundToy from structs to classes first. You can then modify a copy of Proj1.cpp accordingly and test it with Proj1Cmds.dat.
    2. Then add the new colors for RoundToy
    3. Then make the command file related changes for Toys and Boxes
    4. Then implement the Truck
    5. Then add the commands for the Truck
  8. Don't attempt the Extra Credit until you have all the required aspects of the project complete. Submit a completed project 2 without extra credit before you begin to modify your code.
  9. Get your project working with good input first. Then go back and put in the error checking and error handling.
  10. Expect to use/modify code from this project in project 3. Design and code accordingly.
  11. This project is approximately 400 lines of code, not including file header comments or function header comments.... don't procrastinate.
  12. Mr. Frey's public directory for this project is /afs/umbc.edu/users/d/e/dennis/pub/CMSC202/p2.

Project Design Assignment

Your project design document for project 2 must be named p2design.txt. Be sure to read the
design specification carefully. Submit your design in the usual way: submit cs202 Proj2 p2design.txt

Project Makefile

You must provide the makefile for this project. Use the makefile provided to you for project 1 and modify it appropriately. If you don't change the names of the files from project 1, the changes will be minimal.

The graders will be typing the command make Proj2 when they grade your project. This command must cause all .cpp files to be compiled and the executable named Proj2 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, Proj2, and backup files created by the editor. More information about these commands can be found at the bottom of the makefile.


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.

85% - Correctness

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.
  1. Your class implementation and class usage
  2. Proper use of const
  3. Your function header comments (particularly pre- and post-conditions)
  4. In-line comments
  5. Code readability

Project Submission

Assuming you've used the recommended file names, then to submit your project, type the command submit cs202 Proj2 Proj2.cpp Box.h Box.cpp RoundToy.h RoundToy.cpp Truck.cpp Truck.h Makefile The order in which the files are listed doesn't matter. However, you must make sure that all files necessary to compile your project (using the makefile) are listed. You need not submit all files at the same time. You may resubmit your files as often as you like, but only the last submittal will be graded and will be used to determine if your project is late. For more information, see the projects page on the course website.

You can check to see what files you have submitted by typing

submitls cs202 Proj2

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.


Last Modified: Sunday, 03-Oct-2004 22:28:17 EDT