CMSC 201
Programming Project Five
Trains 2
Out: Monday 4/27/09
Due: Before 11:59 PM, Sunday 5/10/09
The design document for this project,
design5.txt ,
is due: Before 11:59 PM, Sunday 5/3/04
|
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 21. 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 21.
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:
carNum cargo origin destination weight miles
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/b/o/bogar/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
- 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
we 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. This is necessary to simulate the
movement of adjacent cars in the arriving train that are bound for the
same destination (in reality moved as a multi-car unit), while still
working within the constraints of the stack and queue which require moving
only a single car at a time.
- 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. Each of the
accounting files must contain the car information for the cars on that
Track, in the order they are on that track, beginning at the top of that
stack. The accounting file must also state how many cars are on that
track and give the total weight in tons and the total bill for that train.
- You may be able to reuse some of your functions from proj3 for this
project unchanged (i.e. FindTons, PrintCar) and some others with minor
modification (i.e. FindTotals). You may use the stack and queue code
supplied in Lecture 21. Some of these functions can be used unchanged and
others will require minor modification.
- You must use the same CAR structure specified in Project 3 and you
must use the same rates per ton-mile. You may be able to use your train.c
and train.h files without modification if your functions were written to
be as modular as possible. You just won't be making calls to all of the
functions in that file.
- You must guard your header files.
- You must use the linked-list implementations of both the stack and the
queue. Use of array implementations of stacks and queues will receive NO
credit.
Submitting the Program
- You must use separate compilation for this project. You should have
many .c and .h files.
- Submit your files using the submit command, as in previous
projects.
Check your submissions using submitls as described in previous project
descriptions.