Interview Question


Country: United States




Comment hidden because of low score. Click to expand.
0
of 0 vote

USE enum to store the values from A to J
enum
{A,//0 value
B,


....



J//19
Max//20
};


declare an array seat [Max][20];
seat [Max][20]={0};// initialize all elements to 0

- Komal February 09, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

USE enum to store the values from A to J
enum
{A,//0 value
B,


....



J//19
Max//20
};


declare an array seat [Max][20];
seat [Max][20]={0};// initialize all elements to 0

- Komal February 09, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <iostream>

using namespace std;

char seatRows[10] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'};

int main()
{
   //bool seatAvailable[10][20] = {0};
   
   unsigned int uiAvailibility = 200;
   unsigned int uiRowID= 0;
   unsigned int uiSeatID = 1;
   //bool bAvailibility = true;
   
   while (uiAvailibility != 0)
   {
       unsigned int uiBookCount = 0;
       std::cout << endl << uiAvailibility << " Seats Available \n";
       std::cout << "Enter number of seats to book; Max 20 tickets can be booked at a time \n";
       std::cin >> uiBookCount;
       std::cout << "Request to book " << uiBookCount <<" tickets \n";
       if(uiBookCount)
       {
           if((uiBookCount <= uiAvailibility) && (20 >= uiBookCount))
           {
               unsigned int uiRowCount = uiBookCount / 20;
               unsigned int uiSeatCount = uiBookCount % 20;
               for(unsigned int uiCounter = 0; uiCounter < uiRowCount; uiCounter++)
               {
                   uiAvailibility -= 20;
               }
               uiAvailibility -= uiSeatCount;
               
               std::cout << "Booked Tickets are: ";
               
               for(unsigned int uiCounter = 0; uiCounter < uiBookCount; uiCounter++)
                {
                	if(20 >= uiSeatID)
                	{
                		std::cout << seatRows[uiRowID] << uiSeatID << ", ";
                		uiSeatID++;
                	}
                	else
                	{
                		uiSeatID = 1;
                    	uiRowID++;
                	}
                    
                }   
           }
           else
           {
               std::cout << "No Seats booked \n";
           }
       }
       else
       {
           std::cout << "No Seats booked \n";
       }
       
   }

   cout << " \n BOOKINGS CLOSED" << endl; 
   
   return 0;
}

- JNayak April 03, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Small change. The top array should be

char seatRows[10] = {'J','I', 'H', 'G', F', 'E', 'D', 'C', 'B', 'A'};

- jnayak April 03, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream.h>
#include<string.h>

class theatre
{
private:
char rows[10][20];

public:

theatre()
{
for(int i=0;i<10;i++)
{
for(int j=0;j<20;j++)
{
rows[i][j]='E';
}
}
}

void display()
{
char ch='A';

for(int i=0;i<10;i++)
{

cout << ch++ << " ";

for(int j=0;j<20;j++)
{
int jj=j;
if(rows[i][j]=='E')
cout << ++jj << " ";
else
cout << "R ";
}
cout << endl;
}

}

bool choose(int r, int c)
{
if(rows[r][c]=='E')
{
cout << " SEAT is booked " ;
rows[r][c]='R';
return true;
}
else
cout << " SEAT was already booked, please choose another seat " << endl;
return false;
}

};

int main()
{
int ro,co,count;
theatre th;

cout << " How many seats ? : " << endl;
cin >> count;
for(int book_count=0;book_count<count;)
{
th.display();
cout << " Choose from the above seats " << endl;
cout << " Row to be selected : " << endl ;
cin >> ro;
cout << " Column to be selected : " << endl ;
cin >> co ;

if(th.choose(ro,co))
{
book_count=book_count+1;
}
else
{
cout << " SEAT SELECTED WAS ALREADY RESERVED: " << endl << " PLEASE TRY AGAIN.!!! " << endl;
}
}

}

- Kunal Bansal August 20, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

//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");
		}
	}

}

- ASHISH ANI September 25, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

plzz solve it.........

- aryan January 17, 2014 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More