CMSC 201
Programming Project Three
Vacation Estimator
Out: Monday 3/31/08
Due: Before 11:59 p.m., Sunday 4/13/08
The design document for this project,
design3.txt ,
is due: Before 11:59 p.m., Monday 4/7/08
|
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, using structures, an array of structures, passing by
reference, and some formatted printing.
The Background
The dollar isn't fairing well against other world currencies, so a trip to
London and Paris this summer wouldn't be financially responsible. Six-week,
cross-country road trips of the past are also out of the question due to high
gas prices. Since Ocean City is not my idea of fun, I decided to try to plan
a two-week, short road trip to see if it will fit our budget.
I've decided to visit some of the New England states, south-eastern Canada and
Niagara Falls by taking a circular route. I have been using Google to find
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 finding prices of hotels and B & B's I'd like to use, tour prices
and musuem admissions. I can even estimate food costs and balance fine meals
with cheap eats. The only part of the trip I can't estimate in advance is the
amount I'll have to spend on gas. We have no way of knowing what the price of
gas will be in June.
I've been putting the information that I've collected into a data file
called vacationPlaces.dat, but it's not in the form that I'd like to
see AND we need to estimate the cost of the gas in order to find a vacation
total.
The Task
Design and code a project that will allow you to read in the information from
a data file, store it in an array of structures so that the file can be closed,
and then use the information in the array of structures to find the following
totals for the entire trip:
- total miles
- total number of nights
- total cost of food & lodging
- total cost of admissions & miscellaneous expenses
The user will need to enter the following information:
- the name of the data file to be used (a string of size 30 or less)
- the mileage the car being driven gets, in miles per gallon (a float)
- the expected gas price (needed to calculate the total cost of gas)
Your program will also need to calculate:
- the total cost of gas
- the grand total for the vacation
and will need to produce a chart of transportation data, a chart of costs, and
a final report summarizing the information for the user. The charts should
present the data nicely formatted with columns of values aligned by their
decimal points. See the sample output below.
The data file contains the following information:
- The first entry in the file is an integer which is the
number of legs of the trip.
- The next 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 leg:
- destination city
- destination state
- miles between the previous location and this one, the mileage
of this leg
- driving time, which is the estimated driving time in minutes
- the major attraction of that leg
- the number of nights spent at the destination location
- the cost of food & lodging at the destination location
- the cost of admissions to attractions and any miscellaneous costs
You can view the vacationPlaces.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/b/o/bogar/pub/vacationPlaces.dat .
The Specifications
- You must use the following structure definition and typedef:
typedef struct leg
{
char originCity[CITY_NAME_SIZE];
char originState[STATE_NAME_SIZE];
char destinCity[CITY_NAME_SIZE];
char destinState[STATE_NAME_SIZE];
float miles;
int hours;
int minutes;
char attraction[ATTRACTION_NAME_SIZE];
int nights;
float foodAndLodging;
float admissionAndMisc;
}LEG;
where CITY_NAME_SIZE has been defined to be 11, STATE_NAME_SIZE has
been defined to be 3 and ATTRACTION_NAME_SIZE has been defined to be
30.
- 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 20.
HINT : the origin of a leg is the previous leg's destination.
- 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. Any
datafile we use for testing will have the exactly the same format as
vacationPlaces.dat
- The file has the driving time in elapsed minutes. You may use the
ConvertTimeToHM() function from Lecture #12 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 legs[], int numLegs, float* pMiles, int* pHours,
int* pMinutes, int* pNights, float* pFoodAndLodging,
float* pAdmissionAndMisc);
where pMiles, pHours, pMinutes, pNights, pFoodAndLodging and
pAdmissionAndMisc are pointers to the variables called miles, hours,
minutes, nights, foodAndLodging and admissionAndMisc, respectively, in
the calling function, so you should pass the addresses of these
variables into this function. This function should total the miles,
hours, minutes, nights, food and lodging costs, and admission and
miscellaneous costs for all of the legs of the journey and store those
totals in the variables miles, hours, etc. in the calling function.
- Be aware that after you've calculated the total time for the trip (the
total number of minutes and hours), the value of minutes will probably
be way more than 60, which is an hour. So you'll need to adjust the
values of hours and minutes of that total, which will result in the
value of minutes being less than 60. You could make use of the
TimeToHM() function again if you'd like.
- If you would like to have a module called OpenFile(), then it should
return a FILE* to the calling function. 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 if you prefer.
Don't forget to close the file as soon as you have finished reading
from it. (To be covered in Lecture on Wed/Thur)
- Do NOT use dynamic memory allocation for the array of LEGs, just
declare it (in main). If there are more legs in the file than can be
stored in the array, which is is of size 20, then you should print an
error message to the user and exit the program. (To be covered in
Lecture on Wed/Thur)
- You must produce tables using formatted printing to make them look
similar to those shown below in the sample output. You must have the
same aligned columns of information as shown. Miles and costs must
be aligned by their decimal points as shown. Your spacing of the
columns may be different, but your table must fit in an 80-character
wide screen.
Sample Runs
The 2007 sample run uses gas prices from last
summer and
the 2008 sample run uses an estimated price of
$4.00/gal expected this summer.
Submitting the Program
You are to use separate compilation for this project, so you will be
submitting five files.
Your C source code file that contains main()
MUST be called proj3.c. You should also have files called
trip.c and trip.h, and util.c and util.h.
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 util.c util.h
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