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

CMSC 202 Spring 2004
Project 3

Modified Air Cargo Plane

Assigned Monday March 29, 2004
Design Due Sunday April 4, 2004 at 11:59pm
Program Due Sunday April 11, 2004 at 11:59pm
Updates 06 April
The formatting requirements stated that "all columns for Cargo must be aligned and right justified.", but the sample output showed the label left-justified. The sample output is correct. The statement in the requirements was intended to refer to only the numeric columns and has been changed.

30 March
New sample output has been provided. This output was produced using the test files now found in Mr. Frey's public directory.
/afs/umbc.edu/users/d/e/dennis/pub/CMSC202/p3


Objectives

To gain experience with

Project Description

In real life, software is rarely static. Once written, it often requires changes because of changing customer requirements, new customer requirements, bugs must be fixed or just because it can be rewritten in a better way.

In project 3, you will modify your project 2 program that simulates the loading, unloading and flying of a cargo plane. You should be able to use much of your code from project 2 to complete this project. Additional code is also required. You will change the way some functionality was implemented in project 2 and you will add new functionality.

Project 3 will be executed from the command line with 7 parameters in the order listed below. The first 5 parameters are the same as project 2.

  1. Maximum volume of cargo the plane can hold in cubic inches
  2. Maximum weight the cargo plane can hold in pounds
  3. Fuel capacity of the plane in gallons
  4. Fuel consumption of the plane in gallons per hour
  5. The city in which the plane begins its route (no spaces)
  6. The name of a file that contains commands
  7. The name of a file that contains flight information

Classes

You will modify both the Cargo and CargoPlane classes from project 2 in the manner specified below. Modifications and additions to the classes are highlighted in green and marked with . Two new classes will also be required.

The Cargo Class

This class models a single cargo container. As in project 2, Cargo containers are uniquely identified by their label. You may assume that no two containers have the same label.

All private data members of the Cargo class must be dynamically allocated. The Cargo class interface is defined by these public functions:

operator<< must be overloaded as a friend of the Cargo class. This operator replaces Cargo's Print( ) function from project 2. operator<< prints all attributes of the cargo container in a format consistent with the
sample output.

The CargoPlane class

The CargoPlane class models a single plane which contains zero or more Cargo containers and many additional attributes.

All private data members of the CargoPlane class must be dynamically allocated The CargoPlane class interface is defined by these public functions:

operator<< must be overloaded as a friend of CargoPlane. This operator replaces CargoPlane's Print() function from project 2. In addition to all data output in project 2, the CargoPlane's flight table information is also printed.
  1. Current City - the city in which the plane is currently located
  2. Miles Flown - the total number of miles flown
  3. Hours Flown - the total number of hours flown
  4. Fuel Rate - the fuel consumption rate in gallons per hour
  5. Fuel Capacity - the plane's fuel capacity in gallons
  6. Fuel Consumed - the total gallons of fuel used
  7. Fuel Remaining - the total number of unused gallons of fuel
  8. Weight Limit - the maximum weight the plane can hold
  9. Weight Loaded - the total number of pounds of cargo loaded on the plane
  10. Weight Remaining - the total number of pounds that can still be loaded on the plane
  11. Volume Limit - the maximum volume of cargo the plane can hold
  12. Volume Loaded - the total space occupied by cargo loaded on the plane
  13. Volume Remaining - the remaining space that can still be loaded on the plane
  14. Current Cargo - a table showing the details of the cargo currently on the plane. If there is no cargo on the plane, an appropriate message should be displayed.
  15. Flight Information - a table showing the miles and flight times between all cities serviced by this CargoPlane

The FlightTable class

This class contains information about all possible flights that the CargoPlane may make. Each flight consists of four data elements -- city of origin, destination city, number of miles, and flight time in hours. Note that due to effect of the jet stream, the time traveling from city A to city B may be different than the time traveling from city B to city A.

The CargoPlane has a private data member which is a pointer to a FlightTable object which is constructed and exists in main( ) (or a function called from main).

The FlightTable class supports the following public interface

To output a FlightTable, operator<< must be overloaded as a friend function for the FlightTable class.

To encapsulate the information for a single flight, the FlightTable defines a private "embedded" class named Flight. The Flight class can only be used within the FlightTable class. Since this class is known only to the FlightTable class, its design and implementation are up to you, but you must follow good OOP/OOD principles. In particular, all data members of the Flight class must be private. The code for the Flight class may coexist with the code for the FlightTable class.

The Command File

For this project, commands will be read from a file instead of being input by the user. The name of the command file is the 6th command line parameter. The commands are exactly the same as in project 2 -- FLY, PRINT, LOAD, UNLOAD and QUIT.

Except for the FLY command, all inputs for all commands are the same as in project 2, in the same order. Because of the use of the FlightTable, the FLY command now has just one parameter, the destination city.

Each command and each input will be on a separate line in the file.

The Flight Data File

For this project, flight data will be read from a file and stored in a FlightTable object. The name of the flight data file is the 7th command line parameter. The CargoPlane points to the FlightTable object and looks up mileage and flight time each time it flies to a new city.

City names in the file have no spaces, so it is possible to use operator>> to read this file (DO NOT use getline()). Each line of the file contains the data for one flight -- origin, destination, miles, hours (in that order).

Summary of Miscellaneous Project Requirements, Restrictions and Assumptions

  1. You may assume that both the command file and flight data files exist.
  2. You may assume that all input data is valid. You may remove project 2 code that is now unnecessary, or leave it in. In particular this means
    1. The format of the command file and flight files will be valid
    2. The correct number of command line arguments will be present
    3. The values of all data will be valid (eg positive)
    4. You will only be asked to FLY to a city for which flight information exists
    5. The flight data file will contain no duplicate information
    6. The command file will contain no invalid commands
  3. All commands must be displayed as they are being executed. Some (or all) of the command parameters must also be displayed. See the sample output.
  4. No public methods other than those specified are permitted.
  5. You may reorder the parameters in any function, but no new parameters may be added, and no parameter may be removed.
  6. The return types of the functions may not be changed (other than using const or reference).
  7. The cargo container label may be a multi-word label (eg. Tom's Books).
  8. Cargo container labels uniquely identify a container. You may assume that no duplicate containers are loaded on the plane.
  9. 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.
  10. 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.
  11. Your project must input the cargo data in the following order (same as proj 2). See the command file description above.
    1. label
    2. weight
    3. height
    4. width
    5. length
  12. All weight data must be output with 2 decimal points.
  13. If your plane crashes, an appropriate message should be displayed, the current plane information displayed (as with the PRINT command) and your program terminated.
  14. If a Cargo container cannot be loaded, an appropriate message indicating why it cannot be loaded should be displayed.
  15. You may find that you can write your program without using the default constructors for Cargo and CargoPlane, but they must still be implemented, as this is a good programming practice.
  16. You may assume that the destination city name (for the FLY command) are one word (i.e. no spaces).
  17. You may assume that any command that is entered will not contain spaces
  18. Your executable MUST be named Proj3 as that name is used in the testing/grading scripts.
  19. We will be using our own "driver" program to test some of your code. You MUST follow the naming conventions found in the Project Submission section below.

Sample Output

This sample output is provided to show you a reasonable output format which satisfies the project requirements. Except for required formatting, and the addition of the Flight Table, this output is the same as project 2.

It is not necessary that you follow this format exactly, but whatever format you choose must provide all required information, including tabular form for the cargo and flight data.

Required formatting

  1. All numeric columns for Cargo must be aligned and right justified.
    You may assume the Cargo dimensions are no more than 3 digits each
    You may assume the volume is no more than 12 digits
    You may assume the weight is no more than 12 digits (including 2 decimals)
  2. All columns for the Flight information must be aligned and right justified
    You may assume that the city names are no more than 20 characters
    You may assume the hours and miles are no more than 5 digits
  3. If the plane's weight, volume and fuel data form columns (as in the sample output below) they must be aligned and right justified.
    You may assume that the weight, volume and fuel are no more than 12 digits
linux3[80]% Proj3 50000 60000 70000 700 home p3cmds.dat p3flights.dat CMD: FLY to Chicago CMD: LOAD Chicago Bull's CMD: LOAD Lots of Meat CMD: PRINT Current City: Chicago Mile Flown: 400 Hours Flown: 3 Fuel Rate: 700 gallons per hour Fuel Capacity: 70000 Consumed: 2100 Remaining: 67900 Volume Limit: 50000 Loaded: 17000 Remaining: 33000 Weight Limit: 60000.00 Loaded: 4200.00 Remaining: 55800.00 Current Cargo 20 x 30 x 15 1200.00 9000 Chicago Bull's 20 x 20 x 20 3000.00 8000 Lots of Meat Flight Table ------Origin------ ------Destination------ --Miles-- --Hours-- home Chicago 400 3 Chicago LA 600 10 LA Chicago 600 8 LA Vegas 200 1 LA Dallas 1000 12 Dallas Cincinnati 500 6 Dallas home 500 40 home Crash 40000 3000 Philly NY 150 2 NY LA 3000 8 CMD: FLY to LA CMD: PRINT Current City: LA Mile Flown: 1000 Hours Flown: 13 Fuel Rate: 700 gallons per hour Fuel Capacity: 70000 Consumed: 9100 Remaining: 60900 Volume Limit: 50000 Loaded: 17000 Remaining: 33000 Weight Limit: 60000.00 Loaded: 4200.00 Remaining: 55800.00 Current Cargo 20 x 30 x 15 1200.00 9000 Chicago Bull's 20 x 20 x 20 3000.00 8000 Lots of Meat Flight Table ------Origin------ ------Destination------ --Miles-- --Hours-- home Chicago 400 3 Chicago LA 600 10 LA Chicago 600 8 LA Vegas 200 1 LA Dallas 1000 12 Dallas Cincinnati 500 6 Dallas home 500 40 home Crash 40000 3000 Philly NY 150 2 NY LA 3000 8 CMD: UNLOAD Lots of Meat CMD: LOAD Lots of Candy Cargo too big CMD: PRINT Current City: LA Mile Flown: 1000 Hours Flown: 13 Fuel Rate: 700 gallons per hour Fuel Capacity: 70000 Consumed: 9100 Remaining: 60900 Volume Limit: 50000 Loaded: 9000 Remaining: 41000 Weight Limit: 60000.00 Loaded: 1200.00 Remaining: 58800.00 Current Cargo 20 x 30 x 15 1200.00 9000 Chicago Bull's Flight Table ------Origin------ ------Destination------ --Miles-- --Hours-- home Chicago 400 3 Chicago LA 600 10 LA Chicago 600 8 LA Vegas 200 1 LA Dallas 1000 12 Dallas Cincinnati 500 6 Dallas home 500 40 home Crash 40000 3000 Philly NY 150 2 NY LA 3000 8 CMD: FLY to Dallas CMD: LOAD Lots of Cows CMD: UNLOAD Chicago Bull's CMD: PRINT Current City: Dallas Mile Flown: 2000 Hours Flown: 25 Fuel Rate: 700 gallons per hour Fuel Capacity: 70000 Consumed: 17500 Remaining: 52500 Volume Limit: 50000 Loaded: 40000 Remaining: 10000 Weight Limit: 60000.00 Loaded: 5000.00 Remaining: 55000.00 Current Cargo 40 x 20 x 50 5000.00 40000 Lots of Cows Flight Table ------Origin------ ------Destination------ --Miles-- --Hours-- home Chicago 400 3 Chicago LA 600 10 LA Chicago 600 8 LA Vegas 200 1 LA Dallas 1000 12 Dallas Cincinnati 500 6 Dallas home 500 40 home Crash 40000 3000 Philly NY 150 2 NY LA 3000 8 CMD: FLY to home CMD: UNLOAD nothing CMD: FLY to Crash Out of Fuel!! Mayday! Mayday! We're going down!! Current City: home Mile Flown: 2500 Hours Flown: 65 Fuel Rate: 700 gallons per hour Fuel Capacity: 70000 Consumed: 70000 Remaining: 0 Volume Limit: 50000 Loaded: 40000 Remaining: 10000 Weight Limit: 60000.00 Loaded: 5000.00 Remaining: 55000.00 Current Cargo 40 x 20 x 50 5000.00 40000 Lots of Cows Flight Table ------Origin------ ------Destination------ --Miles-- --Hours-- home Chicago 400 3 Chicago LA 600 10 LA Chicago 600 8 LA Vegas 200 1 LA Dallas 1000 12 Dallas Cincinnati 500 6 Dallas home 500 40 home Crash 40000 3000 Philly NY 150 2 NY LA 3000 8

Extra Credit

Project 3 offers two opportunities for extra credit. If you implement the extra credit features, submit a file named ExtraCredit.txt indicating which extra credit work you performed.

CargoPlane::operator-= (const string& label) -- 5 points

The project description requires that you implement operator-=( ) for the CargoPlane as a replacement for UnLoadCargo. The parameter for operator-=( ) is a string which is the label of the Cargo to unload. This technique is not very elegant. It seems more logical that the parameter should be a Cargo object since that's what the CargoPlane contains.

For 5 points extra credit, overload operator-= to have a Cargo object as the parameter. This technique has some subtleties, not the least of which is the need for a new constructor for the Cargo class.

Static Members - 5 points

One common use of static data members and static methods is to keep track of the number of objects of a particular class type currently in existence.

For 5 points extra credit, you'll get practice with static members to count the number of Cargo objects that exist throughout the execution of your program. You will define and implement the necessary static data members and member functions of the Cargo class. Your program will report the number of Cargo objects in existence

  1. As the first line of code in main()
  2. As part of the output of the PRINT command
  3. Whenever a new Cargo object is created
  4. Whenever a Cargo object is destroyed

Free Advice and Information

  1. Use incremental development -- start with your Project 2 solution and make ONE modification at a time, testing each one as you go.
  2. Get your code working perfectly, THEN make your private data members be dynamically allocated as the last step.
  3. Get the required parts of your project working perfectly before attempting the extra credit.
  4. You may find it convenient to write a separate function for each possible command. These functions should be placed in Proj3Aux.cpp with their prototypes in Proj3Aux.h.
  5. Review the class notes on the different methods of passing parameters. Each is best for a different situation and data type.
  6. When calling getline( ) after using " >> " to input numeric data, you may need to use the function ignore( ) to remove the unused newline character. Ask about this in class, ask your TA, or ask the tutors in the HelpCenter.
  7. Use atoi( ) and atof( ) to change the command line arguments into integer and floating point values, respectively.
  8. About embedded classes....
    When class A defines an embedded class (call it class B), then the actual name of the embedded class is A::B, not just B. So the member functions of the embedded class are really named A::B::SomeFunction( ), not just B::SomeFunction().
    Class A has no special privileges to B's private data

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

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, examine and understand the makefile for project 2, then modify it for project 3.

When you want to compile and link your program, simply type the command make or make Proj3 at the Linux prompt. This will compile Proj3.cpp, CargoPlane.cpp, Cargo.cpp and FlightTable.cpp and create the executable named Proj3. Your executable MUST be named Proj3 as that name is used in the testing/grading scripts.

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.

Project Submission

Submit the following files for your project. You MUST use these filenames
  1. Proj3.cpp - contains main()
  2. Proj3Aux.cpp - contains helper functions called from main()
  3. Proj3Aux.h - contains prototypes, etc. for functions in Proj3Aux.cpp and is #included in Proj3.cpp
  4. Cargo.cpp - implementation of the Cargo class
  5. Cargo.h - interface for the Cargo class
  6. CargoPlane.cpp - implementation of the CargoPlane class
  7. CargoPlane.h - interface of the CargoPlane class
  8. FlightTable.cpp - implementation of the FlightTable and Flight classes
  9. FlightTable.h - interface for the FlightTable class and embedded Flight class
The order in which the files are submitted 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: Tuesday, 06-Apr-2004 18:21:42 EDT