Advertisement
tiffprag

Untitled

Dec 6th, 2019
420
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.33 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. void phoneBubbleSort(Restaurant* rts){
  111.      int i,j;
  112.      Customer current;  
  113.      for(i=0; i<rts->m_size;i++)      
  114.         for (j=0; j<rts->m_size-1; j++){                    
  115.             if(rts->customerArray[j].phone>rts->customerArray[j+1].phone){
  116.                 current = rts->customerArray[j];
  117.                 rts->customerArray[j] = rts->customerArray[j+1];
  118.                 rts->customerArray[j+1] = current;      
  119.             }          
  120.         }
  121. }
  122.  
  123. void nameBinarySearch(Restaurant* rts, string key){
  124.     int low = 0;
  125.     int high = rts->m_size-1;
  126.     int median;
  127.     while(low <= high){
  128.         median = (low+high)/2;
  129.  
  130.         if(key == rts->customerArray[median].name){
  131.             cout<<"*********************************************************\n" ;
  132.             cout << "num of pax:" << rts->customerArray[median].num<< "\n";
  133.             cout << "name:" << rts->customerArray[median].name << "\n";
  134.             cout << "phone number :" << rts->customerArray[median].phone << "\n";
  135.             cout << "Booking time:" << rts->customerArray[median].time << "\n";
  136.             cout << "Booking Date :" << rts->customerArray[median].date << "\n";
  137.             cout<<"*********************************************************\n";
  138.         return;
  139.         }else if(key < rts->customerArray[median].name){
  140.             high = median - 1;
  141.         }else{
  142.             low = median + 1;
  143.         }
  144.     }
  145.     cout<<"no data\n";
  146. }
  147.  
  148. void phoneBinarySearch(Restaurant* rts, string key){
  149.     int low = 0;
  150.     int high = rts->m_size-1;
  151.     int median;
  152.     while(low <= high){
  153.         median = (low+high)/2;
  154.  
  155.         if(key == rts->customerArray[median].phone){
  156.             cout<<"*********************************************************\n" ;
  157.             cout << "num of pax:" << rts->customerArray[median].num<< "\n";
  158.             cout << "name:" << rts->customerArray[median].name << "\n";
  159.             cout << "phone number :" << rts->customerArray[median].phone << "\n";
  160.             cout << "Booking time:" << rts->customerArray[median].time << "\n";
  161.             cout << "Booking Date :" << rts->customerArray[median].date << "\n";
  162.             cout<<"*********************************************************\n";
  163.         return;
  164.         }else if(key < rts->customerArray[median].phone){
  165.             high = median - 1;
  166.         }else{
  167.             low = median + 1;
  168.         }
  169.     }
  170.     cout<<"no data\n";
  171. }
  172.    
  173. int seachcustomer(Restaurant*rts){
  174.     int m_num;
  175.     string Date;
  176.     int ch=0;
  177.     cout<<"1.seach by num fo pax\n";
  178.     cout<<"2.sech by date\n";
  179.    
  180.     while(true){
  181.         cin>>ch;
  182.         if(ch==1){
  183.             int Num;
  184.             cout<<"enter number of pax\n";
  185.             cin>>Num;
  186.             Num=m_num+1;
  187.                 int ret = isEmty(rts, Num);
  188.                 if (ret!=-1){
  189.                     string Num, Name, Phone, Date, Time;
  190.  
  191.         cout << "num of pax:" << rts->customerArray[ret].num << "\t";
  192.         cout << "name:" << rts->customerArray[ret].name << "\t";
  193.         cout << "phone number :" << rts->customerArray[ret].phone << "\t";
  194.         cout << "Booking time:" << rts->customerArray[ret].time << "\t";
  195.         cout << "Booking Date :" << rts->customerArray[ret].date << "\t";
  196.         cout << "\n";
  197.    
  198.                 }
  199.                 else
  200.     {
  201.         cout << " no fine record\n";
  202.     }
  203.     cout << "\n";
  204.     system("pause");
  205.     system("cls");
  206.    
  207.         }
  208.         else if(ch==2){
  209.             string Date;
  210.             cout << "enter booking date you need seach";
  211.     cin >> Date;
  212.     int ret = isEmty(rts, Date);
  213.    
  214.         if (ret != -1)
  215.     {
  216.         string Num, Name, Phone, Date, Time;
  217.  
  218.         cout << "num of pax:" << rts->customerArray[ret].num<< "\t";
  219.         cout << "name:" << rts->customerArray[ret].name<< "\t";
  220.         cout << "phone number :" << rts->customerArray[ret].phone<< "\t";
  221.         cout << "Booking time:" << rts->customerArray[ret].time<< "\t";
  222.         cout << "Booking Date :" << rts->customerArray[ret].date<< "\t";
  223.         cout << "\n";
  224.    
  225.     }
  226.     else
  227.     {
  228.         cout << " no fine record\n";
  229.     }
  230.     cout << "\n";
  231.     system("pause");
  232.     system("cls");
  233.    
  234.         }else{
  235.             cout<<"Erro input\n";
  236.         }
  237.         return 0;
  238.             system("pause");
  239.             system("cls");
  240.     }
  241.     }
  242.    
  243.  
  244. void ShowAll(Restaurant*rts) {
  245.  
  246.     //if m_size=0 then emty else show all record
  247.     if (rts->m_size == 0) {
  248.         cout << "the recort is emty\n";
  249.     }
  250.     else
  251.     {
  252.         for ( int i = 0; i <rts->m_size; i++)
  253.         {   cout<<"*********************************************************\n" ;
  254.             cout << "num of pax:" << rts->customerArray[i].num<< "\n";
  255.             cout << "name:" << rts->customerArray[i].name << "\n";
  256.             cout << "phone number :" << rts->customerArray[i].phone << "\n";
  257.             cout << "Booking time:" << rts->customerArray[i].time << "\n";
  258.             cout << "Booking Date :" << rts->customerArray[i].date << "\n";
  259.             cout<<"*********************************************************\n";
  260.             system("pause");
  261.             system("cls");
  262.  
  263.         }
  264.     }
  265.  
  266. }
  267.  
  268. void ShowManu() {
  269.     cout << "1.add\n ";
  270.     cout << "2.show\n";
  271.     cout << "3.sort\n";
  272.     cout << "4.binary search\n";
  273.     cout << "5.recursive seach\n";
  274.     cout << "0.exit\n";
  275. }
  276.  
  277. int main() {
  278.  
  279.     Restaurant rts;
  280.  
  281.     rts.m_size = 0;
  282.  
  283.     int select = 0;
  284.     int select2 = 0;
  285.     string name;
  286.     string phone;
  287.     while (true)
  288.     {
  289.        
  290.         ShowManu();
  291.         cin >> select;
  292.         switch (select)
  293.         {
  294.         case 1://add
  295.             addCustomer(&rts);
  296.             break;
  297.         case 2://show
  298.             ShowAll(&rts);
  299.             break;
  300.         case 3:
  301.             cout << "1.sort by name\n ";
  302.             cout << "2.sort by date\n";
  303.             cout << "0.exit\n";
  304.             cin >> select2;
  305.             switch (select2)
  306.             {
  307.                 case 1://sort by name
  308.                     nameBubbleSort(&rts);
  309.                     break;
  310.                 case 2://sort by date
  311.                     dateBubbleSort(&rts);
  312.                     break;
  313.                 default:
  314.                     break;
  315.             }
  316.             break;
  317.         case 4:
  318.             cout << "1.search by name\n ";
  319.             cout << "2.search by phone\n";
  320.             cout << "0.exit\n";
  321.             cin >> select2;
  322.             switch (select2)
  323.             {
  324.                 case 1://search by name
  325.                     cin.ignore();
  326.                     cout<<"Give name: ";
  327.                     getline(cin, name);
  328.                     nameBubbleSort(&rts);
  329.                     nameBinarySearch(&rts, name);
  330.  
  331.                     break;
  332.                 case 2://search by phone
  333.                     cout<<"Give phone: ";
  334.                     cin>>phone;
  335.                     phoneBubbleSort(&rts);
  336.                     phoneBinarySearch(&rts, phone);
  337.                     break;
  338.                 default:
  339.                     break;
  340.             }
  341.             break;
  342.         case 5://seach
  343.         seachcustomer(&rts);
  344.            
  345.             break;
  346.         case 0://exit
  347.             cout << "welcome next time" << endl;
  348.             system("pause");
  349.             return 0;
  350.             break;
  351.         default:
  352.             break;
  353.         }
  354.  
  355.     }
  356. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement