A theater seating chart is implemented as a two dimensional array of ticket pric
ID: 3544416 • Letter: A
Question
A theater 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
I need to write a JAVA program that prompts users to pick either a seat or a price. Mark sold seats by changing the price to 0. When a u
ser specifies a seat , make sure it is available. When a user specifies a price find any seat with that price
The prgram have to meet these requirements below
The solution also assumes that the user will enter a row and seat which start at 1 and where row 1 is the bottom front row. Your program should have at least 3 static methods that i) print the array, ii) sellSeatByPrice, and iii)sellSeatByNumber. Please declare and initialize your array to the provided seat price values in main
thanks
Explanation / Answer
# 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]<<" ";
A[row][col] = 0;
}
else cout<<"This seat is not available ";
}
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 ";
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 ";
A[i][j] = 0;
B = true;
}
}
}
}
if (B==false) cout<<"There are no seats with this price ";
}
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<< ";
}
getch();
}}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.