Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
The below code is written in C++,This is an implementation of FSM which is Finite State Machine
#include <iostream>
using namespace std;
#include <unistd.h> //Library Delay Timer
string lights,lever; //global variable declaration
void setLightsRed(){ //Indicates take off, setting lights to Red
lights = "Red";
}
void setLightsGreen(){ //Indicates Landing, setting lights to Red
lights= "Green";
}
void setLightsOff(){ //Dimming the lights in the Airoplane
lights = "Off";
}
string getLights(){ //Get the current status of Lights Red/Green
return lights;
}
void setLeverUp(){ //To change the lever to Up
lever = "Up";
cout << "C:-LEVER STATUS UP,Over!"<<endl;
}
void setLeverDown(){ //To change the lever to Down
lever = "Down";
}
string getLever(){ //Get the lever status
return lever;
}
string takeOff(){ //Function for Take Off Phase
if(getLights() != "Red" ){
return "C:-Can't take off because lights are not red\n";
}else{
setLeverUp();
cout<<"A:-Dear Passengers, we are ready to take off to Bengaluru\n";
setLightsOff();
cout<<"A:-We will be dimming the lights now\n";
return """C:-Take Off Success, Over!\n\n";
}
}
string PrintAltitude(){ //To print the Altitude
return "A:-Dear Passenges,We are flying at an altitude of 10000 metres from the sea level,now we are preparing for landing\n";
}
string landing(){ //Function for Landing Phase
if(getLights() != "Green" ){
return "C:-Can't land because lights are not Green\n";
}else{
setLeverDown();
cout<<PrintAltitude();
return "C:-Landing Success, Over!\n";
}
}
int main()
{
char command;
string l;
/* A=Pilot gives Announcement to Passengers, C=Pilot takes Command from ATC */
cout<<"Take Off Phase\n";
cout<<"Enter the command to take off(R or G): ";
cin >> command;
if (command == 'R'){ //checking the command and setting to Red
setLightsRed();
}
cout<<takeOff();
sleep(2); //Delay Timer
cout<<"Landing Phase\n";
cout<<"Enter the command to Land(R or G): ";
cin >> command;
if (command == 'G'){ //checking the command and setting to Green
setLightsGreen();
}
l = landing();
cout<<l; //Printing the status of Landing
if(l == "C:-Landing Success, Over!\n"){
cout<<"A:-We have reached Bengaluru,Thank you for travelling with Singapore Airlines, :)\n";
}
return 0;
}