Advertisement
Guest User

Untitled

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