Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please Provide the C++ Code for the below Your job is to create a reservation sy

ID: 3591694 • Letter: P

Question

Please Provide the C++ Code for the below

Your job is to create a reservation system for a restaurant. The restaurant has 20 tables. Here is the functionality required for this system (you may want to display a menu and let user choose options 1 to 4, make sure to put your program in a loop so program does not exit until user chooses menu 0):

1- Reserve a Table
   User needs to input the table number (Tables are numbered from 0 to 19). If the table is not available (reserved), inform the user that the selected table is not available. If the table is available, then ask for the name (name is a single word, no space) and mark the table as reserved.
  
2- Clear Reservation
   User needs to input the table number (Tables are numbered from 0 to 19). If the table is not reserved, inform the user that the selected table is already available (nothing to clear). If the table is reserved, mark it as available. That table is no longer reserved.

3- Report
   Prints out the state of each table. Each table is printed on a separate line -- so your report will print out 20 rows. If reserved, it will print out the name on the reservation next to the table number. If available, it should print out "available".
  
0- Exit Program.

I would recommend either:

a) keeping two arrays (parallel arrays!), both are size 20, one of type boolean (true/false -- reserved/available) and the other one of type string (name on reservation if reserved, blank otherwise).

b) keeping a single array of size 20 of type string. At the beginning of the program, set all the tables to "AVAILABLE". As tables get reserved, set the table array item as the name on the reservation . If the value on a table is "AVAILABLE" then the table is available (not reserved) otherwise, the table is reserved and the value is the name on the reservation.

Explanation / Answer

Hello,

This program follows your recommendation(b)

#include<iostream>
#include<string>
using namespace std;

int main()
{
   string table[20],customer_name;
   char choice, loop;
   int table_num;
   for(int i = 0; i < 20; i++)
   {
       table[i] = "AVAILABLE";
   }
   do
   {
       cout << " " << "USER MENU";
       cout << " " << "1 - Reserve a Table";
       cout << " " << "2 - Clear Reservation";
       cout << " " << "3 - Report - Display the status of tables(AVAILABLE/RESERVED)";
       cout << " " << "0 - Exit Program.";
       cout << " " << "Please enter your choice: ";
       cin >> choice ;
       switch(choice)
       {
           case '1':
               cout << " Please enter the table number to reserve: ";
               cin >> table_num ;
               if( (table_num >= 0) && (table_num <= 19) )
               {
                   if(table[table_num].compare("AVAILABLE") == 0)
                   {
                       cout << " Please enter your name to reserve: ";
                       cin >>customer_name;
                       table[table_num] = customer_name;
                   }
                   else
                   {
                           cout << " The table you choose is not available,please choose another table";
                   }
               }
               else
               {
                   cout << " Please enter the table number within a range from 0 to 19";
               }
               break;
           case '2':
               cout << " Please enter the table number to clear the reservation";
               cin >> table_num;
               if( (table_num >= 0) && (table_num <= 19) )
               {
                   if(table[table_num].compare("AVAILABLE") == 0)
                   {
                       cout << " This table is already available(nothing to clear)";
                   }
                   else
                   {
                           table[table_num] = "AVAILABLE";
                           cout << " The Table is successfully cleared, now it is available to reserve.";
                   }
               }
               else
               {
                   cout << " Please enter the table number within a range from 0 to 19";
               }
               break;
           case '3':
               for(int i = 0; i < 20; i++)
               {
                   string temp = "AVAILABLE";
                   if(temp.compare(table[i]) == 0)
                   {
                       cout << " " << "Table" << i << " - AVAILABLE";
                   }
                   else
                   {
                       cout << " " << "Table" << i << " - " << table[i] << "[RESERVED]" ;
                   }
               }
               break;
           case '0':
               exit(0);
               break;
           default:
               printf(" Please enter the valid choice");
       }
       printf(" Do you want to continue(y/n)");
       cin >> loop;
   }while(loop == 'y');
   return 0;
}