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

Definition of priority queue was given. We have to implement the priority queue using array of pointers with the priorities given in the range 1..n. The array could be accessed using the variable top. The list corresponding to the array elements contains the items having the priority as the array index. Adding an item would require changing the value of top if it has higher priority than top. Extracting an item would require deleting the first element from the corresponding queue. The following class was given: class PriorityQueue { int *Data[100]; int top; public: void put(int item, int priority); // inserts the item with the given priority. int get(int priority); // extract the element with the given priority. int count(); // returns the total elements in the priority queue. int isEmpty(); // check whether the priority queue is empty or not. }; We had to implement all these class functions.

0 Answers   Nagarro, Wollega University,


Write a program using one dimensional array that searches a number and display the number of times it occurs on the list of 12 input values. Sample input/output dialogue: Enter 12 values: 13 15 20 13 30 35 40 16 18 20 18 20 Enter number to search: 20 Occurences: 3

2 Answers  


write a function that allocates memory for a single data type passed as a parameter.the function uses the new operator and return a pointer to the allocated memory.the function must catch and handle any exception during allocation

0 Answers   HCL,


write a function – oriented program that calculates the sum of the squares from 1 to n. thus, if the input is 3, the output is 14

3 Answers  


What is the time complexity T(n) of the following program? a) int n, d, i, j; cin >> n; for (d=1; d<=n; d++) for (i=1; i<=d; i++) for (j=1; j<=n; j += n/10) cout << d << " " << i << " " << j << endl; b) void main() { int n, s, t; cin >> n; for (s = 1; s <= n/4; s++) {t = s; while (t >= 1) { cout << s << " " << t << endl; t--; } } } c) void main() { int n, r, s, t; cin >> n; for (r = 2; r <= n; r = r * 2) for (s = 1; s <= n/4; s++) { t = s; while (t >= 1) { cout << s << " " << t << endl; t--; } } }

3 Answers   CTS, IBM, Infosys, Qatar University,






1.program to add any two objects using operator overloading 2.program to add any two objects using constructors 3.program to add any two objects using binary operator 4.program to add any two objects using unary operator

2 Answers   IBM,


output for printf("printf");

0 Answers  


Write a simple encryption program using string function which apply the substitution method.

0 Answers  


hello friends, given an expression we have to remove the unwanted brackets in that expression. Eg : (a+b) ---> a+b (a+b)*(c)-----> (a+b)*c. Please mail me if you know the logic. My mail id is : saravana6m@gmail.com. Thank you in advance :-)

1 Answers   GrapeCity, Microsoft,


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)

0 Answers  


write a program that reverses the input number of n.Formulate an equation to come up with the answer.

0 Answers   Satyam,


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

0 Answers  


Categories