Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

***WILL GIVE MORE POINTS FOR CORRECT ANSWER WIT COMMENTS*** Write a program in C

ID: 644417 • Letter: #

Question

***WILL GIVE MORE POINTS FOR CORRECT ANSWER WIT COMMENTS***

Write a program in C++ for a small theater to use to keep track of which seats have been reserved and which seats are available.

The program should begin by reading seating.txt, which contains information stored from the previous execution of the program, and displaying the seating chart to the screen so the user can see which seats are available and which are not. Use a 2D array to represent the theater seating with each row of the theater corresponding to each row of the array and each seat corresponding to a column in the array. The theater has thirty seats in a row and ten rows.

The first time the program is executed, seating.txt should be initialized to hold the price per seat on one line followed by all zeros for the seats; the program should then display the following where the first line is a header to help track the seat number and the numbers along the left are used to track the row number.


The program should then allow the user to choose from the following options.

The main function should interact with the user and call functions as needed; all input should be validated. There should be no file I/O within function main. The program should continue to execute until the user chooses to exit the program.

Whenever there has been a change to the seating chart, the program should display the updated seating chart.

Establish a global constant, ROWS, for the number of rows as well as a global constant, SEATS, for the number of seats.

Include definitions for the following function prototypes you may also create additional "helper" functions if you wish, but you are required to include the functions described below:

void initializeSeating (int theater[][SEATS], double& ticketPrice);

Prompts user for cost per ticket.

Initializes all elements in the 2D array to zero.

void displaySeating (const int theater[][SEATS]);

Displays seating chart to screen.

void readSeating (int theater[][SEATS], double &ticketPrice);

Attempts to open the file containing the saved ticket price and seating chart.

If the file exists, the cost per ticket and seating information is read.

If the file does not exist, function initializeSeating is called.

void storeSeating (const int theater[][SEATS], double ticketPrice);

The contents of seating.txt is overwritten with the current data.

The first line of the file contains the ticket price.

The seating chart information is stored one row per line with a space between each seat.

int displayMenu (void);

Displays the user's options to the screen.

The user is prompted for a choice, which is returned from the function.

int calcTicketsAvailableInRow(const int theater[][SEATS], int row);

Calculates and returns the number of tickets available in the row.

The function performs no input or output.

NOTE: The value of row is expected to be a human-friendly row number, not an array index. You will need to take this into account!

int calcTotalTicketsSold(const int theater[][SEATS]);

Calculates and returns the total number of tickets that have been sold.

The function performs no input or output.

void reserveSeats(int theater[][SEATS]);

Prompts the user for the number of seats to be reserved; no more than SEATS may be reserved at a time.

If single seat reservation

Prompts the user for the preferred seat; input validation is employed.

If the preferred seat is available, the seat is reserved by replacing the value of zero with a value of one.

If a ticket for the seat has already been sold, the user is informed.

If multiple seat reservation

For simplicity, a multiple seat reservation will require all seats to be on the same row. No more than SEATS number of seats may be reserved at a time.

Prompts the user for the location of the first seat.

When validating input, consider the possibility that the first seat chosen will not allow for the requested number of seats (e. g. 10 seats are requested with a first seat number of 25).

If the requested number of seats beginning with the first seat selected are available, the seats are reserved by replacing the value of zero with a value of one in each element of the array representing the group of seats.

If any of the seats are not available, the user is informed and none of the seats are reserved

The output of your program should look exactly like this. Data values may differ.
  123456789012345678901234567890  1 000000000000000000000000000000  2 000000000000000000000000000000  3 000000000000000000000000000000  4 000000000000000000000000000000  5 000000000000000000000000000000  6 000000000000000000000000000000  7 000000000000000000000000000000  8 000000000000000000000000000000  9 000000000000000000000000000000 10 000000000000000000000000000000 

Explanation / Answer

#include

#define SEATS 30
void initializeSeating (int theater[10][SEATS], double& ticketPrice);
void displaySeating (int theater[10][SEATS]);
void reserveSeats(int theater[10][SEATS]);
int calcTicketsAvailableInRow(int theater[10][SEATS], int row);
int calcTotalTicketsSold(int theater[10][SEATS]);
int calcTotalTicketsRemaining(int theater[10][SEATS]);
int displayMenu (void);

void main()
{
int n;
int thea[10][SEATS]={0,0};

n=displayMenu();

do
{
switch(n)
{
case 1:
{
       double n=30.0;
initializeSeating (thea,n);
}
break;

case 2:
{
displaySeating (thea);
}
break;
case 3:
{
reserveSeats(thea);
}
break;

case 4:
{
int ticrow,row;
printf("Enter the row:");
scanf("%d",&row);

ticrow=calcTicketsAvailableInRow(thea,row);

printf("The Tickets available in row is : %d",ticrow);
}
break;


case 5:
{
int ctsr;
ctsr=calcTotalTicketsRemaining(thea);
printf("Total Ticket Sold %d",ctsr);
}
break;

case 6:
{
int cts;
cts=calcTotalTicketsSold(thea);
printf("Total Ticket Sold %d",cts);
}
break;

default:
{
printf("Enter from the option please:");
}
}
}
while(n==8);
}


void initializeSeating (int theater[10][SEATS], double& ticketPrice)
{
int i=0,j;
for(i=1;i<=10;i++)
{
for(j=1;j<=30;j++)
{
theater[i][j]=0;
}
}

}


void displaySeating (int theater[10][SEATS])
{
   int i,j;

for(i=1;i<=10;i++)
{
for(j=1;j<=30;j++)
{
printf(" %d",theater[i][j]);
}
printf(" ");
}
}

void reserveSeats(int theater[10][SEATS])
{
int i,j;

printf("Enter the row and column to be reserved :");
scanf("%d %d",&i,&j);

theater[i][j]=1;
}

int calcTicketsAvailableInRow(int theater[10][SEATS], int row)
{
int i,count=0;

for(i=1;i<=30;i++)
{
if(theater[row][i]==0)
{
count++;
}
}
return count;
}

int calcTotalTicketsSold(int theater[10][SEATS])
{
int i,j,count=0;

for(i=1;i<=10;i++)
{
for(j=1;j<=30;j++)
{
if(theater[i][j]==1)
count++;
}
}
return count;
}

int calcTotalTicketsRemaining(int theater[10][SEATS])
{
int i,j,count=0;

for(i=1;i<=10;i++)
{
for(j=1;j<=30;j++)
{
if(theater[i][j]==0)
count++;
}
}
return count;
}


int displayMenu (void)
{
   int n;

printf("Enter a option:");
printf(" 1. Initialize seating for new performance.");
printf(" 2. View seating chart.");
printf(" 3. Reserve seats.");
printf(" 4. Calculate tickets remaining in row.");
printf(" 5. Calculate tickets remaining in theater.");
printf(" 6. Calculate total tickets sold.");
printf(" 7. Calculate ticket sales.");
printf(" 8. Exit program.");
scanf("%d",&n);

return n;
}