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

CMSC 202 Fall 2004
Project 1

Your First C++ Program

Assigned Mon Sept 13, 2004
Design Due Sunday Sept 19 at 11:59pm
Program Due Sunday Sept 26 at 11:59pm
Updates 20 Sept 2004
  • Although not part of the project description, the sample output shows the following features which should be considered project requirements
    1. All decimal values are output with 2 decimal places
    2. The commands found in the file and their arguments (if any) must be echoed as part of the output
  • In this sentence from the project description, "When no more toys of the requested size will fit in the box production of the current toy stops and a message is displayed indicating how many toys were not placed in the box." the word current is important. It is meant to say that some future MAKE command may create toys which will fit in the box. That's why we ask you to output a message rather than terminate your program.

Objectives


Project Description

In this project, you will write a program that simulates the manufacturing of spherical tinker toys and places them in a box for shipping to the assembly plant. Spherical tinker toys and boxes will be represented by structures. You will write functions to manipulate and access the toys and the boxes. You will also print information about the box and the details of the toys stored in the box. Your program will respond to commands found in the command file.

Boxes have finite size as determined by their dimensions. As toys are created, they are placed in the box. When no more toys of the requested size will fit in the box, production of the current toy stops and a message is displayed indicating how many toys were not placed in the box.

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.

Spherical (Round) Tinker Toys

Spherical (aka Round) tinker toys are modeled using a C++ struct named RoundToy. A round tinker toy has the following attributes.
  1. diameter - a floating point value
  2. color - restricted to red, white and blue for this project
  3. number of holes - an integer
The following functions are related to tinker toys. These functions are sufficient for the project. None of these functions read the command file. These are the only functions which may directly access the data members of the tinker toy structure.

NOTE: Although the parameter and return types have been specified, the method for passing the parameter and returning values (by value, by reference, by constant reference) has not. You must determine the appropriate method of passing parameters and return values.

  1. double RoundToyDiameter( RoundToy toy ) -- returns the diameter of the specified round tinker toy
  2. string RoundToyColor ( RoundToy toy ) -- returns a string which is the color of the specified round tinker toy
  3. int RoundToyHoles ( RoundToy toy ) -- returns the number of holes in the specified round tinker toy
  4. double RoundToyVolume( RoundToy toy ) -- returns the volume of the round (spherical) tinker toy
  5. void RoundToyInit( RoundToy toy, double diameter, string color, int nrHoles) -- Initializes the specified toy with the specified values.

Box

A box is modeled using a C++ struct named Box. A box has the obvious attributes of length, width and height which are integer values.

The following functions are related to a box. These functions are sufficient for the project. None of these functions read the command file. These are the only functions which may directly access the data members of the box structure.

NOTE: Although the parameter and return types have been specified, the method for passing the parameter and returning values (by value, by reference, by constant reference) has not. You must determine the appropriate method of passing parameters and return values.

  1. void BoxInit (Box box, int length, int width, int height) -- Initializes the specified box with the specified length, width and height.
  2. void BoxPrint ( ostream out, const Box& box) -- Prints the box details and summary. Box details include the dimensions, total volume, unused volume and the details of each toy stored in the box. The summary lists the number of round toys of each color in the box. See the sample output below.
  3. double BoxUnused( Box box) -- Returns the unused volume (available space) in the box.
  4. bool BoxStore( Box box, RoundToy toy) -- >Stores the specified round tinker toy in the specified box. Returns true if the toy fits in the box and false if there is insufficient space.

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 Proj1Cmds.dat found in Mr. Frey's public directory.

linuxserver1[234] Proj1 Proj1Cmds.dat CMD PRINT Box Dimensions : 5 x 4 x 8 Box Volume : 160 Unused Volume : 160.00 Box Contents Box is empty Box Summary: 0 total toys 0 Red 0 White 0 Blue CMD MAKE: 3, 1.50, Blue, 2 CMD MAKE: 1, 1.50, Red, 3 CMD MAKE: 500, 5.00, Red, 1 498 Red Round Toys with diameter 5.00 and 1 holes did not fit in the box CMD MAKE: 10, 1000.00, Blue, 5 10 Blue Round Toys with diameter 1000.00 and 5 holes did not fit in the box CMD PRINT Box Dimensions : 5 x 4 x 8 Box Volume : 160 Unused Volume : 22.03 Box Contents Color Diameter Volume Holes ----- -------- ------ ----- Blue 1.50 1.77 2 Blue 1.50 1.77 2 Blue 1.50 1.77 2 Red 1.50 1.77 3 Red 5.00 65.45 1 Red 5.00 65.45 1 Box Summary: 6 total toys 3 Red 0 White 3 Blue

Free Advice and Information

  1. Functions other than those listed above are permitted. If you create new functions, their prototypes must be found in Proj1Aux.h and they must be implemented in Proj1Aux.cpp; you must modify the makefile provided to account for these new files.
  2. Your program must provide adequate error checking.
  3. Review the class notes on the different methods of passing parameters. Each is best for a different situation.
  4. Be sure your function header comments list the pre- and post-conditions and handle each pre-condition that is not met.
  5. Be sure to name your files Proj1.cpp, Box.cpp, Box.h, RoundToy.cpp and RoundToy.h; otherwise, you will have to modify the makefile we provide.
  6. Your program will be tested with a variety of good and bad inputs.
  7. Use incremental development.
  8. When using structs in C++, it is not necessary to use the keyword struct when declaring variables or parameters.
  9. Get your project working with good input first. Then go back and put in the error checking and error handling.
  10. This project is approximately 200 lines of code, not including file header comments or function header comments.... don't procrastinate.
  11. Mr. Frey's public directory for this project is /afs/umbc.edu/users/d/e/dennis/pub/CMSC202/p1.

Project Design Assignment

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

Project Makefile

The "make" utility is used to help control projects with large numbers of files. It consists of targets, rules, and dependencies. You will be learning about make files in discussion. For this project, the makefile will be provided for you. You will be responsible for providing makefiles for all future projects. Copy the file

/afs/umbc.edu/users/d/e/dennis/pub/CMSC202/p1/Makefile to your directory.

When you want to compile and link your program, simply type the command make or make Proj1 at the Linux prompt. This will compile all necessary .cpp files and create the executable named Proj1.

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, Proj1, 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, pay attention to the list below. Graders will check all applicable items in the coding standards.
  1. Your file header comments
  2. Your function header comments (particularly pre- and post-conditions)
  3. Function and variable names
  4. In-line comments
  5. Code readability
  6. Limiting variable scope

Project Submission

Assuming you've used the recommended file names, then to submit your project, type the command submit cs202 Proj1 Proj1.cpp Box.h Box.cpp RoundToy.h RoundToy.cpp 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 Proj1

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, 20-Sep-2004 15:56:35 EDT