# Answer to Question #5398 in C++ for air

Question #5398
Problem:
A theatre seating chart is implemented as a two-dimensional array of ticket prices, like this:
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10 10 10
10 10 20 20 20 20 20 20 10 10
10 10 20 20 20 20 20 20 10 10
10 10 20 20 20 20 20 20 10 10
20 20 30 30 40 40 30 30 20 20
20 30 30 40 50 50 40 30 30 20
30 40 50 50 50 50 50 50 40 30
Write a program that prompts users to pick either a seat or a price. Mark sold seats by changing the price to 0. When a user specifies a seat, make sure it is available. When a user specifies a price, find any seat with that price starting at the front and working to the back of the theatre. Make sure you write your program using well defined functions.
1
2011-12-01T08:11:47-0500
# include<iostream.h>
# include<conio.h>
# include <string.h>

int A;
int i, j, row, col, price;

void FillA(){
for (i=0;i<=8;i++){
& for (j=0;j<=5;j++) A[i][j] = 10;
& }
for (i=3;i<=4;i++){
& for (j=2;j<=6;j++) A[i][j] = 20;
& }
A=20; A=20; A=30; A=30; A=40; A=40; A=30; A=30; A=20; A=20;
A=20; A=30; A=30; A=40; A=50; A=50; A=40; A=30; A=30; A=20;
A=30; A=40; A=30; A=50; A=50; A=50; A=50; A=50; A=40; A=30;
}

void ChooseBySeat(){
cout<<"Enter row number: ";
cin>>row;
cout<<"Enter row column: ";
cin>>col;
if ((A[row][col])!=0){
& cout<<"It'll cost you \$"<<A[row][col]<<"\r\n";
& A[row][col] = 0;
& }
else cout<<"This seat is not available\r\n";
}

void ChooseByPrice(){
cout<<"Enter the wanted price please (20, 30, 40, 50): ";
cin>>price;
bool B=false;
if ((price!=20)&&(price!=30)&&(price!=40)&&(price!=50)) cout<<"Enter a valid price, please\r\n";
else{
& for (i=8;i>=0;i--){
& for (j=9;j>=0;j--){
& if ((A[i][j]==price)&&(B==false)) {
& cout<<"We can propose you seat "<<i<<"row "<<j<<"column\r\n";
& A[i][j] = 0;
& B = true;
& }
& }
& }
& }
if (B==false) cout<<"There are no seats with this price\r\n";
}

void main(){
FillA();
& cout<<"Would you like to choose seat by prise (type 'p') or by number (type 'n')? (type 'e' to finish)";
}
getch();
}}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!