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

A theater seating chart is implemented as a table of ticket prices, like this 10

ID: 3599932 • Letter: A

Question

A theater seating chart is implemented as a table 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 30 30 30 30 20 20

20 30 30 40 50 50 40 30 30 20

30 40 50 50 50 50 50 50 40 30

20 40 50 50 50 50 50 50 40 20

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, randomly choose a seat with that price; mark the sold seats by changing the price to 0. Make sure your code will check whether the seat is available (doesn’t matter which method you use).

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.

P.S. in C++ Language (in Microsoft Visual Studio) and Objective: Practice reading from a file Practice using an array.

Explanation / Answer

//Theatre Seat reservation programme

class SeatAllocation

{

private int a[][];

private int ls[];

private char sr[]={'A','B','C','D','E','F','G','H','I','J'};

public SeatAllocation()

{

a=new int[10][20];

ls=new int[10];

for(int i=0;i<10;i++)

{

for(int j=0;j<20;j++)

a[i][j]=0;

ls[i]=20;

}

}

public static void main(String[] arg)

{

SeatAllocation sa=new SeatAllocation();

//CHANGE ACCORDING TO YOUR REQUIREMENT

sa.book(Integer.parseInt(arg[0]));

sa.book(Integer.parseInt(arg[1]));

sa.book(Integer.parseInt(arg[2]));

sa.book(Integer.parseInt(arg[3]));

sa.display();

}

public void display()

{

System.out.println("Current Seat Status:");

For(int i=0;i<10;i++)

{

System.out.println("");

For(int j=0;j<20;j++)

{

System.out.println(" "+a[i][j]);

}

}

System.out.println(" ");

}

public void book(int n)

{

if(n<=20)

{

int ir=-1;

for(int i=9;i>=0;i--)

{

if(ls[i]>=n)

{ir=i;break;}

}

if(ir!=-1)

{

System.out.print("BOOKED SEATS ARE:");

for(int j=0;j<n;j++)

{

System.out.print(" "+sr[ir]+ " "+(21-ls[ir]+j));

a[ir][20-ls[ir]+j]=1;

}

ls[ir]=ls[ir]-n;

System.out.println(" ");

}

else

{

System.out.println(" Sorry !! Required Seats Not Available");

}

}

else

{

System.out.println(" Only 20 tickets can be booked at a time");

}

}

}

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