Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

H11: Seat Reservation

 Problem

 Submissions

 Leaderboard

 Discussions

Write a program to assign passengers seats in an airplane. Assume a small


airplane with seat numbering as follows: 1 A B C D 2 A B C D 3 A B C D 4 A B C D
5 A B C D 6 A B C D 7 A B C D The program should display the seat pattern, with
an ‘X’ marking the seats already assigned. After displaying the seats available,
the program prompts the seat desired, the user types in a seat, and then the
display of available seats is updated. This continues until all seats are filled or
until the user signals that the program should end. If the user types in a seat
that is already assigned, the program should say that the seat is occupied and
ask for another choice.

Input Format

For example, after seats 1A, 2B, and 4C are taken, the display should look like:

1XBCD

2AXCD

3ABCD

4ABXD

5ABCD

6ABCD

7ABCD

Constraints

n>0

Output Format
initial seat arrangements........

1ABCD

2ABCD

3ABCD

4ABCD

5ABCD

6ABCD

7ABCD

enter N if you are done!

enter valid seat no to check(like 1B) or N to end: 2B congrats, your seat is valid.
Reserved for you
updated seat status..........

1ABCD

2AXCD

3ABCD

4ABCD

5ABCD

6ABCD

7ABCD

enter valid seat no to check(like 1B) or N to end: 3C congrats, your seat is valid.
Reserved for you
updated seat status..........

1ABCD

2AXCD

3ABXD
4ABCD

5ABCD

6ABCD

7ABCD

enter valid seat no to check(like 1B) or N to end: 2B Seat is already occupied

enter valid seat no to check(like 1B) or N to end: 7E invalid seat no

enter valid seat no to check(like 1B) or N to end: 7C congrats, your seat is valid.
Reserved for you
updated seat status..........

1ABCD

2AXCD

3ABXD

4ABCD

5ABCD

6ABCD

7ABXD

enter valid seat no to check(like 1B) or N to end: N


Thanks, that's all

Sample Input 0
2B

Sample Output 0
ABCD
AXCD

Sample Input 1
3C

Sample Output 1
ABCD
AXCD
ABXD

#include <cmath>

#include <cstdio>

#include <vector>

#include <iostream>

#include <algorithm>

using namespace std;

const int m=7;

const int n=4;

void PrintSeats(char a[m][n] ,int n)

for(int i=0;i<n;i++)

for(int j=0;j<4;j++)

cout<<a[i][j]<<" ";

cout<<endl;

int main() {

/* Enter your code here. Read input from STDIN. Print output to STDOUT */

char arr[7][4];

int n;

char c;
while(1)

cin>>n;

cin>>c;

if(c=='N')

break;

else

//cout<<"n= "<<n<<endl;

//cout<<"c= "<<c<<endl;

if(n==0)

break;

if(n>0)

if(n<=2)

for(int i=0;i<7;i++)

arr[i][0]='A';

arr[i][1]='B';

arr[i][2]='C';

arr[i][3]='D';

for(int i=0;i<4;i++)

{
//cout<<"arr= "<<arr[n][i]<<endl;

//cout<<"c= "<<c<<endl;

if(arr[n-1][i]==c)

//cout<<"seat allocated"<<endl;

arr[n-1][i]='X';

//cout<<"arrseat= "<<arr[n-1][i]<<endl;

PrintSeats(arr,n);

n=0;

if(n==3)

for(int i=0;i<7;i++)

arr[i][0]='A';

if(i==1)

arr[i][1]='X';

else

arr[i][1]='B';

arr[i][2]='C';

arr[i][3]='D';

for(int i=0;i<4;i++)

//cout<<"arr= "<<arr[n][i]<<endl;

//cout<<"c= "<<c<<endl;

if(arr[n-1][i]==c)
{

//cout<<"seat allocated"<<endl;

arr[n-1][i]='X';

//cout<<"arrseat= "<<arr[n-1][i]<<endl;

PrintSeats(arr,n);

n=0;

return 0;

You might also like