Advertisement
tiffprag

Untitled

Dec 6th, 2019
435
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.02 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. #define MAX 1000
  4. using namespace std;
  5.  
  6. //struct of customer
  7. struct Customer
  8. {
  9.     //num of pax
  10.     int num;
  11.     //customer name
  12.     string name;
  13.     // phone number
  14.     string phone;
  15.     //booking date
  16.     string date;
  17.     //booking time
  18.     string time;
  19. };
  20. //struct of restoren
  21. struct Restaurant
  22. {
  23.     //Array of customers stored in the restaurant
  24.     struct Customer customerArray[MAX];
  25.     //The restaurant currently records the number of customers
  26.     int m_size;
  27. };
  28.  
  29. int isEmty(Restaurant* rts, string Date) {
  30.     for (int i = 0; i < rts->m_size; i++)
  31.     {      
  32.         if (rts->customerArray[i].date==Date)
  33.         {
  34.             return i;
  35.         }
  36.     }
  37.     return -1;
  38. }
  39. int isEmty(Restaurant* rts, int Num) {
  40.     for (int i = 0; i < rts->m_size; i++)
  41.     {      
  42.         if (rts->customerArray[i].num==Num)
  43.         {
  44.             return i;
  45.         }
  46.     }
  47.     return -1;
  48. }
  49. void addCustomer(Restaurant*rts) {
  50.     if (rts->m_size == MAX) {
  51.         cout << "it is full, cannot at\n ";
  52.         return;
  53.     }
  54.     else {//add the data
  55.        
  56.             int Num;
  57.             cout << "enter num of pax:\n";
  58.             cin >> Num;
  59.             rts->customerArray[rts->m_size].num = Num;
  60.             string Name;
  61.             cout << "enter customer name;\n";
  62.             cin >> Name;
  63.             rts->customerArray[rts->m_size].name = Name;
  64.             string Phone;
  65.             cout << "Enter phone Number:\n";
  66.             cin >> Phone;
  67.             rts->customerArray[rts->m_size].phone = Phone;
  68.             string Date;
  69.             cout << "Enter Booking Date:\n";
  70.             cin >> Date;
  71.             rts->customerArray[rts->m_size].date = Date;
  72.             string Time;
  73.             cout << "Enter Booking Time:\n";
  74.             cin >> Time;
  75.             rts->customerArray[rts->m_size].time = Time;
  76.             rts->m_size++;//uodate the quantiti of m_size
  77.             cout << "add finish\n";
  78.             system("pause");
  79.                 system("cls");
  80.                
  81.             }
  82. }
  83.  
  84. void nameBubbleSort(Restaurant* rts){
  85.      int i,j;
  86.      Customer current;
  87.      for(i=0; i<rts->m_size;i++)      
  88.         for (j=0; j<rts->m_size-1; j++){                    
  89.             if(rts->customerArray[j].name>rts->customerArray[j+1].name){
  90.                 current = rts->customerArray[j];
  91.                 rts->customerArray[j] = rts->customerArray[j+1];
  92.                 rts->customerArray[j+1] = current;      
  93.             }          
  94.         }
  95. }
  96.  
  97. void dateBubbleSort(Restaurant* rts){
  98.      int i,j;
  99.      Customer current;  
  100.      for(i=0; i<rts->m_size;i++)      
  101.         for (j=0; j<rts->m_size-1; j++){                    
  102.             if(rts->customerArray[j].date>rts->customerArray[j+1].date){
  103.                 current = rts->customerArray[j];
  104.                 rts->customerArray[j] = rts->customerArray[j+1];
  105.                 rts->customerArray[j+1] = current;      
  106.             }          
  107.         }
  108. }
  109.    
  110. int seachcustomer(Restaurant*rts){
  111.     int m_num;
  112.     string Date;
  113.     int ch=0;
  114.     cout<<"1.seach by num fo pax\n";
  115.     cout<<"2.sech by date\n";
  116.    
  117.     while(true){
  118.         cin>>ch;
  119.         if(ch==1){
  120.             int Num;
  121.             cout<<"enter number of pax\n";
  122.             cin>>Num;
  123.             Num=m_num+1;
  124.                 int ret = isEmty(rts, Num);
  125.                 if (ret!=-1){
  126.                     string Num, Name, Phone, Date, Time;
  127.  
  128.         cout << "num of pax:" << rts->customerArray[ret].num << "\t";
  129.         cout << "name:" << rts->customerArray[ret].name << "\t";
  130.         cout << "phone number :" << rts->customerArray[ret].phone << "\t";
  131.         cout << "Booking time:" << rts->customerArray[ret].time << "\t";
  132.         cout << "Booking Date :" << rts->customerArray[ret].date << "\t";
  133.         cout << "\n";
  134.    
  135.                 }
  136.                 else
  137.     {
  138.         cout << " no fine record\n";
  139.     }
  140.     cout << "\n";
  141.     system("pause");
  142.     system("cls");
  143.    
  144.         }
  145.         else if(ch==2){
  146.             string Date;
  147.             cout << "enter booking date you need seach";
  148.     cin >> Date;
  149.     int ret = isEmty(rts, Date);
  150.    
  151.         if (ret != -1)
  152.     {
  153.         string Num, Name, Phone, Date, Time;
  154.  
  155.         cout << "num of pax:" << rts->customerArray[ret].num<< "\t";
  156.         cout << "name:" << rts->customerArray[ret].name<< "\t";
  157.         cout << "phone number :" << rts->customerArray[ret].phone<< "\t";
  158.         cout << "Booking time:" << rts->customerArray[ret].time<< "\t";
  159.         cout << "Booking Date :" << rts->customerArray[ret].date<< "\t";
  160.         cout << "\n";
  161.    
  162.     }
  163.     else
  164.     {
  165.         cout << " no fine record\n";
  166.     }
  167.     cout << "\n";
  168.     system("pause");
  169.     system("cls");
  170.    
  171.         }else{
  172.             cout<<"Erro input\n";
  173.         }
  174.         return 0;
  175.             system("pause");
  176.             system("cls");
  177.     }
  178.     }
  179.    
  180.  
  181. void ShowAll(Restaurant*rts) {
  182.  
  183.     //if m_size=0 then emty else show all record
  184.     if (rts->m_size == 0) {
  185.         cout << "the recort is emty\n";
  186.     }
  187.     else
  188.     {
  189.         for ( int i = 0; i <rts->m_size; i++)
  190.         {   cout<<"*********************************************************\n" ;
  191.             cout << "num of pax:" << rts->customerArray[i].num<< "\n";
  192.             cout << "name:" << rts->customerArray[i].name << "\n";
  193.             cout << "phone number :" << rts->customerArray[i].phone << "\n";
  194.             cout << "Booking time:" << rts->customerArray[i].time << "\n";
  195.             cout << "Booking Date :" << rts->customerArray[i].date << "\n";
  196.             cout<<"*********************************************************\n";
  197.             system("pause");
  198.             system("cls");
  199.  
  200.         }
  201.     }
  202.  
  203. }
  204.  
  205. void ShowManu() {
  206.     cout << "1.add\n ";
  207.     cout << "2.show\n";
  208.     cout << "3.sort\n";
  209.     cout << "4.seach\n";
  210.     cout << "0.exit\n";
  211. }
  212.  
  213. int main() {
  214.  
  215.     Restaurant rts;
  216.  
  217.     rts.m_size = 0;
  218.  
  219.     int select = 0;
  220.     int selectSort = 0;
  221.     while (true)
  222.     {
  223.        
  224.         ShowManu();
  225.         cin >> select;
  226.         switch (select)
  227.         {
  228.         case 1://add
  229.             addCustomer(&rts);
  230.             break;
  231.         case 2://show
  232.             ShowAll(&rts);
  233.             break;
  234.         case 3:
  235.             cout << "1.sort by name\n ";
  236.             cout << "2.sort by date\n";
  237.             cout << "0.exit\n";
  238.             cin >> selectSort;
  239.             switch (selectSort)
  240.             {
  241.                 case 1://add
  242.                     nameBubbleSort(&rts);
  243.                     break;
  244.                 case 2://show
  245.                     dateBubbleSort(&rts);
  246.                     break;
  247.                 default:
  248.                     break;
  249.             }
  250.             break;
  251.         case 4://seach
  252.         seachcustomer(&rts);
  253.            
  254.             break;
  255.         case 0://exit
  256.             cout << "welcome next time" << endl;
  257.             system("pause");
  258.             return 0;
  259.             break;
  260.         default:
  261.             break;
  262.         }
  263.  
  264.     }
  265. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement