#include <iostream> #include <iomanip> using namespace std; /******************************************************************************* * This program takes as input a ticket type of first class, business class, or * economy class, and a desired seat number and letter. ******************************************************************************/ int main() { // Inputs char ticket; // Ticket type (f, b, or e) char seats[13][6]; // Array of seats (* or X) int row = 0; char seatLetter = 'a'; int seatColumn = 0; // Initialize seats array with asterisks for (int i = 0; i < 13; i++) { for (int j = 0; j < 6; j++) { seats[i][j] = '*'; } } // Start of Loop while (true) { // Ticket type menu cout << "Select ticket type [first, business, economy class, " << "or 'done' to exit]: "; cin >> ticket; // Prevent Invalid types of ticket while (ticket != 'f' && ticket != 'b' && ticket != 'e' && ticket != 'd') { cout << "Invalid ticket type" << endl; cout << "Select ticket type [first, business, economy class, " << "or 'done' to exit]: "; cin >> ticket; } // cin.ignore(); // Switch for ticket type switch(ticket) { case 'f': cout << "First class" << endl << endl; do { cout << "Select row [1 or 2]: "; cin >> row; cout << row << endl; } while (row != 1 && row != 2); row--; break; case 'b': cout << "Business class" << endl << endl; do { cout << "Select row [3 to 7]: "; cin >> row; cout << row << endl; } while (row < 3 || row > 7); row--; break; case 'e': cout << "Economy class" << endl << endl; do { cout << "Select row [8 to 13]: "; cin >> row; cout << row << endl; } while (row < 8 || row > 13); row--; break; case 'd': // Done cout << "Done" << endl; cout << "Exiting program" << endl; return 0; } do { cout << "Select seat [A-F]: "; cin >> seatLetter; cout << seatLetter << endl; } while (seatLetter != 'a' && seatLetter != 'b' && seatLetter != 'c' && seatLetter != 'd' && seatLetter != 'e' && seatLetter != 'f'); switch(seatLetter) { case 'a': seatColumn = 0; break; case 'b': seatColumn = 1; break; case 'c': seatColumn = 2; break; case 'd': seatColumn = 3; break; case 'e': seatColumn = 4; break; case 'f': seatColumn = 5; break; } if (seats[row][seatColumn] == 'X') { cout << "Seat already chosen" << endl; continue; } seats[row][seatColumn] = 'X'; // DISPLAY SEATING PLAN cout << '\n'; cout << right << setw(10) << 'A' << setw(5) << 'B' << setw(5) << 'C' << setw(5) << 'D' << setw(5) << 'E' << setw(5) << 'F' << endl; for (int i = 0; i < 13; i++) { cout << left << "Row " << setw(5) << i + 1; for (int j = 0; j < 6; j++) { cout << seats[i][j] << " "; } cout << endl; } } // End of Loop return 0; } /* for (int i = 0; i < 13; i++) { cout << "Row " << left << setw(5) << i + 1; for (int j = 0; j < 6; j++) { cout << seats[i][j] << " "; } cout << endl; } */
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
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