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
Expert's answer
2011-12-01T08:11:47-0500
# include<iostream.h>
# include<conio.h>
# include <string.h>

int A[9][10];
int i, j, row, col, price;
char answer;

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[6][0]=20; A[6][1]=20; A[6][2]=30; A[6][3]=30; A[6][4]=40; A[6][5]=40; A[6][6]=30; A[6][7]=30; A[6][8]=20; A[6][9]=20;
A[7][0]=20; A[7][1]=30; A[7][2]=30; A[7][3]=40; A[7][4]=50; A[7][5]=50; A[7][6]=40; A[7][7]=30; A[7][8]=30; A[7][9]=20;
A[8][0]=30; A[8][1]=40; A[8][2]=30; A[8][3]=50; A[8][4]=50; A[8][5]=50; A[8][6]=50; A[8][7]=50; A[8][8]=40; A[8][9]=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();
& while (answer!='e'){
& cout<<"Would you like to choose seat by prise (type 'p') or by number (type 'n')? (type 'e' to finish)";
& cin>>answer;
& if (answer=='p') ChooseByPrice();
& if (answer=='n') ChooseBySeat();
& if ((answer!='p')&&(answer!='n')&&(answer!='e')) cout<<"Please, chpose proper answer<<\r\n";
}
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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS