I/O Stream C++ Practice: Write a program to assign passengers seats in an airplane. Assume a small airplane with seat numbering as Figure 1. The
I/O Stream C++ Practice:
Write a program to assign passengers seats in an airplane. Assume a small airplane with seat numbering as Figure 1. The program should display the seat pattern, with an X marking the seats already assigned. For example, after seats 1A, 2B, and 4C are taken, the display should look like Figure 2. After displaying the seats available, the program prompts for the seat desired, the user types in a seat, and then the display of available seats is updated. This continues until all seats are filled or until the user signals that the program should end. If the user types in a seat that is already assigned, the program should say that that seat is occupied and ask for another choice.
Here's the input1_1.txt file:
1A 2B 3C 4D 4D 5C 6B 7A END
Here's the input1_2.txt file:
1A 1B 1C 1D 2A 2B 2C 2D 3A 3B 3C 3D 4A 4B 4C 4D 5A 5B 5C 5D 6A 6B 6C 6D 7A 7B 7C 7D
-----------------------------------------------------------
Here's the outpu1_1.txt.file:
1 A B C D 2 A B C D 3 A B C D 4 A B C D 5 A B C D 6 A B C D 7 A B C D
Please choose a seat: 1A 1 X B C D 2 A B C D 3 A B C D 4 A B C D 5 A B C D 6 A B C D 7 A B C D
Please choose a seat: 2B 1 X B C D 2 A X C D 3 A B C D 4 A B C D 5 A B C D 6 A B C D 7 A B C D
Please choose a seat: 3C 1 X B C D 2 A X C D 3 A B X D 4 A B C D 5 A B C D 6 A B C D 7 A B C D
Please choose a seat: 4D 1 X B C D 2 A X C D 3 A B X D 4 A B C X 5 A B C D 6 A B C D 7 A B C D
Please choose a seat: 4D The seat is already occupied, please choose another seat.
Please choose a seat: 5C 1 X B C D 2 A X C D 3 A B X D 4 A B C X 5 A B X D 6 A B C D 7 A B C D
Please choose a seat: 6B 1 X B C D 2 A X C D 3 A B X D 4 A B C X 5 A B X D 6 A X C D 7 A B C D
Please choose a seat: 7A 1 X B C D 2 A X C D 3 A B X D 4 A B C X 5 A B X D 6 A X C D 7 X B C D
Please choose a seat: END End of choosing the seat.
Here's the output1_2.txt file:
1 A B C D 2 A B C D 3 A B C D 4 A B C D 5 A B C D 6 A B C D 7 A B C D
Please choose a seat: 1A 1 X B C D 2 A B C D 3 A B C D 4 A B C D 5 A B C D 6 A B C D 7 A B C D
Please choose a seat: 1B 1 X X C D 2 A B C D 3 A B C D 4 A B C D 5 A B C D 6 A B C D 7 A B C D
Please choose a seat: 1C 1 X X X D 2 A B C D 3 A B C D 4 A B C D 5 A B C D 6 A B C D 7 A B C D
Please choose a seat: 1D 1 X X X X 2 A B C D 3 A B C D 4 A B C D 5 A B C D 6 A B C D 7 A B C D
Please choose a seat: 2A 1 X X X X 2 X B C D 3 A B C D 4 A B C D 5 A B C D 6 A B C D 7 A B C D
Please choose a seat: 2B 1 X X X X 2 X X C D 3 A B C D 4 A B C D 5 A B C D 6 A B C D 7 A B C D
Please choose a seat: 2C 1 X X X X 2 X X X D 3 A B C D 4 A B C D 5 A B C D 6 A B C D 7 A B C D
Please choose a seat: 2D 1 X X X X 2 X X X X 3 A B C D 4 A B C D 5 A B C D 6 A B C D 7 A B C D
Please choose a seat: 3A 1 X X X X 2 X X X X 3 X B C D 4 A B C D 5 A B C D 6 A B C D 7 A B C D
Please choose a seat: 3B 1 X X X X 2 X X X X 3 X X C D 4 A B C D 5 A B C D 6 A B C D 7 A B C D
Please choose a seat: 3C 1 X X X X 2 X X X X 3 X X X D 4 A B C D 5 A B C D 6 A B C D 7 A B C D
Please choose a seat: 3D 1 X X X X 2 X X X X 3 X X X X 4 A B C D 5 A B C D 6 A B C D 7 A B C D
Please choose a seat: 4A 1 X X X X 2 X X X X 3 X X X X 4 X B C D 5 A B C D 6 A B C D 7 A B C D
Please choose a seat: 4B 1 X X X X 2 X X X X 3 X X X X 4 X X C D 5 A B C D 6 A B C D 7 A B C D
Please choose a seat: 4C 1 X X X X 2 X X X X 3 X X X X 4 X X X D 5 A B C D 6 A B C D 7 A B C D
Please choose a seat: 4D 1 X X X X 2 X X X X 3 X X X X 4 X X X X 5 A B C D 6 A B C D 7 A B C D
Please choose a seat: 5A 1 X X X X 2 X X X X 3 X X X X 4 X X X X 5 X B C D 6 A B C D 7 A B C D
Please choose a seat: 5B 1 X X X X 2 X X X X 3 X X X X 4 X X X X 5 X X C D 6 A B C D 7 A B C D
Please choose a seat: 5C 1 X X X X 2 X X X X 3 X X X X 4 X X X X 5 X X X D 6 A B C D 7 A B C D
Please choose a seat: 5D 1 X X X X 2 X X X X 3 X X X X 4 X X X X 5 X X X X 6 A B C D 7 A B C D
Please choose a seat: 6A 1 X X X X 2 X X X X 3 X X X X 4 X X X X 5 X X X X 6 X B C D 7 A B C D
Please choose a seat: 6B 1 X X X X 2 X X X X 3 X X X X 4 X X X X 5 X X X X 6 X X C D 7 A B C D
Please choose a seat: 6C 1 X X X X 2 X X X X 3 X X X X 4 X X X X 5 X X X X 6 X X X D 7 A B C D
Please choose a seat: 6D 1 X X X X 2 X X X X 3 X X X X 4 X X X X 5 X X X X 6 X X X X 7 A B C D
Please choose a seat: 7A 1 X X X X 2 X X X X 3 X X X X 4 X X X X 5 X X X X 6 X X X X 7 X B C D
Please choose a seat: 7B 1 X X X X 2 X X X X 3 X X X X 4 X X X X 5 X X X X 6 X X X X 7 X X C D
Please choose a seat: 7C 1 X X X X 2 X X X X 3 X X X X 4 X X X X 5 X X X X 6 X X X X 7 X X X D
Please choose a seat: 7D 1 X X X X 2 X X X X 3 X X X X 4 X X X X 5 X X X X 6 X X X X 7 X X X X
All seats are occupied!
Airplane : The number of rows is fixed at 7 rows, Each row will begin with a row ID, starting from 1, followed by the letters ABCD, separated by a space.
Input file : When submitting the code, it should only accept a file named input1.txt as input. Only 1A,1B, ..., 7D, END will appear in the input file.
Output file :
When submitting the code, it should only accept a file named output1.txt as output, Display the initial seat at the beginning.
The user inputs a seat, and the display of available seats is updated, When the input is 'END,' print out 'End of choosing the seat.' and then stop the program, If all seats are filled, print out 'All seats are occupied!' and then stop the program, If the user types in a seat that is already assigned, print out 'The seat is already occupied, please choose another seat.'.
Reminder: code in C++
Figure 1 \begin{tabular}{|c|} \hline 18 \\ \hlineAx \\ \hline 34 \\ \hline \\ \hline \\ \hline 6ABC \\ \hlineAB \\ \hline \end{tabular} Figure 2Step by Step Solution
There are 3 Steps involved in it
Step: 1
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started