UMBC CS 201,Spring 04
UMBC CMSC 201 Spring '04 CSEE | 201 | 201 S'04 | lectures | news | help

CMSC 201
Programming Project Five

Trains 2

Out: Sunday 4/25/04
Due: Before Midnight, Monday 5/10/04

The design document for this project, design5.txt ,
is due: Before Midnight, Monday 5/3/04

Modification 5/05 1:32 PM: Changed project due date from Sunday 5/9 to Monday 5/10.

Modification 5/03 1:40 PM: Changed design5.txt due date from Sunday 5/2 to Monday 5/3.

Modification 4/30 1:15 AM: The provided datafile at /afs/umbc.edu/users/s/b/sbogar1/pub/arriving.dat has been updated to match what is posted on the project description. If you have previously copied the datafile, simply reissue the copy command to get the matching version.

The Objective

This project will give you the opportunity to practice with the linked list implementations of stacks and queues, work some more with dynamically allocated memory, make use of command line arguments, use the stderr stream for reporting errors and guarding header files.

The Background

Computer simulations are becoming widespread in everyday use. In the past, simulations were done only to model dangerous situations. Then they were used for expensive projects, like new car design. As the price of computing has fallen, we find computer simulations being used throughout many industries and within our everyday lives.

For this project, you will model a railway switching yard that uses computer generated switching instructions for the yard crew. These instructions are prepared by running a simulation of a train arriving at the yard on the main rail, and building new trains from its cars, each new train having a different destination. You will also create a file containing accounting information for each of the new trains being assembled to be used by the main accounting office.

The Task

You are to simulate the train arriving at the switching yard as a queue. Keep in mind that working code for a queue is given in lecture 22. Each of the trains you are assembling, each on its own side rail, is to be modeled using a stack. Working code for a stack is also given in lecture 22.

You are allowed to add a new function to the queue code named Peek(), that lets you look at the information contained in the first node of the queue without dequeueing it. Depending upon your design choices, you may or may not want this function.

You are required to have functions called DestroyStack() and DestroyQueue() which will destroy these data structures when you are finished using them by freeing all of the nodes and setting the heads to NULL.

The Specifications

You are to use an input data file that will contain information about each of the cars in the arriving train, in order of their occurrence in the train. Each car's information will consist of the following, in this order:

Here is the contents of a sample data file called arriving.dat:

45301 coal Pittsburgh Baltimore 13000 229 57321 cattle Lancaster Trenton 5000 198 82353 hogs York Trenton 3500 181 77443 eggs Lancaster Charlotte 1500 481 39115 coal Pittsburgh Norfolk 13500 451 27145 coal Pittsburgh Norfolk 13700 451 81123 autos Detroit Baltimore 27000 477 32492 hogs Lancaster Trenton 3750 198 65230 eggs Lancaster Newark 1600 245 37220 coal Pittsburgh Roanoke 13600 495 72413 autos Detroit Trenton 26500 610 49374 autos Detroit Charlotte 27300 893 92949 eggs Lancaster Charlotte 1550 481 You may copy this file into your account by using the following command:
cp /afs/umbc.edu/users/s/b/sbogar1/pub/arriving.dat .

If we refer to the main line as track 0, then we want to build a new train on the side-rail referred to as track 1 that contains only cars destined for Trenton. Track 2 will contain cars destined for Charlotte. Track 3 will contain cars destined for Baltimore. Track 4 will contain cars that are going to other destinations.

Sample switching instructions for this train would look like this :

Uncouple between cars 45301 and 57321 and back car 45301 onto track 3. Uncouple between cars 82353 and 77443 and back them onto track 1. Uncouple between cars 77443 and 39115 and back car 77443 onto track 2. Uncouple between cars 27145 and 81123 and back them onto track 4. Uncouple between cars 81123 and 32492 and back car 81123 onto track 3. Uncouple between cars 32492 and 65230 and back car 32492 onto track 1. Uncouple between cars 37220 and 72413 and back them onto track 4. Uncouple between cars 72413 and 49374 and back car 72413 onto track 1. Back remaining cars onto track 2.

An example accounting file (this one for Track 1, acct1.txt) would look like this:

Track 1: A total of 4 cars bound for Trenton : Car number : 72413 Cargo : autos Origin : Detroit Destination : Trenton Weight : 26500 pounds Distance : 610 miles Cost : $ 1333.61 Car number : 32492 Cargo : hogs Origin : Lancaster Destination : Trenton Weight : 3750 pounds Distance : 198 miles Cost : $ 234.26 Car number : 57321 Cargo : cattle Origin : Lancaster Destination : Trenton Weight : 5000 pounds Distance : 198 miles Cost : $ 259.88 Car number : 82353 Cargo : hogs Origin : York Destination : Trenton Weight : 3500 pounds Distance : 181 miles Cost : $ 199.87 Total weight: 19.375 tons Total bill: $ 2027.62

More details

Submitting the Program