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

Write a (n) algorithm that sorts n distinct integers, ranging in size between 1 and kn inclusive, where k is a constant positive integer. (Hint: Use a kn-element array.)

4453


i don't know about working of nested for loop can any one help me

1794


solve the problem in the programming language C++"if a five digit number is input through the keyboard.Write a program to calculate the sum of its digits(hint: use the modulus operator)

2937


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

2369


Write a program that print in screen a tree with its height taken from user by entering number of 4 digits and find the odd numbers then calculate the sum of odd numbers so he get the height of tree?

2915






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

2568


i really need help about this.. write a program to display the set of odd and even numbers separately. find the highest and lowest value of the given numbers.

1971


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

2565


write a program that creates a sequenced array of numbers starting with 1 and alternately add 1 and then 2 to create the text number in the series , as shown below. 1,33,4,6,7,9,............147,148,150 Then , using a binary search , searches the array 100 times using randomly generated targets in the range of 1 to 150

3269


write a function that reverse the elements of an array in place.The function must accept only one pointer value and return void.

3959


Given a table of the form: Product Sold on A 1/1/1980 B 1/1/1980 C 1/1/1980 A 1/1/1980 B 1/1/1980 C 2/1/1980 A 2/1/1980 There are 30 products and 10,000 records of such type. Also the month period during which sales happened is given to u. Write the program to display the result as: Product Month No. of copies A January 12 A February 15 A March 27 B January 54 B February 15 B March 10 C January 37

2198


Code for Easily Using Hash Table?

2391


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


write a program using 2 D that searches a number and display the number of items 12 inputs values input 15,20, 13, 30, 38, 40,16, 18, 20 ,18 ,20 enter no. to search : 20

3368


1+1/2!+1/3!+...+1/n!

1945