UMBC CS 201, Spring 06
 UMBC CMSC 201 Spring '06 CSEE | 201 | 201 S'06 | lectures | news | help Search Notes:

 CMSC 201 Programming Project Three Trains Out: Friday 3/31/06 Due: before Midnight, Sunday 4/16/06 The design document for this project, design3.txt , is due: Before Midnight, Sunday 4/9/06

## The Objective

This project will give you practice using good design techniques, separate compilation, pointers, structures, arrays of structures, string comparison, C file-handling functions, and dynamic memory allocation.

## The Background

Trains are used by industry to transport both their raw materials and finished goods and by farmers to ship their crops and livestock to market. Freight rates are different for each type of item shipped and are generally given in cents per ton-mile. A rate of 52.5 cents per ton-mile means that it will cost 52 and 1/2 cents to ship 1 ton of that item a distance of one mile. Rates vary quite a bit due to the density of some items. For instance, the rate for shipping coal needs to be much less than the rate for shipping eggs.

For this project, you will be keeping track of the cars found in one train. For each of the cars, there is a car identification number, the cargo being carried, the origin and destination, the number of miles being travelled from the origin to the destination, the weight of the items in the car in pounds, and the cost of shipping that car full of product.

You will also need to keep some information about the entire train. You'll need to know the number of cars in the train, the total weight of everything being shipped and the total shipping cost associated with the cars in this train.

Your task is to read in information from the cars.dat file, find the shipping cost for each car, and the train totals mentioned above. You will then use this information to print out a train report. You will also draw an illustration of this train using ascii art, which is a crude picture comprised solely of ascii characters. See the sample output for an example.

## More details

• You must use the following structure definition : typedef struct car { int carNum; char cargo[LENGTH]; char origin[LENGTH]; char destination[LENGTH]; int weight; int miles; float cost; }CAR; where LENGTH has been #defined to be 12. The car number, cargo, origin, destination, weight in pounds, and miles for each car are contained in the file. The cost must be calculated using the appropriate rate for that car's cargo, its weight in tons (not pounds) and the number of miles. The cost should be in dollars.

• The shipping rates in cents per ton-mile are : autos : 16.5 coal : 29.1 cattle : 52.5 hogs : 63.1 eggs : 75.9
• You must read the information in from the cars.dat file and use it to fill an array of CAR structures. You are to use the C file-handling functions for this project. The first item in the file is the number of cars. You must use this number to dynamically allocate the memory needed to hold your array of structures. After that initial integer which is the number of cars, the data consists of the car id number, the cargo, the origin, the destination, the weight, and the miles for each car. The last member of the structure, cost, is not contained in the file and must be calculated as described earlier.

• You must then generate a report that shows all of the information for each of the cars and the train totals. It doesn't have to look exactly like the sample, but the numbers should agree and all of the same information needs to be shown. It must also fit within an 80-character wide screen.

• You MUST must have a function called FindTotals and you must use the following function prototype for that function without altering it in any way : void FindTotals(CAR* train, int numCars, float* costPtr, int* wtPtr);

• You must then produce an ascii drawing of the train, with some of the information about each of the cars being shown inside the boxcar itself. Each boxcar must contain the car's id number, its cargo and its destination. You may assume that the cars are in the train in the order that they are read in from the file. When drawing the train you should use an arrow as the coupler between cars to indicate the direction in which the train is travelling. The drawing of the train must be accomplished within an 80-character wide screen. This means that unless the data file is extremely short, the drawing of train will have to be continued on lower lines. See the sample output and note that a train which is 12 cars long has to be printed in three sections. The first section has 5 cars, the second has 5 cars and the last section has the remaining 2 cars. The printing of the train is the major problem-solving portion of this project and as such will carry a fairly high points value.

• The data file, cars.dat, is a sample data file. It has the same format as the data files that we will use to test your projects. You should realize that other data files may contain no cars or many more cars than this sample file and your project must work properly for all files with this format, regardless of the number of cars in that file.

## The data files

The data file is cars.dat, which can be viewed from this link. You should NOT view it and save it into a file or cut and paste it from the browser into a file. Either of these methods of obtaining the file may cause there to be extraneous characters in the file that your program will try to read and disrupt the input of your data. Instead you must copy the file from my directory into the directory that you'll be using to work on this project.

Go to that directory and then issue the following commands exactly :

cp /afs/umbc.edu/users/s/b/sbogar1/pub/cars.dat .

The space and the . (dot) at the end of each command are necessary and a part of the command.

## Sample Output

Since the output file is large, instead of showing the output here, I am just providing a link to my output file, output

Although your output may look different than mine, you should print out the same information and of course the format of the train drawing must be extremely similar, if not identical, to mine.

## What to Turn In

You must use separate compilation for this project and should have a file, called proj3.c, that contains only the function main(). You should also have train.c and train.h.

Submit as follows:

submit cs201 Proj3 proj3.c train.c train.h

The order in which the files are listed doesn't matter. However, you must make sure that all files necessary to compile your project are listed.