fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5.  
  6. /*******************************************************************************
  7.  * This program takes as input a ticket type of first class, business class, or
  8.  * economy class, and a desired seat number and letter.
  9.  ******************************************************************************/
  10.  
  11.  
  12.  
  13. int main() {
  14. // Inputs
  15. char ticket; // Ticket type (f, b, or e)
  16. char seats[13][6]; // Array of seats (* or X)
  17. int row = 0;
  18. char seatLetter = 'a';
  19. int seatColumn = 0;
  20.  
  21. // Initialize seats array with asterisks
  22. for (int i = 0; i < 13; i++) {
  23. for (int j = 0; j < 6; j++) {
  24. seats[i][j] = '*';
  25. }
  26. }
  27.  
  28. // Start of Loop
  29. while (true) {
  30.  
  31. // Ticket type menu
  32. cout << "Select ticket type [first, business, economy class, "
  33. << "or 'done' to exit]: ";
  34. cin >> ticket;
  35.  
  36. // Prevent Invalid types of ticket
  37. while (ticket != 'f' && ticket != 'b' && ticket != 'e' && ticket != 'd') {
  38. cout << "Invalid ticket type" << endl;
  39. cout << "Select ticket type [first, business, economy class, "
  40. << "or 'done' to exit]: ";
  41. cin >> ticket;
  42. }
  43. // cin.ignore();
  44.  
  45. // Switch for ticket type
  46. switch(ticket) {
  47. case 'f':
  48. cout << "First class" << endl << endl;
  49.  
  50. do {
  51. cout << "Select row [1 or 2]: ";
  52. cin >> row;
  53. cout << row << endl;
  54. } while (row != 1 && row != 2);
  55. row--;
  56. break;
  57.  
  58. case 'b':
  59. cout << "Business class" << endl << endl;
  60.  
  61. do {
  62. cout << "Select row [3 to 7]: ";
  63. cin >> row;
  64. cout << row << endl;
  65. } while (row < 3 || row > 7);
  66. row--;
  67. break;
  68.  
  69. case 'e':
  70. cout << "Economy class" << endl << endl;
  71.  
  72. do {
  73. cout << "Select row [8 to 13]: ";
  74. cin >> row;
  75. cout << row << endl;
  76. } while (row < 8 || row > 13);
  77. row--;
  78. break;
  79.  
  80. case 'd': // Done
  81. cout << "Done" << endl;
  82. cout << "Exiting program" << endl;
  83. return 0;
  84. }
  85.  
  86.  
  87.  
  88. do {
  89. cout << "Select seat [A-F]: ";
  90. cin >> seatLetter;
  91. cout << seatLetter << endl;
  92. } while (seatLetter != 'a' && seatLetter != 'b' && seatLetter != 'c'
  93. && seatLetter != 'd' && seatLetter != 'e' && seatLetter != 'f');
  94.  
  95. switch(seatLetter) {
  96. case 'a':
  97. seatColumn = 0;
  98. break;
  99. case 'b':
  100. seatColumn = 1;
  101. break;
  102. case 'c':
  103. seatColumn = 2;
  104. break;
  105. case 'd':
  106. seatColumn = 3;
  107. break;
  108. case 'e':
  109. seatColumn = 4;
  110. break;
  111. case 'f':
  112. seatColumn = 5;
  113. break;
  114. }
  115.  
  116. if (seats[row][seatColumn] == 'X') {
  117. cout << "Seat already chosen" << endl;
  118. continue;
  119. }
  120. seats[row][seatColumn] = 'X';
  121.  
  122. // DISPLAY SEATING PLAN
  123. cout << '\n';
  124. cout << right << setw(10) << 'A' << setw(5) << 'B' << setw(5) << 'C'
  125. << setw(5) << 'D' << setw(5) << 'E' << setw(5) << 'F' << endl;
  126. for (int i = 0; i < 13; i++) {
  127. cout << left << "Row " << setw(5) << i + 1;
  128. for (int j = 0; j < 6; j++) {
  129. cout << seats[i][j] << " ";
  130. }
  131. cout << endl;
  132. }
  133. }
  134. // End of Loop
  135.  
  136. return 0;
  137. }
  138.  
  139. /*
  140. for (int i = 0; i < 13; i++) {
  141. cout << "Row " << left << setw(5) << i + 1;
  142. for (int j = 0; j < 6; j++) {
  143. cout << seats[i][j] << " ";
  144. }
  145. cout << endl;
  146. }
  147.  
  148. */
Success #stdin #stdout 0s 5280KB
stdin
f
1
a
f
2
d
b
1
5
b
b
8
7
f
e
13
f
e
1
8
a
e
9
c
e
9
c
e
12
a
d
stdout
Select ticket type [first, business, economy class, or 'done' to exit]: First class

Select row [1 or 2]: 1
Select seat [A-F]:   a

         A    B    C    D    E    F
Row 1    X    *    *    *    *    *    
Row 2    *    *    *    *    *    *    
Row 3    *    *    *    *    *    *    
Row 4    *    *    *    *    *    *    
Row 5    *    *    *    *    *    *    
Row 6    *    *    *    *    *    *    
Row 7    *    *    *    *    *    *    
Row 8    *    *    *    *    *    *    
Row 9    *    *    *    *    *    *    
Row 10   *    *    *    *    *    *    
Row 11   *    *    *    *    *    *    
Row 12   *    *    *    *    *    *    
Row 13   *    *    *    *    *    *    
Select ticket type [first, business, economy class, or 'done' to exit]: First class

Select row [1 or 2]: 2
Select seat [A-F]:   d

         A    B    C    D    E    F
Row 1    X    *    *    *    *    *    
Row 2    *    *    *    X    *    *    
Row 3    *    *    *    *    *    *    
Row 4    *    *    *    *    *    *    
Row 5    *    *    *    *    *    *    
Row 6    *    *    *    *    *    *    
Row 7    *    *    *    *    *    *    
Row 8    *    *    *    *    *    *    
Row 9    *    *    *    *    *    *    
Row 10   *    *    *    *    *    *    
Row 11   *    *    *    *    *    *    
Row 12   *    *    *    *    *    *    
Row 13   *    *    *    *    *    *    
Select ticket type [first, business, economy class, or 'done' to exit]: Business class

Select row [3 to 7]: 1
Select row [3 to 7]: 5
Select seat [A-F]:   b

         A    B    C    D    E    F
Row 1    X    *    *    *    *    *    
Row 2    *    *    *    X    *    *    
Row 3    *    *    *    *    *    *    
Row 4    *    *    *    *    *    *    
Row 5    *    X    *    *    *    *    
Row 6    *    *    *    *    *    *    
Row 7    *    *    *    *    *    *    
Row 8    *    *    *    *    *    *    
Row 9    *    *    *    *    *    *    
Row 10   *    *    *    *    *    *    
Row 11   *    *    *    *    *    *    
Row 12   *    *    *    *    *    *    
Row 13   *    *    *    *    *    *    
Select ticket type [first, business, economy class, or 'done' to exit]: Business class

Select row [3 to 7]: 8
Select row [3 to 7]: 7
Select seat [A-F]:   f

         A    B    C    D    E    F
Row 1    X    *    *    *    *    *    
Row 2    *    *    *    X    *    *    
Row 3    *    *    *    *    *    *    
Row 4    *    *    *    *    *    *    
Row 5    *    X    *    *    *    *    
Row 6    *    *    *    *    *    *    
Row 7    *    *    *    *    *    X    
Row 8    *    *    *    *    *    *    
Row 9    *    *    *    *    *    *    
Row 10   *    *    *    *    *    *    
Row 11   *    *    *    *    *    *    
Row 12   *    *    *    *    *    *    
Row 13   *    *    *    *    *    *    
Select ticket type [first, business, economy class, or 'done' to exit]: Economy class

Select row [8 to 13]: 13
Select seat [A-F]:   f

         A    B    C    D    E    F
Row 1    X    *    *    *    *    *    
Row 2    *    *    *    X    *    *    
Row 3    *    *    *    *    *    *    
Row 4    *    *    *    *    *    *    
Row 5    *    X    *    *    *    *    
Row 6    *    *    *    *    *    *    
Row 7    *    *    *    *    *    X    
Row 8    *    *    *    *    *    *    
Row 9    *    *    *    *    *    *    
Row 10   *    *    *    *    *    *    
Row 11   *    *    *    *    *    *    
Row 12   *    *    *    *    *    *    
Row 13   *    *    *    *    *    X    
Select ticket type [first, business, economy class, or 'done' to exit]: Economy class

Select row [8 to 13]: 1
Select row [8 to 13]: 8
Select seat [A-F]:   a

         A    B    C    D    E    F
Row 1    X    *    *    *    *    *    
Row 2    *    *    *    X    *    *    
Row 3    *    *    *    *    *    *    
Row 4    *    *    *    *    *    *    
Row 5    *    X    *    *    *    *    
Row 6    *    *    *    *    *    *    
Row 7    *    *    *    *    *    X    
Row 8    X    *    *    *    *    *    
Row 9    *    *    *    *    *    *    
Row 10   *    *    *    *    *    *    
Row 11   *    *    *    *    *    *    
Row 12   *    *    *    *    *    *    
Row 13   *    *    *    *    *    X    
Select ticket type [first, business, economy class, or 'done' to exit]: Economy class

Select row [8 to 13]: 9
Select seat [A-F]:   c

         A    B    C    D    E    F
Row 1    X    *    *    *    *    *    
Row 2    *    *    *    X    *    *    
Row 3    *    *    *    *    *    *    
Row 4    *    *    *    *    *    *    
Row 5    *    X    *    *    *    *    
Row 6    *    *    *    *    *    *    
Row 7    *    *    *    *    *    X    
Row 8    X    *    *    *    *    *    
Row 9    *    *    X    *    *    *    
Row 10   *    *    *    *    *    *    
Row 11   *    *    *    *    *    *    
Row 12   *    *    *    *    *    *    
Row 13   *    *    *    *    *    X    
Select ticket type [first, business, economy class, or 'done' to exit]: Economy class

Select row [8 to 13]: 9
Select seat [A-F]:   c
Seat already chosen
Select ticket type [first, business, economy class, or 'done' to exit]: Economy class

Select row [8 to 13]: 12
Select seat [A-F]:   a

         A    B    C    D    E    F
Row 1    X    *    *    *    *    *    
Row 2    *    *    *    X    *    *    
Row 3    *    *    *    *    *    *    
Row 4    *    *    *    *    *    *    
Row 5    *    X    *    *    *    *    
Row 6    *    *    *    *    *    *    
Row 7    *    *    *    *    *    X    
Row 8    X    *    *    *    *    *    
Row 9    *    *    X    *    *    *    
Row 10   *    *    *    *    *    *    
Row 11   *    *    *    *    *    *    
Row 12   X    *    *    *    *    *    
Row 13   *    *    *    *    *    X    
Select ticket type [first, business, economy class, or 'done' to exit]: Done
Exiting program