Write pseudocode for a program where the seating map for a particular performanc
ID: 3779667 • Letter: W
Question
Write pseudocode for a program where the seating map for a particular performance at a theater contains 70 rows of 100 seats each. Using an array where applicable, develop the pseudeocode for a program that allows a user to continuously enter each household size and then
a) Allows a user to continuously enter a row number and seat number until they enter an appropriate sentinel value for the row number in order to stop entering input. Each time the user enters a valid row and seat number, the program determines if that seat is available, and if so, marks it as reserved with an “X” (available seats are not marked in any way).
b) Once the user quits, the program outputs
i) each row number followed by the seat numbers in that row that have been reserved
ii) the total number of reserved seats
iii) the total number of available seats This seating map applies only to this particular show. For other shows, the seating map may contain a different number of rows and seats per row, and the program must be capable of being modified for those by editing only two lines of code.
the pseudocode needs to look like this
start
declerations
rows = 70
seatsPerRow = 100
num totalSeats = 7000
num reservedSeats
Explanation / Answer
program seatBooking
start
global declarations
ROWS = 70
SEATS = 100
STOP = 9999
boolean layout[ROWS][SEATS];
local declarations
size = 0, row = 0, seat = 0;
for(int i = 0; i<ROWS; i++)
for(int j = 0; j<SEATS; j++)
set layout[i][j] to false;
while(sentinel value not entered, row != STOP) {
display "Enter the household size : "
get size
i = 0;
for each household size {
display "Enter the row numer(press 9999 to exit) : ", get the row number;
display "Enter the seat numer : " get the seat number
if row number is sentinel value
break from the loop
else {
if check layout[row][seat] is true {
display "The seat is already booked, please enter another value!";
continue;
}
else {
set layout[row][seat] to true;
display "Seat booked : [row,seat]"
increment i
} end else
} end else
} end for
} end while
reservedSeats = 0;
display " The Seats booked :: "
for(int i = 0; i<ROWS; i++) {
display the row number
for(int j = 0; j<SEATS; j++) {
if check layout[i][j] is true {
display the seatNumber
increment reservedSeats
} end if
} end for
} end for
display reservedSeats
display Total available seats : (ROWS*SEATS) - reservedSeats
end program
C++ code for the same :
#include <iostream>
#define ROWS 70
#define SEATS 100
#define STOP 9999
using namespace std;
int main() {
bool layout[ROWS][SEATS];
unsigned int size = 0, row = 0, seat = 0;
for(int i = 0; i<ROWS; i++)
for(int j = 0; j<SEATS; j++)
layout[i][j] = false; //seat is not booked, it is available
while(row!=STOP) {
cout << " Enter the household size : ";
cin >> size;
int i = 0;
while(i < size) {
cout << " Enter the row numer(press " << STOP << " to exit) : "; cin >> row;
cout << " Enter the seat numer : "; cin >> seat;
if(row == STOP)
break;
else {
if(layout[row][seat] == true) {
cout << " The seat is already booked, please enter another value!";
continue;
}
else {
layout[row][seat] = true;
cout << " Seat booked : [" << row << " ," << seat << "]";
i++;
}
}
}
}
int reservedSeats = 0;
cout << " Seats booked :: ";
for(int i = 0; i<ROWS; i++) {
cout << " Row " << i << " : ";
for(int j = 0; j<SEATS; j++) {
if (layout[i][j] == true) {
cout << j << " , ";
reservedSeats ++;
}
}
}
cout << " Total reserved seats : " << reservedSeats;
cout << " Total available seats : " << (ROWS*SEATS) - reservedSeats;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.