HTML> CMSC 202 - Project 1, Spring 2004 UMBC CMSC 202
UMBC CMSC 202 CSEE | 202 | current 202

CMSC 202 Spring 2004
Project 1

Your First C++ Program

Assigned Wed Feb 11, 2004
Program Due Sunday Feb 22nd at 11:59pm
Updates Feb 19th
A clarification on the order of the command line arguments...
The wording under the "Project Description" section implies that the first command line argument is MaxWeight and the second is MaxVolune. The sample output shows that the first argument is the MaxVolume and the second is the MaxWeight....the sample output is correct.

Objectives


Project Description

In this project, you will write a program that simulates the loading of a cargo plane. You will input information (dimensions, weight, label) from the user about the containers to be loaded onto the cargo plane. Your project will then report statistics about the cargo and the cargo plane. The command line for the project will have two arguments -- the maximum weight the plane can carry (in pounds) and the maximum volume the plane can carry (in cubic inches).

Your project must contain the following function called from main, the code for which must be placed in Proj1Aux.cpp. Their prototypes and function header comments must be placed in Proj1Aux.h. Although the parameter types are given, the method of passing the parameters is up to you. Part of the project grade is choosing the appropriate method of passing parameters.

In the following prototypes, allCargo is a vector of Cargo structs containing the cargo loaded on the plane

  1. void LoadPlane( vector<Cargo> allCargo, double maxWeight, double usedWeight, int maxVolume, int usedVolume ) -- inputs and verifies all user data and loads the plane.

  2. void PrintWeight( double maxWeight, double usedWeight) -- Prints the plane's weight limit and the unused weight allowance
  3. void PrintVolume( int maxVolume, int usedVolume) -- Prints the plane's volume limit and the unused volume allowance
  4. void PrintHeaviest(vector<Cargo> allCargo) -- Prints the weight of the heaviest cargo container
  5. void PrintLargest(vector<Cargo> allCargo) -- Prints the volume of the largest cargo container
  6. void PrintCargo(vector<Cargo> allCargo) -- Prints a table of all cargo loaded on the plane. The data must be printed in table format with column headings. As we have not yet learned about formatted output, use tabs and/or spaces to align the data. See the sample output for a suggested output format.

Your project must use a structure to organize the data for a cargo container. Your structure must contain the following data members

Your project must contain the following functions, the code for which must be placed in Cargo.cpp. Their prototypes and function header comments will be placed in Cargo.h. Other Cargo-related functions are permitted as you deem necessary. Although the parameter types are given, the method of passing the parameters is up to you. Part of the project grade is choosing the appropriate method of passing parameters.

Only these functions may reference the data members of the Cargo structure.

  1. void InitCargo( Cargo cargo, int height, int width, int length, double weight, string label) -- initializes the data members of the cargo struct with the height, width, length, weight and label parameters.
    • cargo -- a Cargo struct to be initialized
    • height, width, length, weight, label -- the data values
  2. double CargoWeight( Cargo cargo ) -- returns the weight of the cargo container
  3. int CargoVolume( Cargo cargo ) -- returns the volume of the cargo container
  4. void PrintCargo( Cargo cargo ) -- prints the data of the cargo container in a format suitable for the table of cargo data

Project Requirements and Restrictions

  1. There must be exactly two command line arguments, both of which must be positive.
  2. All numeric user input must be positive.
  3. The cargo container label may be a multi-word label (eg. Tom's Books)
  4. The maximum weight of the plane may not be exceeded. Any cargo container that would cause the weight limit of the plane to be exceeded must not be loaded.
  5. The maximum volume of the plane may not be exceeded. Any cargo container that would cause the volume limit of the plane to be exceeded must not be loaded.
  6. Duplicate cargo containers are permitted.
  7. Your project must input the user data in the following order
    1. label
    2. weight
    3. height
    4. width
    5. length
  8. Your program must continue to prompt the user for cargo data until the user enters "quit" (without the quotes) as the label.
  9. All weight data must be output with 2 decimal points.

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 in tabular form. Note that the use of tabs will make the columns left-justified. linuxserver1[213] Proj1 3000000 50000 Input label: Bill's Bananas Input weight: 3000 Input height: 60 Input width: 60 Input length: 60 Input label: Tractor Input weight: 9000.50 Input height: 120 Input width: 60 Input length: 60 Input label: quit --- Cargo Statistics --- Maximum Cargo Weight: 50000.00 pounds Unused Cargo Weight : 37999.50 pounds Maximum Cargo Volume: 3000000 cubic inches Unused Cargo Volume : 2352000 cubic inches Heaviest container weighed 9000.50 pounds Largest container had volume of 432000 cubic inches --- Table of Cargo Containers --- Dimensions Volume Weight Label 60 x 60 x 60 216000 3000.00 Bill's Bananas 60 x 60 x 120 432000 9000.50 Tractor

Free Advice and Information

  1. Review the class notes on the different methods of passing parameters. Each is best for a different situation.
  2. Be sure your function header comments list the pre- and post-conditions and handle each pre-condition that is not met.
  3. Be sure to name your files Proj1.cpp, Cargo.cpp, Cargo.h, Proj1Aux.cpp and Proj1Aux.h, otherwise, you will have to modify the makefile we provide.
  4. Your program will be tested with a variety of good and bad inputs.
  5. Use incremental development.
  6. When using structs in C++, it is not necessary to use the keyword struct when declaring variables or parameters.
  7. There are 5 inputs for each cargo container; that's a lot of typing. When developing your program, manually input data for one or two containers. When you think your program works, create data files with many containers and use Unix redirection to input the data.
  8. Get your project working with good input first. Then go back and put in the error checking and error handling.
  9. When calling getline( ) after using " >> " to input numeric data, you may need to use the function cin.ignore( ) to remove the unused newline character. Ask about this in class, ask your TA, or ask the tutors in the HelpCenter.
  10. Use atoi( ) and atof( ) to change the command line arguments into integer and floating point values, respectively.
  11. This project is approximately 200 lines of code, not including file header comments or function header comments.... don't procrastinate.

Project Design Assignment

There is no project design assignment for this project.

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 Proj1.cpp, Proj1Aux.cpp and Cargo.cpp and create the executable named Proj1.

The make utility can also be used for compiling a single program without linking. For example, to compile Cargo.cpp, type make Cargo.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 Proj1Aux.cpp Proj1Aux.h Cargo.cpp Cargo.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 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: Thursday, 19-Feb-2004 08:42:45 EST