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.



Seat Reservation prog for the theatre. Write a function for seat allocation for the movie tickets...

Answer / 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

More C++ Code Interview Questions

Implement a command console for changing settings on a particular object. The command console should allow you to enter a string and will return the response (very similar to a terminal session). The commands are as follows: SET propertyname=newvalue will change the target object’s member named “propertyname” to have a value equal to “newvalue”. If the input value is incompatible (i.e. an int being set to a string), print out an appropriate error message. GET propertyname will print out the current value of the target object’s member named “propertyname”. GET * will print out a list of all target object members and their current values. The system should be extensible for future commands and should accept an arbitrary object, such that another developer could insert another object into the system and rely on the command console to get and set the properties correctly.

0 Answers   ABC, Guidance Software,


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

0 Answers  


Write a function- oriented to convert the input dollar(s) into its equivalent peso. Assume that one dollar is equivalent to 51.60

1 Answers  


Write a program that takes a 3 digit number n and finds out whether the number 2^n + 1 is prime, or if it is not prime find out its factors.

3 Answers   TCS, Vimukti Technologies, Wipro,


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

0 Answers   HCL, SRCASW,






write a program to calculate the radius for a quadratic equation use modular programming(function abitraction)hint use quadratic function

1 Answers   ICAN, Jomo Kenyatta University,


Where now stands that small knot of villages known as the Endians, a mighty forest once stood. Indeed, legand has it that you could have stoodon the edge of the wood and seen it stretch out for miles, were it not for the trees getting in the way. In one section of the forest, the trees stood in a row and were of hight from 1 to n, each hight occurring once and once only. A tree was only visible if there were no higher trees before it in the row. For example, if the heights were 324165, the only visible trees would have been those of height 3,4 & 6. Write a Program that takes an array of integers representing the heights of the trees in the row as input and prints the list of the visible trees.

2 Answers   ABC, Nagarro,


program to find the magic square using array

1 Answers  


output for printf("printf");

0 Answers  


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

0 Answers  


How to swap two ASCII numbers?

0 Answers  


using repetition structure. Write a c program that will accept five numbers. The program should count and output the total count of even numbers and total count of add numbers.

2 Answers  


Categories