Here's a basic code; that's using two bool arrays to determinate if the seat is taken and if the seat is for smokers;
#include <iostream>
using namespace std;
#define Row 2
#define Column 10
bool SeatTaken [Row][Column]; // Is a specific seat taken?
bool SmokerSeat[Row][Column]; // Is a specific seat for smokers?
void ClearSeatsTaken()
{
for (int n=0; n<Column; n++)
for (int a=0; a<Row; a++)
SeatTaken [a][n]=0;
}
void SetSmokerSeats()
{
for (int n=0; n<Column; n++)
{for (int a=0; a<Row; a++)
{SmokerSeat [a][n]=0;}}
for (int n=0; n<Column/2; n++)
{for (int a=0; a<Row; a++)
{SmokerSeat [a][n]=1;}}
}
void TESTUNIT()
{
for (int n=0; n<Column; n++)
{for (int a=0; a<Row; a++)
{cout << SeatTaken [a][n] << " ";}
cout << endl;
}
}
void MISSING()
{
cout << "THIS PART OF THE PROGRAM IS MISSING; IT*S NOT MADE YET. IT SHOULD FIND ANOTHER RUTE IN THIS FUNCTION!" << endl;
}
void DedicateSeat(bool Smoker)
{
bool GlobalBreak=false;
for (int n=0; n<Column; n++)
{
if (GlobalBreak==true){break;}
for (int a=0; a<Row; a++)
{
if (GlobalBreak==true){break;}
if ((SmokerSeat [a][n]==Smoker) && (SeatTaken [a][n]==false))
{
SeatTaken [a][n]=true;
cout << "Seat" << a << " at " << n << " is now taken!" << endl;
GlobalBreak=true;
}
}
}
if (GlobalBreak==false)
{
bool Interrested=false;
cout << "ERROR! No ";
if (Smoker){cout << "smoker";}else{cout << "non smoker";}
cout << " seats avaiable!" << endl;
cout << "Interrested in another apparture? [Yes=1][No=0]" << endl;
cin >> Interrested;
if (Interrested){MISSING();}
}
}
bool YouASmoker()
{
int SmokerSeatNeeded=0;
cout << "Do you need a smokers seed? [Yes=1][No=0][Exit=-1]" << endl;
cin >> SmokerSeatNeeded;
if (SmokerSeatNeeded==-1){return 1;}
DedicateSeat(SmokerSeatNeeded);
return 0;
}
int main()
{
ClearSeatsTaken();
SetSmokerSeats();
while (1){
if(YouASmoker()==1){break;}
TESTUNIT();}
return 0;
}
^^It's just a simple test code; based upon a matrix array.
Hope it will help in any way
#include <iostream>
#include <string>
using namespace std;
void initialize(int& flight, int& seatAreaOne, int& seatAreaTwo);
void plane(int flight);
void planeOne(int seatAreaOne);
void planeTwo(int seatAreaTwo);
void ClearSeatsTaken();
void SetSmokerSeats();
void MISSING();
bool YouASmoker();
void TESTUNIT();
#define Row 1
#define Column 10
bool SeatTaken [Row][Column]; // Is a specific seat taken?
bool SmokerSeat[Row][Column]; // Is a specific seat for smokers?
int main()
{
string name;
string passport;
int flight;
int seatAreaOne;
int seatAreaTwo;
int n;
cout<<"WELCOME TO C++ AIRLINES."<<endl;
cout<<"Please enter your name:"<<endl;
getline(cin, name);
cout<<"Please enter your passport number:"<<endl;
cin>>passport;
cout<<"Name:"<<name<<endl;
cout<<"Passport number:"<<passport<<endl;
initialize(flight, seatAreaOne, seatAreaTwo);
plane(flight);
ClearSeatsTaken();
SetSmokerSeats();
while (1){
if(YouASmoker()==1){break;}
TESTUNIT();}
cout<<"Boardingpass slip"<<endl;
cout<<"Name:"<<name<<endl;
cout<<"Pasport number:"<<passport<<endl;
cout<<"Your seat number:"<<n + 1<<endl;
return 0;
}
void initialize(int& flight, int& seatAreaOne, int& seatAreaTwo)
{
flight = 0;
seatAreaOne = 0;
seatAreaTwo = 0;
}
void plane(int flight)
{
int seatAreaOne;
int seatAreaTwo;
seatAreaOne = 0;
seatAreaTwo = 0;
cout<<"For your information, our company provides only two flights per day."<<endl;
cout<<"Enter (1) for flight A101 OR (2) for flight A102."<<endl;
cin>>flight;
if (flight==1)
{
cout<<"A101"<<endl;
planeOne(seatAreaOne);
}
else
{
cout<<"A102"<<endl;
planeTwo(seatAreaTwo);
}
}
void planeOne(int seatAreaOne)
{
cout<<"There are two types of seating area provided in this flight:"<<endl;
bool YouASmoker();
}
void planeTwo(int seatAreaTwo)
{
cout<<"There are two types of seating area provided in this flight"<<endl;
cout<<"Please choose a type of seating area."<<endl;
bool YouASmoker();
}
void ClearSeatsTaken()
{
for (int n=0; n<Column; n++)
for (int a=0; a<Row; a++)
SeatTaken [a][n]=0;
}
void SetSmokerSeats()
{
for (int n=0; n<Column; n++)
{for (int a=0; a<Row; a++)
{SmokerSeat [a][n]=0;}}
for (int n=0; n<Column/2; n++)
{for (int a=0; a<Row; a++)
{SmokerSeat [a][n]=1;}}
}
void TESTUNIT()
{
for (int n=0; n<Column; n++)
{for (int a=0; a<Row; a++)
{cout << SeatTaken [a][n] << " ";}
cout << endl;
}
}
void MISSING()
{
cout << "THIS PART OF THE PROGRAM IS MISSING; IT*S NOT MADE YET. IT SHOULD FIND ANOTHER RUTE IN THIS FUNCTION!" << endl;
}
void DedicateSeat(bool Smoker)
{
bool GlobalBreak=false;
for (int n=0; n<Column; n++)
{
if (GlobalBreak==true){break;}
for (int a=0; a<Row; a++)
{
if (GlobalBreak==true){break;}
if ((SmokerSeat [a][n]==Smoker) && (SeatTaken [a][n]==false))
{
SeatTaken [a][n]=true;
cout << "Seat" << a << " at " << n << " is now taken!" << endl;
GlobalBreak=true;
}
}
}
if (GlobalBreak==false)
{
bool Interrested=false;
cout << "ERROR! No ";
if (Smoker){cout << "smoker";}else{cout << "non smoker";}
cout << " seats avaiable!" << endl;
cout << "Interrested in another apparture? [Yes=1][No=0]" << endl;
cin >> Interrested;
if (Interrested){MISSING();}
}
}
bool YouASmoker()
{
int SmokerSeatNeeded=0;
cout << "Do you need a smokers seed? [Yes=1][No=0][Exit=-1]" << endl;
cin >> SmokerSeatNeeded;
if (SmokerSeatNeeded==-1){return 1;}
DedicateSeat(SmokerSeatNeeded);
return 0;
}
Thanks for yr helping ... tis is my 2nd draft ..if i want to print a boardingpass, do i need to do another function call ?
my boarding pass include list out name, passport number , and the seat number ...