In: Computer Science
DESIGN IN RAPTOR PROGRAMMING APP Le Chef Heureux Restaurant has 20 tables that can be reserved at 5 p.m., 7 p.m., or 9 p.m. Design a program that accepts reservations for specific tables at specific times; the user enters the number of customers, the table number, and the time. Do not allow more than four guests per table or invalid table numbers or times. If an attempt is made to reserve a table already taken, reprompt the user. Continue to accept reservations until the user enters a sentinel value or all slots are filled. Then display all empty tables in each time slot.
#include<iostream>
using namespace std;
struct table{
int time[3];
int num;
};
void reserve(table T[], int b,int a, int n){
if (n > 4){
cout << "Error: Number of
guests exceeding four\n";
return;
}
if (T[b-1].time[a] == 0){
T[b-1].time[a] = 1;
cout << "Table is
reserved\n";
return;
}
cout << "Sorry! Table is already
reserved\n";
}
int main(){
table Table[20];
int b,g,n;
int t;
for (int i = 0; i<20; i++)
for (int j=0; j<3;
j++)
Table[i].time[j] = 0;
cout << "Welcome to Le Chef Heureux
Reservation System\n";
while(true){
int found =
0;
for (int i = 0;
i<20; i++)
for (int j=0; j<3; j++)
if (Table[i].time[j] == 0)
found = 1;
if (found ==
0){
cout << "Reservation is Full\n";
break;
}
cout <<
"1.Reserve a table\n";
cout <<
"2.Quit\n";
cout <<
"Enter choice:";
cin >>
n;
if (n == 1){
while(true){
cout << "Enter table number(1-20):";
cin >> b;
if (b < 1 || b > 20)
cout << "Error:Invalid input\n";
else
break;
}
while(true){
cout << "Enter time(0-5pm,1-7pm,2-9pm):";
cin >> t;
if (t <0 || t >2)
cout << "Error:Invalid input\n";
else
break;
}
while(true){
cout << "Enter number of guests(>=4):";
cin >> g;
if (g <=0 || g > 4)
cout << "Error:Invalid input\n";
else
break;
}
reserve(Table,b,t,g);
}
if (n == 2)
break;
}
}