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,...
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.
(In C language) Given a two-dimensional char array, how do I encode it into a one...
(In C language) Given a two-dimensional char array, how do I encode it into a one dimensional integer array? For example: char arr [8][8] = {{1,1,1,1,1,1,1,1}, {1,0,0,0,1,0,0,1}, {1,0,1,0,1,1,0,1}, {1,0,1,0,0,0,0,1}, {1,0,1,1,1,1,0,1}, {1,0,0,0,0,0,0,1}, {1,0,1,0,1,0,1,1}, {1,1,1,1,1,1,1,1}} into int arr2 [8] I know this problem requires bit-shifting but I am unsure how. It also needs to be as efficient as possible. Thanks!
How to create a two-dimensional array, initializing elements in the array and access an element in...
How to create a two-dimensional array, initializing elements in the array and access an element in the array using PHP, C# and Python? Provide code examples for each of these programming languages. [10pt] PHP C# Python Create a two-dimensional array Initializing elements in the array Access an element in the array
Build a two dimensional array out of the following three lists. The array will represent a...
Build a two dimensional array out of the following three lists. The array will represent a deck of cards. The values in dCardValues correspond to the card names in dCardNames. Note that when you make an array all data types must be the same. Apply dSuits to dCardValues and dCardNames by assigning a suit to each set of 13 elements. dCardNames = ['2','3','4','5','6','7','8','9','10','J','Q','K','A'] dCardValues = ['2','3','4','5','6','7','8','9','10','11','12','13','14'] dSuits = ["Clubs","Spades","Diamonds","Hearts"] Once assigned your two dimensional array should resemble this : 2...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT