Date: Mon, 11 Nov 1996 17:35:30 GMT Server: NCSA/1.5 Content-type: text/html Last-modified: Sun, 29 Sep 1996 16:31:07 GMT Content-length: 9419
Note that this program is worth 25% of your grade; the previous two assignments were only worth 20% each.
This assignment is meant to give you practice using functions; passing parameters by value and by reference; return statements; if/else statements and switch statements.
The story so far: You've been hired by HAPPY FAMILY travel agency to create a reservation system. The basic idea of this program is to aid the user to estimate the cost of her/his family vacation. Even though you have had only a month of C++, your employers insist you complete the project by the stated deadline.
But there is a silver lining. A previous programmer (now unemployed) had previously tried (unsuccessfully) to write the program last year -- and he left notes! A skeleton program! Just the thing to get you started. Using this outline code, and a list of guidelines required by your employers, you must now begin your plan of attack ...
Your program will need to be "full-featured" and allow the user to:
userChoice()
,
bookTickets()
,
bookRooms()
,
reserveCars()
, and
printReceipt()
which are outlined below. The skeleton code follows:// a header comment should go here // include statements should go here // function prototypes char userInput(); char userChoice(int& numChildren, int& numAdults); double bookTickets(int numChildren, int numAdults); // returns ticket cost double bookRooms(); // returns room cost double reserveCars(); // returns car rental cost void printReceipt(double totalCost); // displays total cost void main() // main should just call the auxiliary functions { // and must be very short! } //gets input after a Y/N question char userInput() { char response; cin >> response; if ((response == 'y')||(response == 'Y')) return 'y'; else if ((response == 'n')||(response == 'N')) return 'n'; else { cout<<"Bad Input--expected Y or N and you typed: "<<response<<<endl; cout<<"shame on you! Aborting program...."<<endl; exit(0); } } char userChoice(int& numChildren, int& numAdults) { char response; // user's response return response; } double bookTickets(int numChildren, // returns plane tix cost int numAdults) { const int HAWAII = 1; // only three destinations const int GREECE = 2; // are necessary for this program const int INDIA = 3; // -- do more if you want } double bookRooms() // returns room cost { const int MARRIOT = 1; // hotels -- again, three minimum const int DAYS_INN = 2; const int MOTEL6 = 3; } double reserveCars() // returns car rental price { const int BUDGET = 1; // rental car companies -- three min const int ALAMO = 2; const int RENT_A_WRECK = 3; } void printReceipt(double totalCost) // prints out total cost // (don't cout totals from within main!) { }
Note: You have been supplied with a working function userInput() that accepts the answer to a Y/N question (and filters out invalid input). To greatly simplify your code, you might choose to use it ...
Also since a lot of the above code involves implementing menu-driven decisions, you might find the switch statement quite helpful. Look at the examples of the switch statements we looked at in lecture.
userChoice
function should do the following:
bookTickets
function should do the following:
Destination - PER ADULT 1. Hawaii : $672.19 2. Greece : $900.27 3. India : $1599.99 Please choose a destination (1-3):
bookRooms
function should do the following:
1. Marriot : $65.00 per night 2. Days Inn : $45.95 per night 3. Motel 6 : $36.00 per night Please choose a hotel (1-3):
reserveCars
function should do the following:
1. Budget : $68.52 per day 2. Alamo : $72.36 per day 3. RentAWreck : $25.99 per day Please choose a car (1-3):
printReceipt
procedure should display the total
amount spent at the travel agency.
userChoice()
function:
If function returns 'n' your program must terminate with a thank you message.
If function returns 'y' your program should call the other functions
bookTickets(), bookRooms(), reserveTickets()
and
printReceipt()
. It must then terminate with a thank you
message.
If function returns anything other than a 'n' or a 'y' your program must terminate with an error message.