Question: Write a program to assign passengers seats in an airplane. Assume a small airplane with seat numbering as follows: ( You can assume that the
Write a program to assign passengers seats in an airplane. Assume a small airplane
with seat numbering as follows: You can assume that the columns are but the
rows will differ
A B C D
A B C D
A B C D
A B C D
A B C D
A B C D
A B C D
Your program will ask the user how many rows the plane has and use a dynamic
array or arrays to handle the number of rows. Your program should display the seat
pattern, with an X marking the seats already assigned. For example, after seats A
B and C are taken, the display should look like this:
X B C D
A X C D
A B C D
A B X D
A B C D
A B C D
A B C D
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
the seat is occupied and ask for another choice. Do not forget to free the memory
allocated for these returned dynamic arrays when the data is no longer needed.
Automated testing For a large number of rows, you may need to enter a lot of test
data. In order to speed up the testing, you need to design your program to allow the
input to be entered via console or an input file. So you should initially prompt the
user to ask whether the input will come from the console or an input file. If from an
input file, user needs to enter the file name. For example, the test file should contain
the following input: The first line will contain the number of rows
A
A
A
A
A
A
A
B
C
D
D
end
You can have different test files, with some containing conflicting seat assignments.
Hint: To make your program automatically testable, replace the cin with an istream
variable so you can control where the input stream come from in the main
program.
More hint:
There are two approaches to define the arrays.
The first approach is to use a twodimensional array to represent the seats, as
follows:
char seats;
cin rowSize;
seats new charrowSize;
for int i ; i rowSize; i
seatsi new char;
Then you can access each seat by using two indices as seatsij
The second approach is to define four arrays, each represent a column of seats. See
the following code fragment:
char colA;
char colB;
char colC;
char colD;
cin rowSize;
colA new charrowSize;
colB new charrowSize;
colC new charrowSize;
colD new charrowSize;
Write a function called deleterepeats that has a partially filled array of
characters as a formal parameter and that deletes all repeated letters from the
array. It returns a new dynamic array where all repeated letters are deleted. Do not
modify the input array.
For example, consider the following code:
char strto be or not to be;
int size strlenstr;
char noRepeat;
noRepeat deleterepeatsstr size;
cout noRepeat;
Will print out:
to bern
Lets assume that the characters are case insensitive.
Dont forget to free the memory allocated for these returned dynamic arrays when
the data is no longer needed.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
