In: Computer Science
(c++ code)
A theatre seating chart is implemented as a two-dimensional array of ticket prices, like this:
AISLE
ROW 1 2 3 4 5 6 7 8 9 10
--------------------------------------------------------------------------------------------------------------
10 10 10 10 10 10 10 10 10 10 10
9 10 10 10 10 10 10 10 10 10 10
8 10 10 10 10 10 10 10 10 10 10
7 10 10 20 20 20 20 20 20 10 10
6 10 10 20 20 20 20 20 20 10 10
5 10 10 20 20 20 20 20 20 10 10
4 20 20 30 30 40 40 30 30 20 20
3 20 30 30 40 50 50 40 30 30 20
2 30 40 50 50 50 50 50 50 40 30
1 30 40 50 50 50 50 50 50 40 30
Write a program that prompts users to pick either a seat or a price or quit. 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.
You are to hand in:
Note: Could you plz go through this code and let me
know if u need any changes in this.Thank You
_________________
#include <fstream>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
using namespace std;
void printSeats(int seats[10][10],int rows,int cols);
bool getByLoc(int row,int seat,int seats[10][10],int rows,int
cols);
bool getByPrice(double price,int seats[10][10],int rows,int
cols);
int main() {
const int rows=10;
const int cols=10;
int choice;
int seats[rows][cols] = {
{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},
{30,40,50,50,50,50,50,50,40,30}
};
while(true)
{
cout<<"\n:: MENU ::"<<endl;
cout<<"1.getByLoc"<<endl;
cout<<"2.getByPrice"<<endl;
cout<<"Enter choice :";
cin>>choice;
switch(choice)
{
case 1:{
int row,location;
printSeats(seats,rows,cols);
cout<<"Enter Row :";
cin>>row;
cout<<"Enter Location :";
cin>>location;
if(getByLoc((rows+1)-row,location,seats,rows,cols))
{
cout<<"Seat is available"<<endl;
}
printSeats(seats,rows,cols);
break;
}
case 2:{
int price;
printSeats(seats,rows,cols);
cout<<"Enter Seat Price :$";
cin>>price;
if(getByPrice(price,seats,rows,cols))
{
cout<<"Seat is available"<<endl;
}
printSeats(seats,rows,cols);
break;
}
default:{
cout<<"** Invalid Chocie
**"<<endl;
continue;
}
}
break;
}
return 0;
}
bool getByLoc(int row,int seat,int seats[10][10],int rows,int
cols)
{
if(row<=rows && seat<=cols)
{
if(seats[row-1][seat-1]!=0)
{
cout<<"The price of the seat is
:"<<seats[row-1][seat-1]<<" and is
reserved."<<endl;
seats[row-1][seat-1]=0;
return true;
}
else
{
return false;
}
}
else if(seats[row-1][seat]==0)
{
cout<<"Seat is not available."<<endl;
return false;
}
else
{
cout<<"** Invalid Seat location **"<<endl;
}
return false;
}
bool getByPrice(double price,int seats[10][10],int rows,int
cols)
{
for(int i=rows-1;i>=0;i--)
{
for(int j=0;j<cols;j++)
{
if(seats[i][j]==price)
{
cout<<"Seat with price "<<seats[i][j]<<" is
reserved "<<endl;
seats[i][j]=0;
return true;
}
}
}
}
void printSeats(int seats[10][10],int rows,int cols)
{
cout<<"Row\t1\t2\t3\t4\t5\t6\t7\t8\t9\t10"<<endl;
cout<<"-----------------------------------------------------------------------------------"<<endl;
for (int i = 0; i < rows; i++) {
cout<<setw(8)<<left<<rows-(i);
for (int j = 0; j < cols; j++) {
cout<<setw(8)<<left<<seats[i][j];
}
cout<<endl;
}
}
_________________________
Output:
________________________
Output#2: (Reserved seat based on price)
_______________Could you plz rate me well.Thank
You