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

CMSC 202 Fall 2004
Project 3

Operator Overloading

Assigned Mon Oct 25th, 2004
Design Due Sunday Oct 31 at 11:59pm
Program Due Sunday Nov 7th at 11:59pm
Updates 28 October 2004
The requirement that the Truck use operator+= to add a DeliveryRcd is superfluous and has been removed. There's no need for any such Truck operation.

Objectives


Project Description

This project continues our simulation of tinker toy manufacturing and assembling. In this project, you will modify and extend project 2. The Box, RoundToy and Truck classes continue to be used. Two new classes - DeliveryLog and DeliveryRecord are introduced. We've attempted to highlight the functional differences between project 2 and project 3 using blue text and this image It's possible we missed some, but we're confident you'll point them out to us :-)

The handling of the BOXES and TOYS command in project 3 is the same as the required implementation in project 2. Those who did the extra credit version of project 2 are required to modify their code to revert to the required method which is repeated for you here.

In this project you will be filling boxes (plural) with round tinker toys and shipping them to the assembly plant in a truck. 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.

  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 message is displayed listing how many boxes (regardless of dimensions) could not be used and had to be destroyed. These boxes are no longer available for future deliveries.
    As noted in project 2, these rules mean that only one color of RoundToy will be packed into a Box.

As in project 1 and 2, commands will be read and processed from a command file. The file will contain new commands and modified commands that you processed in project 2. As in project 2, 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 2. 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 2.

The Classes

In this project, you will be implementing five C++ classes -- RoundToy, Box and Truck, DeliveryLog, DeliveryRecord. The RoundToy, Box and Truck are similar to those of project 2. The DeliveryLog and DeliveryRecord are new. All public methods for the Box, RoundToy and Truck classes which you've written for project 2 may be kept and reused.

The operations of each class are described below. Each operation 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 - a string
  3. number of holes - an integer
The valid colors for a RoundToy are found in the command file. The number and names of valid colors may be different for each command file, but the color names are guaranteed NOT to contain spaces.
The RoundToy class supports the following operations
  1. The RoundToy default constructor which initializes a toy as you see fit.
  2. The RoundToy constructor that initializes the specified toy with the specified diameter, colors and number of holes
  3. An accessor that returns the diameter of the round tinker toy
  4. An accessor that returns a string which is the color of the round tinker toy
  5. An accessor that returns the number of holes in the round tinker toy
  6. 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. This service must be provided by overloading the output operator for the Box. The output operator may not be a friend function. (Hint: existing functions may be reused) The summary lists the number of round toys in the box and their color (recall that all toys in the box will be the same color).
  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. This service must be provided by overloading the += operator for 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. Note that for this project, the Truck will be delivering boxes to multiple assembly plants. The Truck supports the following operations.
  1. The truck default constructor
  2. The Truck constructor that initializes the truck's attributes.
  3. A service that delivers the Truck's contents to an assembly plant.
  4. A service that loads a box onto the truck. This service must be provided by overloading the += operator for the Truck
  5. A service that prints the Truck's current load and delivery log. This service must be provided by overloading the output operator for the truck The output operator may not be a friend function. 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 - A list of all deliveries, including the assembly plant name, the number of miles and the number of boxes delivered.

DeliveryRecord

This class represents the details of a single delivery of boxes. The attributes of this class include the name of the assembly plant to which the delivery was made, total miles traveled to and from the assembly plant and the number of boxes delivered.

As an academic exercise, all data members of this class must be dynamically allocated. This will not be a requirement for project 4. The DeliveryRecord supports the following operations

  1. A default constructor
  2. A constructor that initializes the DeliveryRecord's attributes
  3. A service to print a DeliveryRecord in a format similar to that in the sample output. This service must be implemented by overloading the DeliveryRecord's output operator as a friend function
  4. Since the data members of this class are dynamically allocated, the following methods are also required
    1. copy constructor
    2. assignment operator
    3. destructor
    Since these methods might not be used in your program, a special test program will be written to verify the correctness of these methods as part of the project grading.

DeliveryLog

A DeliveryLog is a set of DeliveryRecords kept in the order in which deliveries are made. Each Truck keeps a DeliveryLog so it can report its delivery activity details. The DeliveryLog supports the following operations
  1. A default constructor
  2. A service to add a new DeliverRecord to the DeliveryLog.
  3. A service to print the contents of the DeliveryLog in a format similar to that found in the sample output. This service must be implemented by overloading the DeliveryLog's output operator as a friend function.

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.

Other Project Requirements

  1. As shown in the sample output below, your program must print a summary that include the total number of toys produced and the number of toys of each color produced. This summary must be in tabular format (right-justified columns) with 5 toy colors per line.
  2. As usual, your output need not look exactly like the sample output below. However, the output for each box (box number, number of toys and toy color) must appear in right-justified columns as shown in the sample output.
  3. So that we can create a makefile for our special program to test your DeliveryRecord class, you must use the filenames DeliveryRecord.h and DeliveryRecord.cpp for this class.

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 Proj3Cmds.dat found in Mr. Frey's public directory. CMD PRINT Current Load: 0 boxes Delivery Log ------------ No Deliveries CMD BOXES: 5, 15, 2, 20 CMD TOYS: 75, 3.50, DkBlue, 2 All toys made and shipped 2 boxes destroyed CMD PRINT Current Load: 3 boxes Box # 1 26 DkBlue Box # 2 26 DkBlue Box # 3 23 DkBlue Delivery Log ------------ No Deliveries CMD BOXES: 13, 12, 30, 4 CMD TOYS: 50, 4.50, Purple, 3 All toys made and shipped 11 boxes destroyed CMD PRINT Current Load: 5 boxes Box # 1 26 DkBlue Box # 2 26 DkBlue Box # 3 23 DkBlue Box # 4 30 Purple Box # 5 20 Purple Delivery Log ------------ No Deliveries 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 BOXES: 2, 20, 20, 20 CMD TOYS: 100, 2.20, Lime, 4 All toys made and shipped 1 boxes destroyed CMD PRINT Current Load: 6 boxes Box # 1 26 DkBlue Box # 2 26 DkBlue Box # 3 23 DkBlue Box # 4 30 Purple Box # 5 20 Purple Box # 6 100 Lime Delivery Log ------------ No Deliveries CMD DELIVER 39 My House CMD PRINT Current Load: 0 boxes Delivery Log ------------ Delivered to My House 78 miles 6 boxes CMD BOXES: 10, 10, 20, 30 CMD TOYS: 10, 12.00, Tan, 5 All toys made and shipped 8 boxes destroyed CMD PRINT Current Load: 2 boxes Box # 1 6 Tan Box # 2 4 Tan Delivery Log ------------ Delivered to My House 78 miles 6 boxes CMD BOXES: 10, 15, 6, 7 CMD BOXES: 9, 10, 10, 10 CMD TOYS: 2000, 2.80, Yellow, 2 No more boxes 1323 Yellow toys with diameter 2.80 and 2 hole(s) packed 677 Yellow toys with diameter 2.80 and 2 hole(s) not packed CMD BOXES: 6, 9, 9, 9 CMD TOYS: 100, 4.50, Gray, 3 No more boxes 90 Gray toys with diameter 4.50 and 3 hole(s) packed 10 Gray toys with diameter 4.50 and 3 hole(s) not packed CMD PRINT Current Load: 27 boxes Box # 1 6 Tan Box # 2 4 Tan Box # 3 54 Yellow Box # 4 54 Yellow Box # 5 54 Yellow Box # 6 54 Yellow Box # 7 54 Yellow Box # 8 54 Yellow Box # 9 54 Yellow Box # 10 54 Yellow Box # 11 54 Yellow Box # 12 54 Yellow Box # 13 87 Yellow Box # 14 87 Yellow Box # 15 87 Yellow Box # 16 87 Yellow Box # 17 87 Yellow Box # 18 87 Yellow Box # 19 87 Yellow Box # 20 87 Yellow Box # 21 87 Yellow Box # 22 15 Gray Box # 23 15 Gray Box # 24 15 Gray Box # 25 15 Gray Box # 26 15 Gray Box # 27 15 Gray Delivery Log ------------ Delivered to My House 78 miles 6 boxes CMD DELIVER 44 Bob's Assembly Plant CMD PRINT Current Load: 0 boxes Delivery Log ------------ Delivered to My House 78 miles 6 boxes Delivered to Bob's Assembly Plant 88 miles 27 boxes Toy production summary: 1648 toys 0 Red 0 White 0 Blue 0 Green 0 Orange 0 Pink 0 LtBlue 75 DkBlue 0 LtGreen 0 DkGreen 1323 Yellow 0 Black 90 Gray 0 Brown 10 Tan 50 Purple 0 DkRed 0 Beige 100 Lime 0 Gold

Free Advice and Information

  1. THINK about this project before coding. Be sure you understand the relationships among the objects.
  2. Complete the project without using dynamic memory allocation for the DeliveryRecord class. Then after submitting this working version, go back and make all the DeliveryRecord data members be dynamically allocated and rewrite the affected member functions.
  3. There's lots of opportunity here for the method of one class to use a method of another class. Think before you code.
  4. Functions called from main that are not part of any class are permitted. If you create new functions, their prototypes must be found in Proj3Aux.h and they must be implemented in Proj3Aux.cpp; you must modify the makefile provided to account for these new files.
  5. Your program must provide adequate error checking similar to project 2.
  6. Use incremental development.
  7. Expect to use/modify code from this project in project 4. Design and code accordingly.
  8. This project is approximately xxx lines of code, not including file header comments or function header comments.... don't procrastinate.
  9. Mr. Frey's public directory for this project is /afs/umbc.edu/users/d/e/dennis/pub/CMSC202/p3.

Project Design Assignment

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

Project Makefile

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

The graders will be typing the command make Proj3 when they grade your project. This command must cause all .cpp files to be compiled and the executable named Proj3 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, Proj3, 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 Proj3 Proj3.cpp DeliveryRecord.h DeliveryRecord.cpp DeliverLog.cpp DeliveryLog.h 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 Proj3

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: Monday, 01-Nov-2004 12:08:56 EST