Question

In: Computer Science

(c++ code) A theatre seating chart is implemented as a two-dimensional array of ticket prices, like...

(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:

  • Source code (well documented)
  • Input file (if used)
  • Sample tests for valid and invalid choices
  • Hierarchy Chart
  • User Guide

Solutions

Expert Solution

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


Related Solutions

*****IN JAVA**** Implement a theater seating chart  as a two-dimensional array of ticket prices, like this: {10,...
*****IN JAVA**** Implement a theater seating chart  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,...
A theater seating chart is implemented as a table of ticket prices, like this C1 C2...
A theater seating chart is implemented as a table of ticket prices, like this C1 C2 C3 C4 C5 C6 C7 C8 C9 C10 R1 10 10 10 10 10 10 10 10 10 10 R2 10 10 10 10 10 10 10 10 10 10 R3 10 10 10 10 10 10 10 10 10 10 R4 10 10 20 20 20 20 20 20 10 10 R5 10 10 20 20 20 20 20 20 10 10 R6...
Provide code samples for the following in C#a. Declare a two-dimensional array of integers names...
Provide code samples for the following in C#a. Declare a two-dimensional array of integers names intArray17.b. Create a loop to calculate the sum of every element in the first column.c. Create a loop to calculate the sum of every element in the array.
In C# - Provide code samples for the following: Declare a two-dimensional array of integers names...
In C# - Provide code samples for the following: Declare a two-dimensional array of integers names intArray17. Create a loop to calculate the sum of every element in the first column. Create a loop to calculate the sum of every element in the array.
C++ ASSIGNMENT: Two-dimensional array Problem Write a program that create a two-dimensional array initialized with test...
C++ ASSIGNMENT: Two-dimensional array Problem Write a program that create a two-dimensional array initialized with test data. The program should have the following functions: getTotal - This function should accept two-dimensional array as its argument and return the total of all the values in the array. getAverage - This function should accept a two-dimensional array as its argument and return the average of values in the array. getRowTotal - This function should accept a two-dimensional array as its first argument...
1.Write the java code to create a two dimensional String array of sizes 12 by 8;...
1.Write the java code to create a two dimensional String array of sizes 12 by 8; Given the java array:       double[] test = new double[3]; 2.  Write the java code to put the numbers 1.0, 2.0, and 3.0 in to the array so that the 1.0 goes in the first cell, the 2.0 goes in the second cell and the 3.0 goes in the third cell. 3. Can you have different types of data is a three dimensional array? 4....
Write a C function that finds and displays the maximum value ina two-dimensional array of...
Write a C function that finds and displays the maximum value in a two-dimensional array of integers. The array should be declared as a 10-row-by-20-column array of integers in main (), and the starting the address of the array should be passed to the function. Modify the function so that it also displays the rows and columns number of the element with the maximum value
Write a C++ function that takes a two dimensional dynamic array (matrix) and its sizes and...
Write a C++ function that takes a two dimensional dynamic array (matrix) and its sizes and returns true if the matrix is an upper matrix and returns false otherwise. Remark: A matrix M is an upper matrix if it is a square matrix (row size = column size) and every element M[i][j] = 0 for all i > j. That is all the elements of the matrix below the main diagonal are zero.
- Students must develop the code required to create a square two-dimensional array just large enough...
- Students must develop the code required to create a square two-dimensional array just large enough to store a given string in encrypted form using the given encryption algorithm. The character used after the end of the encrypted string is the ASCII delete key, set as final UNPRINTABLE_CHAR_VALUE. After this value is stored, the encryption process fills the remaining elements with random values - Students must develop the code to decrypt a given square two-dimensional array and using the given...
you will create a dynamic two dimensional array of mult_div_values structs (defined below). The two dimensional...
you will create a dynamic two dimensional array of mult_div_values structs (defined below). The two dimensional array will be used to store the rows and columns of a multiplication and division table. Note that the table will start at 1 instead of zero, to prevent causing a divide-by-zero error in the division table! struct mult_div_values { int mult; float div; }; The program needs to read the number of rows and columns from the user as command line arguments. You...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT