Seat Reservation prog for the theatre. Write a function for
seat allocation for the movie tickets. Total no of seats
available are 200. 20 in each row. Each row is referred by
the Character, "A" for the first row and 'J' for the last.
And each seat in a row is represented by the no. 1-20. So
seat in diffrent rows would be represented as
A1,A2....;B1,B2.....;........J1,J2... Each cell in the
table represent either 0 or 1. 0 rep would seat is
available , 1 would represent seat is reserved.
Booking should start from the last row (J) to the first
row(A). At the max 20 seats can be booked at a time. if
seats are available, then print all the seat nos like "B2"
i.e (2 row, 3 col) otherwise Print "Seats are not
available." and we must book consecutive seats only.

Answer Posted / ashish ani

//DEVELOPED BY ASHISH ANI
// 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.print(" "+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");
}
}

}

Is This Answer Correct ?    4 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

how to diplay a external image of output on winxp by using c & c++,

2938


write a program that reads a series of strings and prints only those strings begging with letter "b"

2674


Code for Small C++ Class to Transform Any Static Control into a Hyperlink Control?

2565


A suduco given & u hv 2 check if it is incomplete(blanks left),or correct or incorrect

2407


can you please write a program for deadlock that can detect deadlock and to prevent deadlock.

2746






output for printf("printf");

1985


U hv to enter a range from a and b and search hw many no. of times a pattern n. occurs between the range a and b. Eg :i/p:enter range :0 100 Enter pattern: 13 o/p: the no. times 13 occurred betwwn 0 to 100:1 Eg :i/p:enter range :100 1000 Enter pattern: 13 o/p: the no. times 13 occurred betwwn 100 to 1000: (in this 13,113,131,132,133…139,213,313,…913 all these will be counted)

2125


Teta-Omeg-Big-Oh Show that f(n) = n2 + 3n3 is ;(n3).

3193


how to write a program that opens a file and display in reverse order?

2567


how to take time as input in the format (12:02:13) from user so that controls remains between these columns?

1817


What output does this program generate as shown? Why? class A { A() { cout << "A::A()" << endl; } ~A() { cout << "A::~A()" << endl; throw "A::exception"; } }; class B { B() { cout << "B::B()" << endl; throw "B::exception"; } ~B() { cout << "B::~B()"; } }; int main(int, char**) { try { cout << "Entering try...catch block" << endl; A objectA; B objectB; cout << "Exiting try...catch block" << endl; } catch (char* ex) { cout << ex << endl; } return 0; }

580


create a stucture student containing field for roll no,class,year and marks.create 10 student annd store them in a file

2220


write a program using virtual function to find the transposing of a square matrix?

2845


write a program that can LOCATE and INSERT elements in array using c++ programming languages.

3437


write a program to calculate the amount of investment after a period n years if the principal investors was p and interest is calculated using compound interest,formular=a=p(1+r)^n

2368