Lab Objectives

In this lab you will practice:

  • Define a function
  • Understand every part of the function definition
    • The header of the function definition
    • The parameter and return value are for data exchange between functions
  • Make a function call
  • Add function prototype

Problem Description

Modify the provided C++ program Program6_ReserveRoom.cpp to use user-defined functions without changing the functioning of the given program. The figure on the following page is the provided program Program6_ReserveRoom.cpp.

1. In the comments on the top of the code, add your name and the current date

2. The code segment in the BLUE box is to display the menu for different rooms. A function displayMenu could be created for this part:

  • It does not take any input - has no parameter
  • It does not output any value - have no return value

3. The code segment in the RED box is to request the room choice from the user. A function makeChoice could be created for this part:

  • It does not take any input - has no parameter
  • It outputs the user choice - returns an integer

4. The code segment in the GREEN box is to reserve a room according to the user's choice. A function reserveRoom could be created for this part:

  • It takes an input - has an integer parameter
  • It does not output any value - have no return value

5. Function calls

  • The above functions are created by moving the code segments into the body of the function definitions
  • function calls need to be added to where those code segments used to be

6. Function prototypes

  • Let main function to be on the top of all other functions
  • The function prototypes need to be added before main function

Program6_ReserveRoom_YourName.cpp

#include < iostream >
using namespace std;

int main()
{
int choice;

cout << "This system is for conference room reservation\n";

//Display the menu
cout << "\n*****************************************\n";
cout << "*\t 1. Red Private Room\t\t*\n";
cout << "*\t 2. Green Board Room\t\t*\n";
cout << "*\t 3. Blue Class Room\t\t*\n";
cout << "*\t 4. Yellow Banquet Room\t\t*\n";
cout << "*\t-1. Exit\t\t\t*\n";
cout << "*****************************************\n";

//Request the choice
do {
cout << "\nPlease enter your choice: ";
cin >> choice;
} while (choice != -1 && choice != 1 && choice != 2 && choice != 3 && choice != 4);

if(choice == -1) {
cout << "\nYou have decided to exit!\n\n";
exit(0);
}

//Reserve the room according to user's choice
switch(choice) {
case 1:
cout << "\nYou like to reserve a private meeting room.\n\n";
break;
case 2:
cout << "\nYou like to reserve a room for board meeting.\n\n";
break;
case 3:
cout << "\nYou like to reserve a big classroom.\n\n";
break;
case 4:
cout << "\nYou like to reserve a luxury banquet room.\n\n";
break;
default:
cout << "\nYou should not be here!\n\n";
}

return 0;
}
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.