|
CMSC 201
Programming Project Five
Road Trip 2
Out: Monday 11/24/03
Due: before Midnight, Monday 12/8/03
The design document for this project, design5.txt ,
is due: Before Midnight, Sunday 11/30/03
|
The Objective
This project will give you practice using good design techniques, separate
compilation, arrays of structures, command-line arguments, file handling,
dynamic memory allocation, string manipulation, and a linked-list
implementation of a list ADT.
The Background
This project is a trip planner, rather than the trip cost estimator that we
wrote in Project 3. It doesn't really do any cost estimating, but will allow
you to plan a trip by including a list of attractions, their cost and time
necessary to see them to each of the legs of the trip.
If you wanted to do so you could use Project 3 in combination with this project
to make yourself a really nice trip planning package. There is not enough
time in this course to do so, however. ... A Winter Project ? ;)
The data files for this project are trip2.dat and
attractions.dat. trip2.dat is of the same form
as the newtrip.dat file from project 3, except that cities with multiple words
in their names no longer use underscores between the words. Since the planning
has been much more careful at this point, many of the origin and destination
cities are different (to allow more time to view attractions).
The Task
Your task is to read the legs of the trip in from the trip2.dat file, and then
construct a linked list of attractions for each of the legs of the trip using
the information found in the attractions.dat file. Please note that not all
legs of the trip will have attractions. Those legs then will have an empty
list of attractions and you should print out an appropriate message for those.
(See sample output).
As in Project 3, the trip2.dat file contains information about each leg of the
journey, which includes a city of origin and the destination, the number of
days planned to stay at the destination and the number of miles from the origin
to the destination of that particular leg.
The attractions.dat file contains the origin and destination city of a leg as
a string, the name of an attraction, the cost of that attraction for 2 adults,
and the amount of time needed to see that attraction, followed by the three
pieces of information for each of the other attractions for that leg and then
a line of 5 dashes, -----. Legs of the journey that have no attractions are
not in the attractions.dat file.
More details
- You must use the following typedefs and structure definitions :
typedef struct attraction
{
char name[50];
float cost;
int hours;
int minutes;
}ATTRACTION;
where all items are contained in the attractions.dat file.
typedef struct node * NODEPTR;
typedef struct node
{
ATTRACTION data;
NODEPTR next;
}NODE;
You'll use NODEs to construct the linked list of attractions for each leg.
typedef struct leg
{
char originCity[20];
char originState[3];
char destinCity[20];
char destinState[3];
int nights;
int miles;
NODEPTR attractions;
}LEG;
where all of the information except the NODEPTR attractions
is given in the trip2.dat file. As before, the
number at the beginning of the file is the number of legs found in the file.
- You must build the array of LEGs using trip2.dat and then construct a
linked list of attractions for all of the legs that have attractions.
You'll notice that the LEG structure now has a NODEPTR called attractions
as one of its members. This member is to hold the head of the
linked-list of attractions for that leg. Some legs will have an empty
list of attractions.
- You must use command-line arguments to get the names of the two data
files. Of course, you must check to make sure you've gotten the correct
number of arguments.
- You must use dynamic memory allocation for the array of legs and also
for each of the nodes used in the linked-lists. You must check after
every allocation to make sure that you've gotten the memory and you must
also remember to free all of the memory when you are finished using it.
- You are also using C file-handling, so you must make sure that each file
is properly openned and you must close each file when you have finished
reading from it.
- All error messages should be printed to stderr.
The data files
The data files are trip2.dat and
attractions.dat
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 files
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/trip2.dat .
cp /afs/umbc.edu/users/s/b/sbogar1/pub/attractions.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.
What to Turn In
You must use separate compilation for this project and should have a
file, called proj5.c, that contains only the function main(). You should
also have several other .c and .h files. I'll leave the naming of them to
you.
Submit as follows:
submit cs201 Proj5 proj5.c (followed by any other .c & .h files you have)
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.
Don't forget to submit your .h files