Introduction

This homework aims to make you practice on object sharing via reference variables. In the homework, you are asked to write two classes Waiter and Table such that two waiter objects share table via reference variables. The main function of the program is already given to you. We will explain details about the homework in the following sections.

Using Object Sharing Principles and Object Oriented Design

As mentioned above, you have to have two Waiter and one Table objects in your program. The Table object must be shared by the Waiter objects. For this object sharing, you have to employ the method that uses reference variables.

From the above paragraph it should be clear that you will implement only two classes for Waiter and Table. You need to analyze the requirements carefully and make a good object-oriented design for these classes. In this context, you have to determine the data members and member functions of each class correctly. We will evaluate your object oriented design as well. Moreover, you are not allowed to use friend class or friend functions in your design.

Program Flow

At the beginning of the main function, which is provided with the homework specification, initial values of the Table object sharedTable are set to 4 for number of people in the table, 50 for initial bill, and 5 for the number of orders that has already been given by the people in the table. In the main.cpp, once the sharedTable object is created, the program asks for the name of the waiters. According to this information, two waiter objects, waiter1 and waiter2, are created such that they share the same table, sharedTable object. Then, a menu having 7 choices is displayed. As long as a new request is given by the people in the table, either waiter1 or waiter2 perform this request and the waiter who performs the request is chosen randomly. The appropriate lines in the main.cpp is commented for you to have a better understanding of the program flow .

The specifications of member functions of Waiter class are as follows:

Waiter (Table&, string): The constructor of Waiter class has two parameters: a Table object and a string object. The constructor should assign the Table object such that the Waiter object shares the table. It should also set the name of the waiter with the given parameter. Note that you should define appropriate data members for both the Table object to be shared and the name of the waiter in the Waiter class.

void addNewPersonToTable(int): This function should increase the number of person in the table by the given parameter which is entered by the user in the main.cpp. Note that you should design Table class such that it keeps track of the number of person in the table.

void removePersonFromTable(int, int): The function takes two parameters: number of person to be removed and the partial amount that they will pay before leaving from the total bill of the table. This function decreases the number of person in the table and the total bill of the table by the given parameters entered in the main.cpp. Note that number of person to be removed cannot exceed the number of person in the table. Also, the partial pay neither exceeds the total bill of the table nor be negative. These cases have already been handled in the main.cpp. From the given specifications of the function, you should be aware of that you should also keep track of the total bill of the table in the appropriate place.

void addOrderToTable(int): The functions takes the number of orders given from the table as parameters and increase the number of total orders of the table by the given parameter. A waiter taking the order gets 1TL tip for each order regardless of the number of orders given. Also, 10TL should be added to the total bill for each order. You should keep track of the tip that the waiters earn and the number of orders given to the table in the appropriate places.

void cancelOrder(int): The functions takes the number of orders that will be canceled from the table as parameters and decrease the number of total orders of the table by the given parameter. A waiter cancelling the order lose 1TL tip for each order regardless of the number of cancelled orders. Also, 10TL should be decreased from the total bill for each cancelled order.

void displayTip(): This functions displays the tip that the waiter earned together with the name of the waiter.

void getCheck(): This function sets all data members of the Table object to zero and displays a message Total bill is charged from the table.

The specifications of member functions of Table class are as follows:

int getNumberOfPerson(): This function returns the number of person in the table.

double getTotalBill(): This function returns the total bill of the Table object.

void displayTableInfo(): This function displays the number of person in the table, number of orders served to the table and the total bill in a appropriate format.

The abovementioned member functions of Table class are the ones called from main.cpp. You may need other (helper) member functions of Table class that are called by member functions of Waiter class. You should also consider such functions and write them appropriately.

Please note that you can assume all inputs are entered correctly, so you do not need any input check in your program. You can also assume that the budget of a driver and fuel level of the car reduces below zero. Therefore, you do not have to check such cases in your implementation as well.

Sample Runs

Sample Run 1

Please enter the name of the first waiter
Ahmet
Please enter the name of the second waiter
Ali

Please enter the request from the waiter
1 - Add new person to the table
2 - Remove person from the table
3 - Add order to the table
4 - Cancel order from the table
5 - Display tip of the waiters
6 - Display table details
7 - Request check

3
Enter the number of orders that will be added to the table
2

Please enter the request from the waiter
1 - Add new person to the table
2 - Remove person from the table
3 - Add order to the table
4 - Cancel order from the table
5 - Display tip of the waiters
6 - Display table details
7 - Request check

5
Tip of waiter Ahmet: 0
Tip of waiter Ali: 1

Please enter the request from the waiter
1 - Add new person to the table
2 - Remove person from the table
3 - Add order to the table
4 - Cancel order from the table
5 - Display tip of the waiters
6 - Display table details
7 - Request check

6
Number of person in the table: 4
Number of orders served to the table: 7
Total bill of the table: 70

Please enter the request from the waiter
1 - Add new person to the table
2 - Remove person from the table
3 - Add order to the table
4 - Cancel order from the table
5 - Display tip of the waiters
6 - Display table details
7 - Request check

3
Enter the number of orders that will be added to the table
1

Please enter the request from the waiter
1 - Add new person to the table
2 - Remove person from the table
3 - Add order to the table
4 - Cancel order from the table
5 - Display tip of the waiters
6 - Display table details
7 - Request check

3
Enter the number of orders that will be added to the table
2

Please enter the request from the waiter
1 - Add new person to the table
2 - Remove person from the table
3 - Add order to the table
4 - Cancel order from the table
5 - Display tip of the waiters
6 - Display table details
7 - Request check

5
Tip of waiter Ahmet: 1
Tip of waiter Ali: 2

Please enter the request from the waiter
1 - Add new person to the table
2 - Remove person from the table
3 - Add order to the table
4 - Cancel order from the table
5 - Display tip of the waiters
6 - Display table details
7 - Request check

6
Number of person in the table: 4
Number of orders served to the table: 10
Total bill of the table: 100

Please enter the request from the waiter
1 - Add new person to the table
2 - Remove person from the table
3 - Add order to the table
4 - Cancel order from the table
5 - Display tip of the waiters
6 - Display table details
7 - Request check

2
How many people will be removed from the table
2
The total bill of the table is 100
How much will be paid from the total bill?
30

Please enter the request from the waiter
1 - Add new person to the table
2 - Remove person from the table
3 - Add order to the table
4 - Cancel order from the table
5 - Display tip of the waiters
6 - Display table details
7 - Request check

5
Tip of waiter Ahmet: 1
Tip of waiter Ali: 2

Please enter the request from the waiter
1 - Add new person to the table
2 - Remove person from the table
3 - Add order to the table
4 - Cancel order from the table
5 - Display tip of the waiters
6 - Display table details
7 - Request check

6
Number of person in the table: 2
Number of orders served to the table: 10
Total bill of the table: 70

Please enter the request from the waiter
1 - Add new person to the table
2 - Remove person from the table
3 - Add order to the table
4 - Cancel order from the table
5 - Display tip of the waiters
6 - Display table details
7 - Request check

4
Enter the number of orders that will be canceled from the table
1

Please enter the request from the waiter
1 - Add new person to the table
2 - Remove person from the table
3 - Add order to the table
4 - Cancel order from the table
5 - Display tip of the waiters
6 - Display table details
7 - Request check

5
Tip of waiter Ahmet: 1
Tip of waiter Ali: 1

Please enter the request from the waiter
1 - Add new person to the table
2 - Remove person from the table
3 - Add order to the table
4 - Cancel order from the table
5 - Display tip of the waiters
6 - Display table details
7 - Request check

1
How many people will be added to the table
3

Please enter the request from the waiter
1 - Add new person to the table
2 - Remove person from the table
3 - Add order to the table
4 - Cancel order from the table
5 - Display tip of the waiters
6 - Display table details
7 - Request check

7
Total bill is charged from the table
Press any key to continue . . .
Academic Honesty!
It is not our intention to break the school's academic policy. Projects posted are only 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 fill out the form. Please provide a valid email address and we'll get back to you in less than 24 hours. We will be sending an invoice through PayPal upon confirmation. We are a non profit organization however we need an amount to keep this organization running, and to be able to complete our research and development.