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 / 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 |
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.
Min-Max Write an algorithm that finds both the smallest and largest numbers in a list of n numbers and calculate its complexity T(n).
1 Answers Infosys, Qatar University,
Wrie a function which returns the most frequent number in a list of integers. Handle the case of more than one number which meets this criterion. public static int[] GetFrequency(int[] list)
Deriving time complexity of Binary tree and AVL tree, step by step.
write a function -oriented program that generates the Fibonacci, the current numbers of n(as input) and display them (series). In Fibonacci, the current third number is the sum of the previous number.
A string of charaters were given. Find the highest occurance of a character and display that character. eg.: INPUT: AEGBCNAVNEETGUPTAEDAGPE OUTPUT: E
output for printf("printf");
. Write a program using two-dimensional arrays that computes the sum of data in tows and the sum of data in columns of the 3x3 (three by three) array variable n[3][3].
1. Write a program using one dimensional array that calculates the sum and average of the five input values from the keyboard and prints the calculated sum and average.
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)
using friend function find the maximum number from given two numbers from two different classes.write all necessary functions and constructor for the classes.
Code for Easily Using Hash Table?