//a program to assign seats on each flight of the airlines’ only plane (capacity 25 seats)
#include <iostream>
using std::cout;
using std::endl;
using std::cin;
#include<string>
int main()
{
string Name;
string idNumber;
const int SEATS = 26;
int plane[ SEATS ] = { 0 }, people = 0, economy = 14, firstClass = 1;
char response, choice,F = firstClass,E = economy;
while ( people < 25 ) {
cout << "\nPlease type \"F\" for \"firstClass\" OR \"E\" for \"economy\"\n";
cin >> choice;
cout<<" Enter your name "<<endl;
getline( cin,Name,'\n');
cout<<"Enter your id number"<<endl;
cin>>idNumber;
if ( choice == 'F' ) {
if ( !plane[ firstClass ] && firstClass <= 13 ) {
cout << "Your seat assignment is " << firstClass << ' ';
plane[ firstClass++ ] = 1;
++people;
}
}
if( choice == 'E'){
if ( !plane[ economy ] && economy <= 25 ) {
cout << "Your seat assignment is " << economy << '\n';
plane[ economy++ ] = 1;
++people;
}
}
else if ( firstClass > 13 && economy <= 25 ) {
cout << "The firstClass section is full.\n"
<< "Would you like to sit in the economy"
<< " section (Y or N)? ";
cin >> response;
if( response == 'Y' ) {
cout << "Your seat assignment is " << economy << ' ';
plane[ economy++ ] = 1;
++people;
}
else
cout << "The plane is full!! Next flight leaves in 5 Hours Time.\n";
}
if ( economy > 25 && firstClass <= 13 ) {
cout << "The economy section is full.\n"
<< "Would you like to sit in the firstClass"
<< " section (Y or N)? ";
cin >> response;
if (response == 'Y' ) {
cout << "Your seat assignment is " << firstClass << '\n';
plane[ firstClass++ ] = 1;
++people;
}
else
cout << "The plane is full!! Next flight leaves in 5 Hours Time.\n";
}
}
cout << "The plane is full!! Next flight leaves in 5 Hours Time.\n";
cout << "All seats for this flight are sold." << endl;
return 0;
}
clyo cleopas 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.