ASSIGNMENT: C++ Your employer has determined a market for a simple airline ticke
ID: 3716326 • Letter: A
Question
ASSIGNMENT: C++
Your employer has determined a market for a simple airline ticketing system for a very
simple airline (
Tree Top Airways
-
TTA). The airline only has two aircraft, named ALFA
and BRAVO.
Initially, the ticket system will determine the number of seats on each plane
and in the lounge.
The ticketing system is to be installed at the airport ticket booth for the
airline and will operate under the following rules:
1)
If a party arrives and the
re is enough room on the plane requested, they are allowed to
board and a message to that effect is printed.
2)
If a party arrives and there is not enough room on the plane requested due to people
already being on the plane, the party is directed to wait
in the lounge and a message to
that effect is printed.
3)
If a party arrives and there is not enough room on the plane requested because the
plane is just too small, the party is turned away and a message to that effect is printed.
4)
If a party is direc
ted to the lounge and there is not enough room in the lounge, the
party is turned away.
5
)
Parties are never split.
6
)
A plane will fly whenever it becomes full and a list of all parties on board will be
printed.
7
)
A plane may fly upon a command from t
he ticket clerk. Again a list of all parties on
board will be printed.
8
)
The ticket clerk will enter when a plane
flys and upon the return
of the plane
the
system will move people from the lounge to the plane in the order in which the parties
arrived, bu
t will skip parties that cannot fit and search for those which can fit. A list
of those parties boarding the plane will be printed.
9
)
When the airline shuts down for the night, the airplanes will continue to fly and return
(without the ticket clerk perfo
rming any action) until all parties in the lounge have
flown with appropriate messages being printed.
10)
Party n
ames do not have a maximum size so they must be handled as C
-
type strings
and dynamically allocated.
The commands the system will accept are
the following:
ALFA
<size>
BRAVO
<size>
LOUNGE
<size>
FLY
<airplane>
ARRIVE
<airplane> <party> <size>
SHUTDOWN
where:
<airplane> is either ALFA or BRAVO.
<party> is a name of unlimited length
.
<size> is an integer number
Fields in the input will
be separated by some amount of whitespace.
The ticket clerk is a terrible typist
Please i need the code and the corresponding header file.
Explanation / Answer
Program Code:
// Airlines.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<iostream>
#include<string>
using namespace std;
void flightA(int,string[],int,int, int);
void flightB(int,string[],int,int, int);
void fly(string,int,int,string[]);
void flightReturn(string,int,int,string[]);
int main()
{
string flightChoice;
char ch;
long int loungeA,loungeB;
long int Lsize1,Lsize1Left,Lsize2,Lsize2Left;
string passengerList1[100],passengerList2[100];
int i=0,j=0;
long int partySize;
bool flightAlfa=true;
bool flightAReturn=false,flightBReturn=false;
cout<<"Welcome to Tree Top Airways - TTA"<<endl;
cout<<"================================="<<endl;
cout<<"Alfa";
cin>>Lsize1;
Lsize1Left=Lsize1;
cout<<endl;
cout<<"BRAVO";
cin>>Lsize2;
Lsize2Left=Lsize2;
cout<<endl;
cout<<"LoungeA";
cin>>loungeA;
cout<<"LoungeB";
cin>>loungeB;
cout<<endl;
do
{
cout<<"FLY";
cin>>flightChoice;
if(flightChoice=="Alfa")
{
flightA(Lsize1,passengerList1,i,Lsize1Left,loungeA);
}
else if(flightChoice=="Bravo")
{
flightB(Lsize2,passengerList2,j,Lsize2Left,loungeB);
}
else
{
cout<<"Incorect flight choice";
exit(0);
}
}while(flightChoice!="N");
cout<<endl;
cout<<"Want to fly without filling (Y/N):";
cin>>ch;
if(ch=='y')
fly(flightChoice,0,0,0);
system("pause");
return 0;
}
void flightA(int Lsize1,string passengerList1[],int i,int Lsize1Left, int loungeA)
{
int partySize=0;
cout<<"Enter party name:";
cin>>passengerList1[i];
i++;
cout<<"Enter passenger size";
cin>>partySize;
if(partySize>Lsize1)
cout<<"Flight is full.";
else if(partySize>Lsize1Left)
{
if(partySize<loungeA)
{
cout<<"Please wait in the lounge";
loungeA-=partySize;
}
else
cout<<"You are requested to plan your trip later as there is not enough space in the flight and lounge.! Have a good day!";
}
else
{
cout<<"Your booking is confirmed! Have a safe journey!";
Lsize1Left-=partySize;
}
fly("Alfa", Lsize1Left, Lsize1, passengerList1);
}
void flightB(int Lsize2,string passengerList2[],int j,int Lsize2Left, int loungeB)
{
int partySize;
cout<<"Enter party name:";
cin>>passengerList2[j];
j++;
cout<<"Enter passenger size";
cin>>partySize;
if(partySize>Lsize2)
cout<<"Flight is full.";
else if(partySize>Lsize2Left)
{
if(partySize<loungeB)
{
cout<<"Please wait in the lounge";
loungeB-=partySize;
}
else
cout<<"You are requested to plan your trip later as there is not enough space in the flight and lounge.! Have a good day!";
}
else
{
cout<<"Your booking is confirmed! Have a safe journey!";
Lsize2Left-=partySize;
}
fly("Alfa", Lsize2Left, Lsize2, passengerList2);
}
void fly(string flightChoice,int LsizeLeft,int Lsize,string passengerList[])
{
if(LsizeLeft==0 && Lsize!=0)
{
if(flightChoice=="Alfa")
cout<<"Alfa Flight ready to fly";
else
cout<<"Bravo Flight ready to fly";
cout<<"Passenger List:";
for(int i=0;i<Lsize;i++)
{
cout<<passengerList[i];
}
}
else
cout<<"Flying as per clerk entery";
}
void flightReture(int lounge,string flightChoice,int LsizeLeft,int Lsize,string passengerList[])
{
if(lounge>0)
{
if(lounge<Lsize)
{
LsizeLeft=Lsize-lounge;
lounge=0;
//fly(flightChoice,LsizeLeft,Lsize,passengerList);
}
else if(lounge>Lsize ||lounge==Lsize)
{
lounge-=Lsize;
LsizeLeft=0;
fly(flightChoice,LsizeLeft,Lsize,passengerList);
}
else
{
cout<<"Flight available";
}
}
else
{
cout<<"Flight available";
}
}
Output:
Welcome to Tree Top Airways - TTA
=================================
Alfa125
BRAVO125
LoungeA70
LoungeB50
FLYBravo
Enter party name:sam
Enter passenger size23
Your booking is confirmed! Have a safe journey!Flying as per clerk enteryFLYAlfa
Enter party name:eva
Enter passenger size150
Flight is full.Flying as per clerk enteryFLYn