UMBC CMSC201, Computer Science I, Spring '98

Project 5: Trains

Due date: Tuesday, May 12, 1998

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.

This project will give you practice with linked list implementations of stacks and queues, and file-handling.


Description of the Program

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 23. 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 given in lecture 24.

You will probably want 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.

There will be a file made available to you called arriving.dat 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 data file, arriving.dat:

301 coal 13000 450.50 Atlanta Portsmouth 321 cattle 5000 225.50 Laredo Portsmouth 353 hogs 3500 199.00 Topeka Portsmouth 443 eggs 3000 125.50 Lancaster Miami 115 coal 13500 490.25 Atlanta Norfolk 145 coal 13700 505.75 Atlanta Norfolk 123 tanks 25000 650.25 Chicago Norfolk 492 hogs 3750 202.75 Atlanta Chicago 230 eggs 3100 126.50 Lancaster Roanoke 220 coal 13600 502.75 Pittsburg Roanoke 413 eggs 3000 125.50 Lancaster Atlanta

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 Norfolk. Track 2 will contain cars destined for Roanoke. Track 3 will contain cars destined for Portsmouth. Track 4 will contain cars that are going to other destinations.

Sample switching instructions for this train might look like the following :

Uncouple between cars 353 and 443 and back them onto track 3. Uncouple between cars 443 and 115 and back car 443 onto track 4. Uncouple between cars 123 and 492 and back them onto track 1. Uncouple between cars 492 and 230 and back car 492 onto track 4. Uncouple between cars 220 and 413 and back them onto track 2. Back car 413 onto track 4.

An example accounting file (this one for Track 1) would look like this:

Track 1: A total of 3 cars bound for Norfolk : Car Number: 115 Contents: coal Weight: 13500 Bill: $ 490.25 Origin: Atlanta Destination: Norfolk Car Number: 145 Contents: coal Weight: 13700 Bill: $ 505.75 Origin: Atlanta Destination: Norfolk Car Number: 123 Contents: tanks Weight: 25000 Bill: $ 650.25 Origin: Chicago Destination: Norfolk Total weight: 52200 Total bill: $ 1646.25

More details


Copying the files

arriving.dat can be found in my 201 directory.
     cp ~sbogar1/201/arriving.dat .