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 CS110: Program #2

Program #3 -- Family Vacation Planning Program

Due Date

This assignment is due on Thursday, October 10th

Note that this program is worth 25% of your grade; the previous two assignments were only worth 20% each.

Introduction

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:

To do this, you will need to implement the five functions: 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.

Description of the functions you have to write

Please note that all these functions must behave exactly as specified.

The userChoice Function

The userChoice function should do the following:
  1. Prompt the user asking if s/he is interested in any of three possible vacation destinations.
  2. If the user enters 'y' indicating YES, you will query for the number of children and adults in the family and return the user's response. (NOTE: the number of children and number of adults are returned by reference to the main program to be used at a later stage)
  3. If the user enters 'n', simply return this response

The bookTickets Function

The bookTickets function should do the following:
  1. Ask the user if s/he wants to buy airline tickets. If the answer is no ('n'), then return 0.0 (no money spent).
  2. If the answer is yes ('y'), then display the following menu and ask for a choice of destination:
             Destination  - PER ADULT		
    	1. Hawaii : $672.19
    	2. Greece : $900.27
    	3. India  : $1599.99
    	Please choose a destination (1-3):
    
  3. Calculate the total air-travel cost. Note that children get a 37% discount.
  4. Return the total cost of the purchased tickets.

The bookRooms Function

The bookRooms function should do the following:
  1. Ask the user if s/he wants to book hotel rooms. If the answer is no ('n'), then return 0.0 (no money spent).
  2. If the answer is yes ('y'), then display the following menu and ask for a choice of hotel:
    	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):
    
  3. Ask for the number of rooms to book.
  4. Ask for the number of nights to stay.
  5. Calculate and return the total cost of the rooms.

The reserveCars Function

The reserveCars function should do the following:
  1. Ask the user if s/he wants to reserve any rental cars. If the answer is negative, return 0.0 (no money spent).
  2. If the answer is affirmative, display the following menu and ask for a choice of rental car company:
    	1. Budget     : $68.52 per day
    	2. Alamo      : $72.36 per day
    	3. RentAWreck : $25.99 per day
    	Please choose a car (1-3):
    
  3. Ask for the number of cars they would like to rent.
  4. Ask for the number of days they would like to rent the car.
  5. Ask if they would like collision insurance. Collision insurance will add 10% to the car rental cost.
  6. Calculate and return the total cost of the rentals.

The printReceipt Procedure

The printReceipt procedure should display the total amount spent at the travel agency.

The main program

Your main program must be very very short. It should simply call your functions at appropriate places. It should work as follows:
  1. Call 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.

Your test cases

You will be required to turn in the screen output generated from three program runs. The inputs should cleverly chosen so as to demonstrate all functionality of your program.

Handing In the Assignment

  1. Please turn in both an electronic copy of your source code (.cpp) and your executable program (.exe) into your handin directory. I will be testing each program with my test cases. If I do not receive an electronic copy of your source code and executable, you will lose most of the points. In case your program does not compile or run correctly, you must, nevertheless, turn in what you have to get some credit. If your program fails on my test cases you will receive a low score.
  2. A printed copy of source code.
  3. A printed copy of your three test cases

Items 2 and 3 must be stapled together.


Grading