9. Airplane Seats: Write a program to assign passengers seats in an airplane. As
ID: 2291815 • Letter: 9
Question
9. Airplane Seats: Write a program to assign passengers seats in an airplane. Assume a small airplane with seat numbering as follows: 1 AB C D 2 A B CD 3 AB C D 4 A B C D S ABCD 6 AB CD 7 AB CD should display the seat pattern, with an X marking the seats The program already assigned. For example, after seats 1A, 2B, and 4C are taken, the display should look like this: 1 XB CD 2 AX CD 3 A B CD 4 A B XD S A B CD 6 A B CD 7 AB CD 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 choiceExplanation / Answer
Hello,
Please find the answer attached below. If the answer has helped you please give a thumbs up rating. Thank you and have a nice day!
NOTE: I have witten the code in Matlab:
**** Matlab Code ****
%%%%%%%%% Structure creation %%%%%%%%%%
clc;
seat(1).n = 1;
seat(1).b = {'ABCD'};
seat(2).n = 2;
seat(2).b = {'ABCD'};
seat(3).n = 3;
seat(3).b = {'ABCD'};
seat(4).n = 4;
seat(4).b = {'ABCD'};
seat(5).n = 5;
seat(5).b = {'ABCD'};
seat(6).n = 6;
seat(6).b = {'ABCD'};
seat(7).n = 7;
seat(7).b = {'ABCD'};
loop = 1;
fprintf('========= Seat Assignment Program======== ')
while(loop)
fprintf('========= Available Seats======== ')
for cc = 1:7
nn = seat(cc).n;
pos = char(seat(cc).b);
fprintf('%d==%s==%s==%s==%s ', nn, pos(1),pos(2),pos(3),pos(4));
end
prompt = 'Enter your desired seat (for ex: 4A): ';
x = input(prompt,'s');
n1 = str2num(x(1));
if(x(2)=='a'|x(2)=='A')
seat(n1).b = {'XBCD'};
elseif(x(2)=='b'|x(2)=='B')
seat(n1).b = {'AXCD'};
elseif(x(2)=='c'|x(2)=='C')
seat(n1).b = {'ABXD'};
elseif(x(2)=='d'|x(2)=='D')
seat(n1).b = {'ABCX'};
end
prompt = 'Do you want to enter further seats (press 1 for yes and 0 for no): ';
loop = input(prompt);
end
**** Output ****
========= Seat Assignment Program========
========= Available Seats========
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
Enter your desired seat (for ex: 4A): 5b
Do you want to enter further seats (press 1 for yes and 0 for no): 1
========= Available Seats========
1==A==B==C==D
2==A==B==C==D
3==A==B==C==D
4==A==B==C==D
5==A==X==C==D
6==A==B==C==D
7==A==B==C==D
Enter your desired seat (for ex: 4A): 2c
Do you want to enter further seats (press 1 for yes and 0 for no): 1
========= Available Seats========
1==A==B==C==D
2==A==B==X==D
3==A==B==C==D
4==A==B==C==D
5==A==X==C==D
6==A==B==C==D
7==A==B==C==D
Enter your desired seat (for ex: 4A): 3d
Do you want to enter further seats (press 1 for yes and 0 for no): 0
>>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.