CMSC 201
Programming Project Three
My Summer Vacation
Out: Monday 10/30/00
Due: Before Midnight, Sunday 11/12/00
The design document for this project,
design3.txt ,
is due: Before Midnight, Sunday 11/5/00
|
The Objective
The objective of this assignment is to give you practice with project and
function design. It will also give you an opportunity to work with reading
information from a file, structures, an array of structures, passing by
reference, and some formatted printing.
The Background
I have been planning my summer vacation and have decided to visit some of
the New England states, south-eastern Canada and Niagra Falls by taking a
circular route. I have been using mapquest.com and yahoo.com to find out
information about the places I'd like to visit and to find out how many miles
I'll have to drive between each of these places and the expected driving time
between each site.
I have been putting the information that I've collected into a data file
called p3places.dat, but it is not in the form that I'd like to
see. The first two entries in the file are the starting location's city and
state:
Baltimore
MD
After that, the file contains the following fields for each site:
destination city
destination state
miles between the previous location and this one (mileage of this leg)
driving time, which is the elapsed time in minutes
You can view the p3places.dat file to examine
its contents and see its format.
You should copy this file into your account by using the following command:
cp /afs/umbc.edu/users/s/b/sbogar1/pub/cs201/P3Data/p3places.dat .
The Task
Design and code a project that will allow you to read in the information from
the p3places.dat file, manipulate it to be in the desired form, and produce a
chart that looks like the one shown below:
City of Origin Destination Miles Kilometers Time
------------------------------------------------------------------------------
Baltimore MD Lewes DE 114.9 184.9 2 hrs 58 mins
Lewes DE Cape_May NJ 17.0 27.4 1 hrs 10 mins
Cape_May NJ New_York NY 158.8 255.5 3 hrs 5 mins
New_York NY Mystic CT 135.0 217.2 2 hrs 36 mins
Mystic CT Gloucester MA 139.8 224.9 2 hrs 42 mins
Gloucester MA Kennebunkport ME 74.8 120.4 1 hrs 50 mins
Kennebunkport ME Bar_Harbor ME 204.2 328.6 4 hrs 22 mins
Bar_Harbor ME Quebec QC 275.9 443.9 6 hrs 20 mins
Quebec QC Montreal QC 153.6 247.1 2 hrs 48 mins
Montreal QC Ottawa ON 110.0 177.0 1 hrs 59 mins
Ottawa ON Toronto ON 248.8 400.3 4 hrs 37 mins
Toronto ON Niagra_Falls NY 80.9 130.2 1 hrs 37 mins
Niagra_Falls NY Corning NY 149.0 239.7 3 hrs 17 mins
Corning NY Hershey PA 188.6 303.5 5 hrs 0 mins
Hershey PA Baltimore MD 89.8 144.5 1 hrs 44 mins
and give a summary of the total miles, total kilometers, and total driving time
in hours and minutes of the complete trip.
The Specifications
- You must use the following structure definition and typedef:
typedef struct leg
{
char originCity[MAXCITYNAME];
char originState[MAXSTATE];
char destinCity[MAXCITYNAME];
char destinState[MAXSTATE];
float miles;
float kilometers;
int hours;
int minutes;
}LEG;
where MAXCITYNAME has been defined to be 15 and MAXSTATE has been
defined to be 3.
- You will store the information that you get from the file into an
array of LEGs, where each element of the array will hold the information
for one leg of the journey. The array size should be 25.
- You must ask the user to enter the name of the data file to be used and
you must allow that filename to be as much as 30 characters long.
- The kilometers must be computed from the miles given in the file. There
are 1.609 kilometers per mile.
- The file has the driving time in elapsed minutes. You may use the
ConvertTimeToHM() function from Lecture #13 without citing your source, to
convert this time to the hours and minutes that are to be stored in the
LEG.
- You must have a function called FindTotals() and it must have the
following prototype:
void FindTotals (LEG places[], int numPlaces, float* pMiles,
float* pKilometers, int* pHours, int* pMinutes);
where pMiles, pKilometers, PHours, and pMinutes are pointers to the
miles, kilometers, hours and minutes variables in the calling function.
This function should total all of the miles, kilometers, hours and minutes
for all of the legs of the journey.
- Be aware that the total minutes will probably be more than one hour, so
you should adjust the values of hours and minutes of that total so that
the minutes shown in the total will be less than 60.
- Since we have not covered pointers to pointers in much detail yet, you
are NOT required to have a function called OpenFile(). You may open the
file in main() and then pass the FILE* to the function that reads from the
file. Don't forget to close the file as soon as you have finished reading
from it. Also, you do not have to use dynamic memory allocation for the
array of LEGs, you can just declare it.
- You must produce a table using formatted printing (discussed in Chapter 9)
to make your table look similar to mine, shown both above in the
description and below in the sample output. You must have the same
aligned columns of information as shown. Miles and kilometers must be
aligned by their decimal points as shown. Your spacing of the columns
may be different. Make your table fit in an 80-character wide screen.
Sample Run
ecs225d-sgi-01[102] a.out
Your Greeting goes here ...
Please enter the name of the vacation information file : p3places.dat
City of Origin Destination Miles Kilometers Time
-------------------------------------------------------------------------------
Baltimore MD Lewes DE 114.9 184.9 2 hrs 58 mins
Lewes DE Cape_May NJ 17.0 27.4 1 hrs 10 mins
Cape_May NJ New_York NY 158.8 255.5 3 hrs 5 mins
New_York NY Mystic CT 135.0 217.2 2 hrs 36 mins
Mystic CT Gloucester MA 139.8 224.9 2 hrs 42 mins
Gloucester MA Kennebunkport ME 74.8 120.4 1 hrs 50 mins
Kennebunkport ME Bar_Harbor ME 204.2 328.6 4 hrs 22 mins
Bar_Harbor ME Quebec QC 275.9 443.9 6 hrs 20 mins
Quebec QC Montreal QC 153.6 247.1 2 hrs 48 mins
Montreal QC Ottawa ON 110.0 177.0 1 hrs 59 mins
Ottawa ON Toronto ON 248.8 400.3 4 hrs 37 mins
Toronto ON Niagra_Falls NY 80.9 130.2 1 hrs 37 mins
Niagra_Falls NY Corning NY 149.0 239.7 3 hrs 17 mins
Corning NY Hershey PA 188.6 303.5 5 hrs 0 mins
Hershey PA Baltimore MD 89.8 144.5 1 hrs 44 mins
Your trip is a total of 2141.1 miles or 3445.0 kilometers.
The total driving time will be 46 hours and 5 minutes.
There are 15 legs in this journey.
Bon Voyage !!!
ecs225d-sgi-01[103]
Submitting the Program
You are to use seperate compilation for this project, so you will be
submitting a minimum of three files.
Your C source code file that
contains main() MUST be called proj3.c. I would expect
that you would also have files called trip.c and trip.h, but you
may choose to have additional .c and .h files.
To submit your project, type the following at the Unix prompt.
Note that the project name starts with uppercase 'P'.
submit cs201 Proj3 proj3.c trip.c trip.h (and possibly
other files, seperated by spaces)
To verify that your project was submitted, you can execute the
following command at the Unix prompt. It will show all files that
you submitted in a format similar to the Unix 'ls' command.
submitls cs201 Proj3