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 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(); }}
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment