fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <iomanip>
  4. using namespace std;
  5.  
  6. int main() {
  7.  
  8. char seatingPlan[13][6] = {
  9. { '*', '*', '*', '*', '*', '*' },
  10. { '*', '*', '*', '*', '*', '*' },
  11. { '*', '*', '*', '*', '*', '*' },
  12. { '*', '*', '*', '*', '*', '*' },
  13. { '*', '*', '*', '*', '*', '*' },
  14. { '*', '*', '*', '*', '*', '*' },
  15. { '*', '*', '*', '*', '*', '*' },
  16. { '*', '*', '*', '*', '*', '*' },
  17. { '*', '*', '*', '*', '*', '*' },
  18. { '*', '*', '*', '*', '*', '*' },
  19. { '*', '*', '*', '*', '*', '*' },
  20. { '*', '*', '*', '*', '*', '*' },
  21. { '*', '*', '*', '*', '*', '*' }
  22. };
  23. string ticketClass;
  24. int ticketRow;
  25. int ticketSeat;
  26.  
  27. cout << "What type of ticket would you like?";
  28. cin >> ticketClass;
  29. while (ticketClass != "exit") {
  30. cout << "Which row would you like?";
  31. cin >> ticketRow;
  32.  
  33. cout << "Which seat would you like to choose?";
  34. cin >> ticketSeat;
  35.  
  36. cout << endl;
  37. if (seatingPlan[ticketRow - 1][ticketSeat - 1] == '*') {
  38. seatingPlan[ticketRow - 1][ticketSeat - 1] = 'X';
  39. cout << endl << "You have successfully booked your " << ticketClass;
  40. cout << " class ticket at row " << ticketRow;
  41. cout << ", seat number " << ticketSeat << ".";
  42. } else {
  43. cout << endl << "The seat is taken. Please choose a different one.";
  44. }
  45.  
  46. cout << endl << "What type of ticket would you like?";
  47. cin >> ticketClass;
  48. }
  49.  
  50. cout << endl << endl << "Seating plan:";
  51. for (int i = 0; i < 13; i++) {
  52. cout << endl;
  53. cout << "Row " << left << setw(4) << i + 1;
  54.  
  55. for (int j = 0; j < 6; j++) {
  56. cout << left << setw(3) << seatingPlan[i][j];
  57. }
  58. }
  59.  
  60. cout << endl << endl << "Thank you for using my program.";
  61. return 0;
  62. }
Success #stdin #stdout 0.01s 5288KB
stdin
business
1
2
business
1
2
economy
8
1
exit
stdout
What type of ticket would you like?Which row would you like?Which seat would you like to choose?

You have successfully booked your business class ticket at row 1, seat number 2.
What type of ticket would you like?Which row would you like?Which seat would you like to choose?

The seat is taken. Please choose a different one.
What type of ticket would you like?Which row would you like?Which seat would you like to choose?

You have successfully booked your economy class ticket at row 8, seat number 1.
What type of ticket would you like?

Seating plan:
Row 1   *  X  *  *  *  *  
Row 2   *  *  *  *  *  *  
Row 3   *  *  *  *  *  *  
Row 4   *  *  *  *  *  *  
Row 5   *  *  *  *  *  *  
Row 6   *  *  *  *  *  *  
Row 7   *  *  *  *  *  *  
Row 8   X  *  *  *  *  *  
Row 9   *  *  *  *  *  *  
Row 10  *  *  *  *  *  *  
Row 11  *  *  *  *  *  *  
Row 12  *  *  *  *  *  *  
Row 13  *  *  *  *  *  *  

Thank you for using my program.