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

Practice reading from a file Practice using an array A theater seating chart is

ID: 3847359 • Letter: P

Question

Practice reading from a file Practice using an array A theater seating chart is implemented as a table of ticket prices, like this The above seating information is saved in a text file. Your program should load the information from the file into an array. Write a program that asks users to pick either a seat or a price. When choosing seat, indicate the row and column for the location; when choosing the price, just use the first available price; mark the sold seats by changing the price to 0. When a user specifies a seat, make sure it is available. Use loop to determine whether continue to order or not. In each time, the seating chart should be displayed for user. When user stops ordering, your program should output the number of tickets ordered, and amount ordered.

Explanation / Answer

Ans: The following is the program explained with the comments.

#include<iostream>

#include<iomanip> //manipulator functions

using namespace std;

const int rows=10,cols=10; // the chart has 10 rows and 10 columns

char seat[rows][cols];

double price[rows];

int totalSeatSale=0;

double totalTicketSale=0.0;

int tempArray[rows][cols]; // for calculating the row available

int myTable[rows];

int bugTable[rows];

int value;

int bugV=0;

void getPrice(); // for getting row price

double getRowPrice(double[],int);

void defaultChart();

char setDefaultChart(char s[rows][cols]);

void displayChart(); // displaying seat chart

void printChart(char t[rows][cols]);

void getSeatSold();

char replacePound(char r[rows][cols]);

int getTicketToBuy(int& n);

void printTotal(int);

bool Check(int r,int c,char ch);

void viewTotalTicketSale();

void howManySeatSold();

void SeatAvailbleInTheatre();

void SeatAvailableEachRow();

void CalAvailableSeat(int t[rows][cols]);

void checkRowSeat(int [rows][cols],int[rows]);

void checkMyRow(int);

void catchBug(int);

void menu()

{

cout<< " input 'a' for entering the seat price " << endl; // seat price

cout<< " input 'b' display the chart " << endl; // displays chart

cout<< " input 'c' enter row and the seat number for the ticket being sold " <<endl;

cout<< " input 'd' view the total tickets sale " <<endl; // how many tickets for sale

cout<< " input 'e' view how many seats are sold " <<endl; //

cout<< " input 'f' view how many seats available in Theatre " <<endl;

cout<< " input 'g' to view how many seat available in each row " <<endl;

cout<< " input 'q' to_quit " <<endl;

cout<<" ";

cout<<" ";

}

int main()

{

char choice;

  

do{

menu();

cout<< " Enter your choice " << " ";

cin>>choice;

switch(choice)

{

case 'a': getPrice();

break;

case 'b':displayChart();

break;

case 'c':getSeatSold();

break;

case 'd':viewTotalTicketSale();

break;

case 'e':howManySeatSold();

break;

case 'f':SeatAvailbleInAuditorium();

break;

case 'g':SeatAvailableEachRow();

break;

case 'q': cout<< "message thank you" <<endl;

break;

default: cout<< " INVALID INPUT " <<endl;

}

}while(choice !='q');

return 0;

}

void getPrice()

{

getRowPrice(price,rows);

}

double getRowPrice(double p[],int r)

{

for(int i=1;i<=r;i++)

{

cout<< "Enter price for row " << (i) << " ";

cin>>p[i];

}

defaultChart();

}

void defaultChart()

{

setDefaultChart(seat);

checkRowSeat(tempArray,myTable);

}

char setDefaultChart(char s[rows][cols])

{

char pound='#';

for(int i=1;i<=rows;i++)

{

for(int j=1;j<=cols;j++)

{

s[i][j]=pound;

  

}

}

}

void displayChart(){

printChart(seat);

}

void printChart(char t[rows][cols])

{

char blank=' ';

cout<<blank<<blank<<blank<<blank<<blank<<blank;

for(int k=1;k<=cols;k++)

{

cout<<k;

}

cout<<endl;

for(int i=1;i<=rows;i++)

{

cout<<"ROW " << i << " ";

for(int j=1;j<=cols;j++)

{

cout<<t[i][j];

}

cout<<endl;

}

}

void getSeatSold() { // seats which already sold

replacePound(seat);

}

char replacePound(char r[rows][cols]) //

{

char choice;

int i=1,rw,cl,numtickets=0;

char star='*';

bool flag=true;

int total=0;

getTicketToBuy(numtickets);

while(i<=numtickets)

{

cout<< " Enter Row and the column Number " << " " ;

do{

cin>>rw>>cl;

if(Check(rw,cl,star))

{

cout<< " the Seats you are looking for available " <<endl;

}

else

{

cout<< " the Seats you are looking for not available " <<endl;

cout<< " Please select other seats " << " ";

}

}

while(Check(rw,cl,star)!=flag );

total+=price[rw]; // prints the total cost of ticket

printTotal(rw);

r[rw][cl]=star;

catchBug(rw); // bug catching

i++;

}

printChart(r);

cout<< " Your Grand Total is " << total << " $ " <<endl;

totalSeatSale=totalSeatSale+numtickets;

cout<< " Thank you for the purchasing ticket" <<endl;

}

bool Check(int r,int c,char ch)

{

if(char(seat[r][c]) != ch )

{

return true;

}

else

{

return false;

}

}

void printTotal(int n)

{

totalTicketSale+=price[n]; // total tickets price

}

int getTicketToBuy(int& n)

{

cout<<" How many tickets do want to buy ? " << " ";

cin>>n;

}

void viewTotalTicketSale(){

cout<< " Total $ of all Ticket Sale : " << totalTicketSale << " $ " <<endl;

}

void howManySeatSold(){

cout<< " Total Number of "<< totalSeatSale << " Seats has sold " << endl;

}

void SeatAvailbleInTheatre(){

CalAvailableSeat(tempArray);

}

void CalAvailableSeat(int t[rows][cols])

{

int total=0;

for(int i=1;i<=rows;i++)

{

for(int j=1;j<=cols;j++)

{

t[i][cols]=1;

total++;

}

}

cout<< " total seats available in theatre are" << total - totalSeatSale <<endl;

}

void SeatAvailableEachRow(){

for(int i=1;i<=rows;i++)

{

cout<<" total Seats Available in a row " << i<<" is " <<myTable[i]<<endl;

}

cout<<endl;

}

void checkRowSeat(int c[rows][cols],int myT[rows])

{

int myTemp[rows];

int total;

for(int i=1;i<=rows;i++)

{

  

for(int j=1;j<=cols;j++)

{

c[i][j]=1;

}

}

for(int i=1;i<=rows;i++)

{

total=0;

for(int j=1;j<=cols;j++)

{

total+=c[i][j];

}

myTemp[i]=total;

}

for(int i=1;i<=rows;i++)

{

myT[i]=myTemp[i];

}

  

}

void catchBug(int myBug) // catch bugging

{

int tempN,TempT;

tempN=myTable[myBug];

TempT=tempN-1;

myTable[myBug]=TempT;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote