CMSC 201
Programming Project Three
Road Trip
Out: Wednesday 10/22/03
Due: before Midnight, Tuesday 11/4/03
The design document for this project, design3.txt ,
is due: Before Midnight, Tuesday 10/28/03
|
The Objective
This project will give you practice using good design techniques, separate
compilation, pointers, structures, arrays of structures, file handling,
and dynamic memory allocation.
The Background
This past summer, my husband and I went on a road trip through the New England
states to Acadia National Park in Maine, and then west through upstate New
York to Niagra Falls. We returned home through New York state and central
Pennsylvania. We really enjoyed our trip and since my husband has never
really travelled much, we decided that this summer we will do an extensive
road trip across the United States.
On our trip, we kept track of our gas purchases and mileages so that we could
see how many miles per gallon our car was getting. We found that our gas
mileage varied quite a bit depending upon whether we were logging highway
miles or were in slow traffic situations. The price of a gallon of gas varied
quite a bit too. The highest price paid was on the New Jersey Turnpike. No
surprise there. We also kept track of the amount of cash we were spending.
We used cash for food, admission to museums and other attractions, souveniers,
and miscellaneous items. We charged all of our hotels bills and gas purchases.
For this project, I would like you to use the information from the old trip to
estimate the cost of the new trip.
The Task
Your task is to read in the gas information from the gas.dat file, and the
hotel information from the hotel.dat file and then use this information along
with the amount of cash spent, $1,159.84, to calculate the following data:
- average mpg
- average cost per night for accomodations
- average amount of cash spent per day
You will then read in the itinerary for the new trip from the newtrip.dat
file. It 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.
Using the total number of miles for the entire trip, the miles per gallon that
you've calculated from last summer's data and the current price of gasoline
per gallon, you must calculate the total cost of the gasoline for the new trip.
Using the average cost per night for accomodation that you've already found,
and the number of nights planned for the new trip, you can calculate the cost
of accomodations. Using the cash spent per day that you've found from last
summer's trip, and the number of days expected for the new trip, you can
calculate the total cash needed.
More details
- You must use the following structure definitions :
typedef struct fill
{
int odometer;
float gallons;
float cost;
int elapsedMiles;
float mpg;
float pricePerGal;
}FILL;
where the odometer reading, number of gallons purchased, and total cost of
the fill are contained in the file. The elapsed miles, miles per gallon and
price per gallon must be calculated.
typedef struct hotel
{
char hotel[25];
char city[15];
char state[3];
int nights;
float cost;
float costPerNight;
}HOTEL;
where all data is found in the file except the cost per night, which must
be calculated.
typedef struct leg
{
char originCity[20];
char originState[3];
char destinCity[20];
char destinState[3];
int nights;
int miles;
}LEG;
where all of the information is given in the file.
- You must prompt the user for the current price per gallon of unleaded
regular gasoline (since that's the kind this car uses).
- You must read the information in from the gas.dat file and use it to
fill an array of FILL structures. The first item in the file is the
number of fills. You must use this number to dynamically allocate the
memory needed to hold your array of structures. The next item in the
file is the starting odometer reading. After that the data consists of
the odometer reading, number of gallons, and the purchase price for
each fill. (The other members of the structure must be calculated.)
You must then generate a report about the gas mileages similar to the
one shown in the sample output. It doesn't have to look exactly like the
sample, but the numbers should agree and all of the same information needs
to be shown.
- You must read the information from the hotels.dat file into an array of
HOTELs. The first item in the file is the number of hotels in the file.
You should use this number to dynamically allocate the space you need for
this array of hotel structures. As mentioned earlier, you'll need to
calculate the cost per night member of the structure from the information
found in the file.
You must generate a report about the hotels that contains all of the
information shown in the sample output. Again, your report doesn't have
to look exactly like mine, but the numbers should be the same.
- Next your program must read the information found in the newtrip.dat
file into an array of LEGs. The first item in the file is the number
of legs of the new trip. Space must be dynamically allocated for this
array too. Each leg has an origin city and state and a destination city
and state, the number of nights to be spent at the destination, and the
number of miles for this leg of the trip.
You must print a report, as in the sample output about the legs of the
journey. Your output must be in a reasonable format although it need
not look just like the sample.
- Next your program should calculate and report the estimated items
for the new trip. (See the sample output)
The data files
The data files are gas.dat,
hotels.dat, and newtrip.dat, which can be
viewed from these links. 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/gas.dat .
cp /afs/umbc.edu/users/s/b/sbogar1/pub/hotels.dat .
cp /afs/umbc.edu/users/s/b/sbogar1/pub/newtrip.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 proj3.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 Proj3 proj3.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.