Advertisement
neptunianCoder

Untitled

Apr 8th, 2020
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.56 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. char selection,marathon_type;
  6. const int full_marathon =10000, half_marathon =5000, seats =20, row =5, column =4;
  7. int seat_to_book, seat_to_vacate, gross_profit, seat_to_change;
  8.  
  9. void main_menu()
  10. {
  11.         //display menu
  12.     cout << "========================"<< endl;
  13.     cout << "    THEATRE BOOKING     "<< endl;
  14.     cout << "========================"<< endl;
  15.     cout << "1. View available seats"<< endl;
  16.     cout << "2. Book seat"<< endl;
  17.     cout << "3. Vacate seat"<< endl;
  18.     cout << "4. Change marathon type"<< endl;
  19.     cout << "5. Calculate gross profit"<< endl;
  20.     cout << "6. Quit program"<< endl;
  21. }
  22.  
  23. void print_seats()
  24. {
  25.     int seats [5][4] = {{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16},{17,18,19,20}};
  26.    
  27.         for (int row = 0; row < 5; row++)
  28.         {
  29.            for (int column=0; column<4; column++)
  30.             {
  31.             cout << seats[row][column] << " ";
  32.             }
  33.             cout << endl;
  34.         }
  35. }
  36.  
  37. void marathon_selection()
  38. {
  39.     //selects the marathon type
  40.     cout << "F - Full Marathon" << endl;
  41.     cout << "H - Half Marathon" << endl;
  42.     cin >> marathon_type;
  43.        
  44.     switch(toupper(marathon_type))
  45.     {
  46.         case 'F':
  47.         gross_profit += full_marathon;
  48.         cout << "=========================" << endl;
  49.         cout << "Seat Booking Confirmation" << endl;
  50.         cout << "=========================" << endl;
  51.         cout << "Seat No: " << seat_to_book << endl;
  52.         cout << "Marathon Type: Full Marathon" << endl;
  53.         cout << "Cost: Ksh " << full_marathon << endl;
  54.         break;
  55.        
  56.         case 'H':
  57.         gross_profit += half_marathon;
  58.         cout << "=========================" << endl;
  59.         cout << "Seat Booking Confirmation" << endl;
  60.         cout << "=========================" << endl;
  61.         cout << "Seat No: " << seat_to_book << endl;
  62.         cout << "Marathon Type: Half Marathon" << endl;
  63.         cout << "Cost: Ksh " << half_marathon << endl;
  64.         break;
  65.        
  66.     }
  67.     main_menu();
  68.     return;
  69. }
  70.  
  71.  void vacate_seats()
  72.  {
  73.      int seat_to_vacate;
  74.      int array[20];
  75.      cout << "Vacate seat number: ";
  76.      cin >> seat_to_vacate;
  77.      seat_to_vacate--;
  78.      for (int i = seat_to_vacate; i < seats; i++)
  79.      {
  80.          int temp = array[i];
  81.          array[i] = array[i+1];
  82.          array[i+1] = temp;
  83.      }
  84.      for (int i = 0; i < seats - 1; i ++)
  85.     {
  86.          cout << array[i]<< " ";
  87.      }
  88.  }
  89.  
  90. void book_seats()
  91. {
  92.     //booking seats
  93.     do
  94.     {
  95.         cout << "Enter the seat number to book: ";
  96.         cin >> seat_to_book;
  97.         while (seat_to_book >0 && seat_to_book <= 20)
  98.         {
  99.             cout << "Select the type of marathon you want: " << endl;
  100.             marathon_selection();
  101.             return;
  102.         }
  103.     }
  104.     while (true);
  105. }
  106.  
  107. void change_marathon_type()
  108. {
  109.     char marathon_to_change;
  110.     cout << "Enter the seat number you want to change the Marathon Type: ";
  111.     cin >> seat_to_change;
  112.     cout << "1. Full Marathon to Half Marathon" << endl;
  113.     cout << "2. Half Marathon to Full Marathon" << endl;
  114.     cin >> marathon_type;
  115.    
  116.     if (marathon_type == '1')
  117.     {
  118.         gross_profit-=half_marathon;
  119.         cout << "Successfully changed from Full Marathon to Half Marathon" << endl;
  120.         cout << "Price: " << half_marathon << endl;
  121.     }
  122.     else
  123.     {
  124.         gross_profit+=half_marathon;
  125.         cout << "Successfully changed from Half Marathon to Full Marathon:" << endl;
  126.         cout << "Price: " << endl;
  127.     }
  128.    
  129. }
  130.  
  131. int DisplayGrossProfit()
  132. {
  133.     if (gross_profit != 0)
  134.     {
  135.         cout << "The Gross Profit is Ksh: " << gross_profit << endl;
  136.     }
  137.     else
  138.     { cout << "You have not sold out any tickets. The Gross profit is Ksh: 0 " << endl;
  139.        
  140.     }
  141. }
  142.  
  143. int main ()
  144. {
  145.  
  146.   do
  147.     {
  148.         main_menu();
  149.         cin >> selection;
  150.      
  151.       switch (selection)
  152.       {
  153.           case '1':
  154.           print_seats();
  155.           break;
  156.          
  157.           case '2':
  158.           book_seats();
  159.           break;
  160.  
  161.           case '3':
  162.           vacate_seats();
  163.           break;
  164.          
  165.           case '4':
  166.           change_marathon_type();
  167.           break;
  168.          
  169.           case '5':
  170.           DisplayGrossProfit();
  171.           break;
  172.          
  173.           case '6':
  174.           return 0;
  175.          
  176.           default:
  177.           cout << "Please choose a valid Option!" << endl;
  178.       }
  179.     }
  180.   while (true);
  181.   cout << "Exitting. Thank You for using the Program" << endl;
  182.  
  183.   return 0;
  184. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement