Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.61 KB | None | 0 0
  1. #include <iostream>
  2. //string name,string date,int phoneno, int time, int numberofpeople
  3. //insert, update, delete, view the reservation records
  4. using namespace std;
  5. const int NAME = 50;
  6. const int Month = 20;
  7. class Restaurant{
  8.     struct ReserveNode{
  9.         char Name[NAME];
  10.         char MOfDate[Month];
  11.         int date;
  12.         int phoneno;
  13.         int time;
  14.         int numberofpeople;
  15.         ReserveNode* next;
  16.         ReservationNode(){
  17.             date = 0;
  18.             phoneno = 0;
  19.             numberofpeople = 0;
  20.         }  
  21.     };ReserveNode* head;
  22.     public:
  23.         restaurant(){
  24.             head = NULL;
  25.         }
  26.         void insert();
  27.         void update();
  28.         void deletereserve();
  29.         void displayReservation();
  30.         bool search(string name);
  31.                                
  32. };
  33. void Restaurant::insert(){ 
  34.     ReserveNode* newNode, *nodein;
  35.     newNode = new ReserveNode; 
  36.         cout << "Enter Customer name:";
  37.         cout << "Maximum 50 word."<< endl;
  38.         cin.ignore();
  39.         cin.getline(newNode->Name, NAME);      
  40.         cout << "Enter Month(Etc April):";
  41.         cin.ignore();
  42.         cin.getline(newNode->MOfDate, toupper(Month)); 
  43.     cout << "Please enter the date:";
  44.     cin >> newNode->date;
  45.     cout << "Please enter time: ";             
  46.     cin >> newNode->time;
  47.     cout << "Please enter Phone Number: ";
  48.     cin >> newNode->phoneno;
  49.     cout << "Please enter number of people: ";
  50.     cin >> newNode->numberofpeople;
  51.     if (!head)
  52.         head = newNode;
  53.     else
  54.     {
  55.         nodein = head;
  56.         while (nodein->next != NULL)
  57.             nodein = nodein->next;
  58.         nodein->next = newNode;
  59.     }
  60.     system("cls");
  61. }
  62.  
  63. void Restaurant::displayReservation()
  64. {
  65.     ReserveNode* nodein;
  66.     nodein = head;
  67.  
  68.     if (nodein != NULL)
  69.     {
  70.         cout << "------------------------------------------\n";
  71.         cout << "       Restaurant Reservation Info        \n";
  72.         cout << "------------------------------------------\n";
  73.         while (nodein)
  74.         {
  75.             cout << "Name: " << nodein->Name << endl;
  76.             cout << "Date: " << nodein->MOfDate << " "<< nodein->date << endl;
  77.             cout << "Time: " << nodein->time << endl;
  78.             cout << "Phone No: " << nodein->phoneno << endl;
  79.             cout << "Number of People: " << nodein->numberofpeople << endl;
  80.  
  81.             nodein = nodein->next;
  82.         }
  83.     }
  84.     else
  85.         cout << "Empty List. Please Enter Reservation Information..\n";
  86. }
  87. bool Restaurant::search(string name)
  88. {
  89.     ReserveNode *nodein;
  90.     nodein = head;
  91.     bool found;
  92.     found = false;
  93.    
  94.     while ((nodein != NULL) && (!found))
  95.     {
  96.             if (nodein->Name == name)
  97.               found = true;
  98.             else
  99.               nodein = nodein->next;
  100.     }
  101.         return found;
  102. }
  103.  
  104. int main()
  105. {
  106.     string name;
  107.     Restaurant list;
  108.     char decision;
  109.     char loop = 'y';
  110.     do
  111.     {
  112.         cout << "-------------------------------------------\n";
  113.         cout << "           RESERVATION SYSTEM           \n";
  114.         cout << "-------------------------------------------\n";
  115.         cout << "Press (1) to Enter customer information " << endl;
  116.         cout << "Press (2) to Display all customer information " << endl;
  117.         cout << "Press (3) to Search Customer " << endl;
  118.         cout << "Press (4) to Quit the program" << endl;
  119.         cin >> decision;
  120.         if (decision == 1){
  121.             list.insert();         
  122.         }
  123.         else if(decision == 2){
  124.             list.displayReservation();
  125.             cout << endl;
  126.         }
  127.  
  128.         else if (decision == 3){
  129.             cout << "Enter name of customer that you want to search: " << endl
  130.             << "Name: ";
  131.             cin.ignore(80, '\n');
  132.             getline(cin, name);  
  133.             if (list.search(name))
  134.                 cout << name << "is found.";
  135.             else
  136.                 cout << "Unknown. name not found";         
  137.         }
  138.  
  139.         else if ( decision == 4){
  140.             loop = 'n';
  141.             cout << "\nExiting the program..\n";           
  142.         }  
  143.  
  144.         else{
  145.             cout << "this is an invalid choice. Please select prompt from the menu.\n";
  146.             system("pause");           
  147.         }
  148.     } while ((loop == 'Y') || (loop == 'y'));
  149.  
  150.     return 0;
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement