C Programming Handling Two Dimensional Arrays Nested Loops a
C+ Programming
Handling Two Dimensional Arrays, Nested Loops, and Requirements Theater Seat Selection Program
Write a program using a 2 dimensional array that enables users to select a theater seat based on price, location, and availability.
Project Requirements: Write a looping program for Theater Seating selection The program will display the theater seating (shown later) and prompt the user to select a seat to purchase using the row number and column number.
If the seat is not available (has already been sold), your program should re-display the theater seating and tell the user that the seat (row and column) they selected is not available, and then prompt for another selection.
When an available seat is sold:
1. The seat will be indicated in the display with an “X”.
2. Output “Thank you for choosing seat # row : r, column: c ”
3. Output “Your ticket price is $ price”
4. The program will pause for about 2 seconds, clear the screen, and then continue, and re-prompt for seat selection.
If all seats are sold, the program will announce that the theater is sold out, display the theater (it will be all X’s), and end.
The program must use functions for the following operations (at a minimum)
Display theater seating - void
Check to see if the seat is available – void or bool
Check to see if the theater is sold out - bool
The program must validate User input - \"ATTENTION: THE SEAT SELECTED, Row \" << userRow << \", Column \" << userColumn << \" DOES NOT EXIST.\"
The design must use a two dimensional array (9 x 8) with the pricing shown in dollars, and continue to prompt for seat selection until all seats are sold. Seating must be displayed with the highest prices at the bottom as shown.
Solution
# include <iostream.h>
# include <iomanip.h>
using namespace std;
void seats( double [] , int);
void mapSeats();
char movMenu(char);
int main()
{
const int rowNumber = (15.0);
double rowVal[rowNumber];
char select;
int row1, column1;
const char TAKEN = \'#\';//seats which are taken
const char EMPTY = \'*\';//seats which are free
const int row = 15; //number of rows
const int column = 20;//number of columns
char map[row][column];
for(int i= 0;i<row;i++)
{
for (int j=0;j<column;j++)
{
map[i][j]=EMPTY;
}
}
mapSeats();
seats(rowVal, rowNumber);
cout << endl;
do
{
cout << \"Please select 1 for ticket selling 2 for quit: \";
cin >> select;
if(select ==\'1\')
{
cout << \"Enter row number and seat number for ticket booking: \" ;
cout << \"Row Number :\" ;
cin >> row1;
cout << endl;
cout << \"Seat Number :\" ;
cin >> column1;
cout << endl;
// Checking for seat whether it is free or not
if(map[row1][column1] == TAKEN)
{
cout << \"Seat is already taken by someone!!!!Book another. \ \";
continue;
}
else
map[row1][column1]=TAKEN;
for (int i = 0; i < row; i++){
for(int j = 0; j < column; j++){
cout << map[i][j];
}
cout << endl;
}
}
else if(select ==\'2\')
{
cout << \"Thank you \" << endl;
}
else if(select != \'1\' || select !=\'2\')
{
cout << \"Invalid selection.\" << endl;
}
}while(select != \'1\' || select !=\'2\');
system(\"Pause\");
return 0;
}
void seats(double rowPrice[], int row)
{
cout << \"Enter ticket price for each row.\" << endl;
for(int i = 0 ; i < row; i++)
{
cout << \"Row # \" << i+1 << \": \" ;
cin >> rowPrice[i];
}
}
void mapSeats()
{
const char TAKEN = \'#\';//seats which are taken
const char EMPTY = \'*\';//seats which are free
const int rw=20;
const int cl=15;
cout << \"Seats \" ;
for(int k = 0 ; k <20;k++)
{
cout << fixed<< setw(2) << \" \" << k ;
}
for(int i=0;i<rw;i++)
{
cout << endl<< \"Row \" << i;
for(int j=0;j<cl;j++)
{
cout << fixed<< setw(2) << \"\" << EMPTY;
}
}
cout << endl;
}


