CMSC 201
Programming Project Five
Trains
Out: Tuesday 5/1/01
Due: Before Midnight, Tuesday 5/15/01
The design document for this project,
design5.txt ,
is due: Before Midnight, Sunday 5/6/01
|
The Objective
This project will give you the opportunity to design your own structures,
practice with linked list implementations of stacks and queues, and do some
file-handling.
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 24. 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 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.
You should also have functions called DestroyStack and DestroyQueue which will
destroy these data structures when you are finished using them by freeing all
of the nodes.
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:
idNum contents weight bill origin destination
Here is the contents of a sample data file called 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
You may copy this file into your account by using the following command:
cp /afs/umbc.edu/users/s/b/sbogar1/pub/cs201/P5Data/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
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 would look like this :
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
- Keep in mind that you must work within the constraints of queues and
stacks, with the exception of the new function you can write for the queue
called Peek, and the necessary DestroyStack and DestroyQueue functions which
I did not provide.
- To simulate the movement of the cars correctly, you should have another
stack, possibly called transfer, which will contain the cars that have already
been dequeued from the train on the main line, but have not yet been pushed
onto the appropriate side-rail.
- Your program should produce the switching instructions which are to be
printed to the screen and 4 accounting files, one for each side-rail.
- Your program should accept the name of an input data file as its single
command line argument. This file could be named anything, so do not restrict
it to being named arriving.dat.
- The names of the accounting files your program produces should be
acct1.txt, acct2.txt, acct3.txt and acct4.txt, where acct1.txt contains the
accounting file for the train assembled on Track 1, etc.
Submitting the Program
You must use seperate compilation for this project.
Submit your files using the submit command, as in previous projects.