tiffprag

Untitled

Dec 6th, 2019
505
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 12.56 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. void dateRecursion (Restaurant* rts, string date, int high){
  174.     if (high < 0){
  175.       return;
  176.     }
  177.     else if (date == rts->customerArray[high].date){
  178.         cout<<"*********************************************************\n" ;
  179.         cout << "num of pax:" << rts->customerArray[high].num<< "\n";
  180.         cout << "name:" << rts->customerArray[high].name << "\n";
  181.         cout << "phone number :" << rts->customerArray[high].phone << "\n";
  182.         cout << "Booking time:" << rts->customerArray[high].time << "\n";
  183.         cout << "Booking Date :" << rts->customerArray[high].date << "\n";
  184.         cout<<"*********************************************************\n";
  185.       return dateRecursion(rts, date, high-1);
  186.     }
  187.     else {
  188.       return dateRecursion(rts, date, high-1);
  189.     }
  190. }
  191.  
  192. void numRecursion (Restaurant* rts, int num, int high){
  193.     if(high < 0){
  194.       return;
  195.     }
  196.     else if (num <= rts->customerArray[high].num){
  197.         cout<<"*********************************************************\n" ;
  198.         cout << "num of pax:" << rts->customerArray[high].num<< "\n";
  199.         cout << "name:" << rts->customerArray[high].name << "\n";
  200.         cout << "phone number :" << rts->customerArray[high].phone << "\n";
  201.         cout << "Booking time:" << rts->customerArray[high].time << "\n";
  202.         cout << "Booking Date :" << rts->customerArray[high].date << "\n";
  203.         cout<<"*********************************************************\n";
  204.       return numRecursion(rts, num, high-1);
  205.     }
  206.     else {
  207.       return numRecursion(rts, num, high-1);
  208.     }
  209. }
  210.    
  211. int seachcustomer(Restaurant*rts){
  212.     int m_num;
  213.     string Date;
  214.     int ch=0;
  215.     cout<<"1.seach by num fo pax\n";
  216.     cout<<"2.sech by date\n";
  217.    
  218.     while(true){
  219.         cin>>ch;
  220.         if(ch==1){
  221.             int Num;
  222.             cout<<"enter number of pax\n";
  223.             cin>>Num;
  224.             Num=m_num+1;
  225.                 int ret = isEmty(rts, Num);
  226.                 if (ret!=-1){
  227.                     string Num, Name, Phone, Date, Time;
  228.  
  229.         cout << "num of pax:" << rts->customerArray[ret].num << "\t";
  230.         cout << "name:" << rts->customerArray[ret].name << "\t";
  231.         cout << "phone number :" << rts->customerArray[ret].phone << "\t";
  232.         cout << "Booking time:" << rts->customerArray[ret].time << "\t";
  233.         cout << "Booking Date :" << rts->customerArray[ret].date << "\t";
  234.         cout << "\n";
  235.    
  236.                 }
  237.                 else
  238.     {
  239.         cout << " no fine record\n";
  240.     }
  241.     cout << "\n";
  242.     system("pause");
  243.     system("cls");
  244.    
  245.         }
  246.         else if(ch==2){
  247.             string Date;
  248.             cout << "enter booking date you need seach";
  249.     cin >> Date;
  250.     int ret = isEmty(rts, Date);
  251.    
  252.         if (ret != -1)
  253.     {
  254.         string Num, Name, Phone, Date, Time;
  255.  
  256.         cout << "num of pax:" << rts->customerArray[ret].num<< "\t";
  257.         cout << "name:" << rts->customerArray[ret].name<< "\t";
  258.         cout << "phone number :" << rts->customerArray[ret].phone<< "\t";
  259.         cout << "Booking time:" << rts->customerArray[ret].time<< "\t";
  260.         cout << "Booking Date :" << rts->customerArray[ret].date<< "\t";
  261.         cout << "\n";
  262.    
  263.     }
  264.     else
  265.     {
  266.         cout << " no fine record\n";
  267.     }
  268.     cout << "\n";
  269.     system("pause");
  270.     system("cls");
  271.    
  272.         }else{
  273.             cout<<"Erro input\n";
  274.         }
  275.         return 0;
  276.             system("pause");
  277.             system("cls");
  278.     }
  279.     }
  280.    
  281.  
  282. void ShowAll(Restaurant*rts) {
  283.  
  284.     //if m_size=0 then emty else show all record
  285.     if (rts->m_size == 0) {
  286.         cout << "the recort is emty\n";
  287.     }
  288.     else
  289.     {
  290.         for ( int i = 0; i <rts->m_size; i++)
  291.         {   cout<<"*********************************************************\n" ;
  292.             cout << "num of pax:" << rts->customerArray[i].num<< "\n";
  293.             cout << "name:" << rts->customerArray[i].name << "\n";
  294.             cout << "phone number :" << rts->customerArray[i].phone << "\n";
  295.             cout << "Booking time:" << rts->customerArray[i].time << "\n";
  296.             cout << "Booking Date :" << rts->customerArray[i].date << "\n";
  297.             cout<<"*********************************************************\n";
  298.             system("pause");
  299.             system("cls");
  300.  
  301.         }
  302.     }
  303.  
  304. }
  305.  
  306. void ShowManu() {
  307.     cout << "1.add\n ";
  308.     cout << "2.show\n";
  309.     cout << "3.sort\n";
  310.     cout << "4.binary search\n";
  311.     cout << "5.recursive seach\n";
  312.     cout << "0.exit\n";
  313. }
  314.  
  315. int main() {
  316.  
  317.     Restaurant rts;
  318.  
  319.     rts.m_size = 0;
  320.  
  321.     int select = 0;
  322.     int select2 = 0;
  323.     int num;
  324.     string name;
  325.     string phone;
  326.     string date;
  327.     while (true)
  328.     {
  329.        
  330.         ShowManu();
  331.         cin >> select;
  332.         switch (select)
  333.         {
  334.         case 1://add
  335.             addCustomer(&rts);
  336.             break;
  337.         case 2://show
  338.             ShowAll(&rts);
  339.             break;
  340.         case 3:
  341.             cout << "1.sort by name\n ";
  342.             cout << "2.sort by date\n";
  343.             cout << "0.exit\n";
  344.             cin >> select2;
  345.             switch (select2)
  346.             {
  347.                 case 1://sort by name
  348.                     nameBubbleSort(&rts);
  349.                     break;
  350.                 case 2://sort by date
  351.                     dateBubbleSort(&rts);
  352.                     break;
  353.                 default:
  354.                     break;
  355.             }
  356.             break;
  357.         case 4:
  358.             cout << "1.search by name\n ";
  359.             cout << "2.search by phone\n";
  360.             cout << "0.exit\n";
  361.             cin >> select2;
  362.             switch (select2)
  363.             {
  364.                 case 1://search by name
  365.                     cin.ignore();
  366.                     cout<<"Give name: ";
  367.                     getline(cin, name);
  368.                     nameBubbleSort(&rts);
  369.                     nameBinarySearch(&rts, name);
  370.  
  371.                     break;
  372.                 case 2://search by phone
  373.                     cout<<"Give phone: ";
  374.                     cin>>phone;
  375.                     phoneBubbleSort(&rts);
  376.                     phoneBinarySearch(&rts, phone);
  377.                     break;
  378.                 default:
  379.                     break;
  380.             }
  381.             break;
  382.         case 5://seach
  383.             cout << "1.given date\n ";
  384.             cout << "2.given pax\n";
  385.             cout << "0.exit\n";
  386.             cin >> select2;
  387.             switch (select2)
  388.             {
  389.                 case 1://given date
  390.                     cin.ignore();
  391.                     cout<<"Give date: ";
  392.                     cin>>date;
  393.                     dateRecursion(&rts, date, rts.m_size-1);
  394.  
  395.                     break;
  396.                 case 2://given pax
  397.                     cout<<"Give pax: ";
  398.                     cin>>num;
  399.                     numRecursion(&rts, num, rts.m_size-1);
  400.  
  401.                     break;
  402.                 default:
  403.                     break;
  404.             }
  405.             break;
  406.         case 0://exit
  407.             cout << "welcome next time" << endl;
  408.             system("pause");
  409.             return 0;
  410.             break;
  411.         default:
  412.             break;
  413.         }
  414.  
  415.     }
  416. }
Advertisement
Add Comment
Please, Sign In to add comment