How can i write a c++ program to assign seats on each flight of the airline’s only plane (capacity:10 seats)?

the program should display the following menu of alternatives: 1) Reserve a seat in the smoking section and 2) Reserve a seat in the nonsmoking section. If the person types 1, your program should assign a seat in the smoking section (seats 1-5). If the person types 2, your program should assign a seat in the nonsmoking section (seats 6-10). Your program should print a boarding pass indicating the person’s seat number and whether it is in the smoking or nonsmoking section of the plane.

Use a single-subscripted array to represent the seating chart of the plane. Initialize the elements of the array to 0 to indicate that all seats are empty. As each seat is assigned, set the corresponding elements of the array to 1 to indicate that the seat is no longer available.

.

Your program should never assign a seat that has already been assigned. When the smoking section is full your program should display the message “Sorry, the smoking area is full. Try the nonsmoking area”. Similarly, if the nonsmoking section is full, your program should display “Sorry, the nonsmoking area is full.Try the nonsmoking area”.

I have done this so far :

#include <iostream>

using namespace std;

int main()

{

int a,seat[10]={0,0,0,0,0,0,0,0,0,0},seat_taken,t=6,j=1;

char r;

for (int i=1;i<=10;i++)

{cout<<"would you like to make a reservation? Enter Y for yes and N for no : ";

cin>>r;

if(r =='Y'||r=='y')

{

cout<<"please enter 1 for smokin, 2 for nonsmoking: ";

cin>>a;

if (a==1&&j<6)

{

;

cout <<"seat : "<<seat[j]<< " area : smoking "<< endl<<endl;

seat[j]=j

j=j+1;

}

else if(j>=6)

cout<<"no more set avaliable try the nonsmoking section"<<endl;

if (a==2&&t<11)

{

seat[t]=t;

cout <<"seat : "<<seat[t]<< " area : nonsmoking "<< endl<<endl;

t=t+1;

}

else if (t>=11)

cout<<"no more set avaliable try the smoking section"<<endl;

}

}

return 0;

}

the programe is raning well BUT im not using the array part in the correct way ...help !

Please enter comments
Please enter your name.
Please enter the correct email address.
You must agree before submitting.

Helpful Social

Copyright © 2024 1QUIZZ.COM - All rights reserved.