Guest User

DailyProgram Airplane[][]

a guest
Jul 25th, 2012
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.05 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. void menu();
  7. void addBooking();
  8. void printArray();
  9.  
  10. char seatArray[13][4]  {{'*', '*', '*', '*'},
  11.                         {'*', '*', '*', '*'},
  12.                         {'*', '*', '*', '*'},
  13.                         {'*', '*', '*', '*'},
  14.                         {'*', '*', '*', '*'},
  15.                         {'*', '*', '*', '*'},
  16.                         {'*', '*', '*', '*'},
  17.                         {'*', '*', '*', '*'},
  18.                         {'*', '*', '*', '*'},
  19.                         {'*', '*', '*', '*'},
  20.                         {'*', '*', '*', '*'},
  21.                         {'*', '*', '*', '*'},
  22.                         {'*', '*', '*', '*'}
  23.                     };
  24.  
  25. char occupied = 'X';
  26. char available = '*';
  27.  
  28. void menu()
  29. {
  30.     int userDecision = 0;
  31.  
  32.     cout << endl;
  33.     cout << "Welcome to SpeakoN Airlines" << endl;
  34.  
  35.     cout << "[1] Create Booking\n[2] View Seats" << endl;
  36.  
  37.     cin >> userDecision;
  38.  
  39.     switch(userDecision)
  40.     {
  41.  
  42.     case 1:
  43.         addBooking();
  44.         break;
  45.  
  46.     case 2:
  47.         printArray();
  48.         menu();
  49.         break;
  50.     }
  51. }
  52.  
  53. void addBooking()
  54. {
  55.     int type, seat;
  56.  
  57.  
  58.     cout << "Ticket Type:\n[1]First Class\n[2]Business\n[3]Economy\n" << endl;
  59.     cin >> type;
  60.  
  61.     switch (type)
  62.     {
  63.  
  64.     case 1:
  65.  
  66.         cout << "You Chose: First Class\n" << endl;
  67.  
  68.         cout << "Ticket Type:\n[1]Seat 1\n[2]Seat 2\n[3]Seat 3\n[4]Seat 4\n" << endl;
  69.         cin >> seat;
  70.  
  71.         for(int rows = 0; rows < 2; rows++)
  72.         {
  73.  
  74.             if(seatArray[rows][seat - 1] != 'X')
  75.             {
  76.                 cout << "Row: " << rows + 1 << " | Seat " << seat << " is Available! Booking Confirmed For: ";
  77.                 seatArray[rows][seat - 1] = 'X';
  78.  
  79.                 cout << "Row: " << rows + 1 << " | Seat: " << seat << endl;
  80.  
  81.                 break;
  82.  
  83.             }
  84.             else if(seatArray[rows][seat - 1] == 'X' && rows <= 2)
  85.             {
  86.                 cout << "Row: " << rows + 1 << " | Seat: " << seat << " is Unavailable!" << endl;
  87.             }
  88.  
  89.         }
  90.         menu();
  91.         break;
  92.  
  93.     case 2:
  94.         cout << "You Chose: Business Class\n" << endl;
  95.  
  96.         cout << "Ticket Type:\n[1]Seat 1\n[2]Seat 2\n[3]Seat 3\n[4]Seat 4\n" << endl;
  97.         cin >> seat;
  98.  
  99.         for(int rows = 2; rows < 6; rows++)
  100.         {
  101.             if(seatArray[rows][seat - 1] != 'X')
  102.             {
  103.                 cout << "Row: " << rows + 1 << " | Seat " << seat << " is Available! Booking Confirmed For: ";
  104.                 seatArray[rows][seat - 1] = 'X';
  105.  
  106.                 cout << "Row: " << rows + 1 << " Seat: " << seat << endl;
  107.  
  108.                 break;
  109.             }
  110.             else if(seatArray[rows][seat - 1] == 'X' && rows <= 6)
  111.             {
  112.                 cout << "Row: " << rows + 1 << " | Seat: " << seat << " is Unavailable!" << endl;
  113.  
  114.             }
  115.  
  116.         }
  117.         menu();
  118.         break;
  119.  
  120.  
  121.     case 3:
  122.         cout << "You Chose: Economy Class\n" << endl;
  123.  
  124.         cout << "Ticket Type:\n[1]Seat 1\n[2]Seat 2\n[3]Seat 3\n[4]Seat 4\n" << endl;
  125.         cin >> seat;
  126.  
  127.         for(int rows = 6; rows < 13; rows++)
  128.         {
  129.             if(seatArray[rows][seat - 1] != 'X')
  130.             {
  131.  
  132.                 cout << "Row: " << rows + 1 << " | Seat " << seat << " is Available! Booking Confirmed For: ";
  133.                 seatArray[rows][seat - 1] = 'X';
  134.  
  135.                 cout << "Row: " << rows + 1 << " Seat: " << seat << endl;
  136.  
  137.                 break;
  138.             }
  139.             else if(seatArray[rows][seat - 1] == '*' && rows <= 13)
  140.             {
  141.                 cout << "Row: " << rows + 1 << " | Seat: " << seat << " is Unavailable!" << endl;
  142.             }
  143.  
  144.         }
  145.  
  146.         menu();
  147.         break;
  148.     }
  149. }
  150.  
  151. void printArray()
  152. {
  153.     cout << endl;
  154.  
  155.     for(int rows = 0; rows < 13; rows++)
  156.     {
  157.  
  158.         for(int cols = 0; cols < 4; cols++)
  159.         {
  160.  
  161.             cout << seatArray[rows][cols] << "\t";
  162.  
  163.         }
  164.         cout << endl;
  165.     }
  166.  
  167. }
  168.  
  169. int main()
  170. {
  171.     menu();
  172. }
Advertisement
Add Comment
Please, Sign In to add comment