Challenge

Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear

Offline

Implement the code for controlling the retraction and extension of Airplane's landing gear

Program:

/* Program for Airplanes landing gear */
#include
#include
typedef enum {
gear_down,
checking_before_take_off,
rising_gear,
gear_up,
checking_before_landing,
lowering_gear
//checking_before_landing,
//raising_gear
//checking_before_take_off,
//checking_before_landing
}state_type;//naming the enum
typedef enum {
close,
open
//close
}Switch;//naming the enum
//typedef enum Light{
//off,
//red,
//green
//}color;
typedef enum {
lowering,
rising

}Lever;//naming the enum

static volatile Switch Squat;                             //using the enum as datatype
//static volatile int Color;
static volatile Lever Pilot;                                //using the enum as datatype
state_type current_state;                               //using the enum as datatype

void init_state_machine()
{
current_state=gear_down;
char light[100]="green";                               //giving output to print output
printf("the position of the gear is %s\n",light);


}
void Gear_down()
{
current_state=gear_down;
printf("pilot_lever and squat_switch:");
fflush(stdout);
scanf("%d\n %d",&Pilot,&Squat);
if(Pilot==rising&&Squat==open){//condition checking two at a time
char pilot_lever[100]="Rising";                           //giving output to print output
char light[100]="Green";                                   //giving output to print output
//pilot_lever[100]="Rising";
char squat_switch[100]="Open";                        //giving output to print output
printf("light:%s\n",light);
printf("pilot lever:%s\n", pilot_lever);
printf("squat_switch:%s",squat_switch);
current_state=checking_before_take_off;
}
if(Pilot==lowering&&Squat==close){
char light[100]="Red";                                     //giving output to print output
char pilot_lever[100]="Lowering";                    //giving output to print output
//char light[100]="Red";
//char pilot_lever[100]="Rising";
char squat_switch[100]="Close";                     //giving output to print output
printf("light:%s\n",light);
printf("pilot_lever:%s\n",pilot_lever);
printf("squat_switch:%s",squat_switch);
current_state=gear_down;

}

}
void Checking_Before_take_off(){
current_state=checking_before_take_off;
printf("\npilot_lever and squat_switch:");
fflush(stdout);
scanf("%d\n %d",&Pilot, &Squat);
if(Pilot==rising&&Squat==close){//condition checking two at a time
char light[100]="Red";                                     //giving output to print output
char pilot_lever[100]="Rising";                         //giving output to print output
char squat_switch[100]="Closed";                    //giving output to print output
printf("light:%s\n",light);
printf("pilot lever:%s\n",pilot_lever);
printf("squat_switch:%s",squat_switch);
current_state=rising_gear;
}


}
void Rising_gear(){
current_state=rising_gear;
printf("\npilot_lever and squat_switch:");
fflush(stdout);
scanf("%d\n %d",&Pilot, &Squat);
if(Pilot==rising&&Squat==close){//condition checking two at a time
char light[100]="Off";                                                 //giving output to print output
char pilot_lever[100]="Rising";                                    //giving output to print output
char squat_switch[100]="Closed";                               //giving output to print output
printf("light:%s\n",light);
printf("pilot lever:%s\n",pilot_lever);
printf("squat_switch:%s",squat_switch);
current_state=gear_up;
}
if(Pilot==lowering&&Squat==close){
char light[100]="Red";                                               //giving output to print output
char pilot_lever[100]="Lowering";                               //giving output to print output
char squat_switch[100]="Closed";                               //giving output to print output
printf("light:%s\n",light);
printf("pilot lever:%s\n",pilot_lever);
printf("squat_switch:%s",squat_switch);
current_state=checking_before_landing;

}
}
void Gear_up(){
current_state=gear_up;
printf("\npilot_lever and squat_switch:");
fflush(stdout);
scanf("%d\n %d",&Pilot, &Squat);
if(Pilot==lowering&&Squat==close){//condition checking two at a time
char light[100]="Red";                                    //giving output to print output
char pilot_lever[100]="Lowering";                   //giving output to print output
char squat_switch[100]="Closed";                   //giving output to print output
printf("light:%s\n",light);
printf("pilot lever:%s\n",pilot_lever);
printf("squat_switch:%s",squat_switch);
current_state=checking_before_landing;
}
}
void Checking_before_landing(){
current_state=checking_before_landing;
printf("\npilot_lever and squat_switch:");
fflush(stdout);
scanf("%d\n %d",&Pilot, &Squat);
if(Pilot==lowering&&Squat==close){//condition checking two at a time
char light[100]="Red";                                      //giving output to print output
char pilot_lever[100]="Lowering";                      //giving output to print output
char squat_switch[100]="Closed";                     //giving output to print output
printf("light:%s\n",light);
printf("pilot lever:%s\n",pilot_lever);
printf("squat_switch:%s",squat_switch);
current_state=lowering_gear;
}

}
void Lowering_gear(){
current_state=lowering_gear;
printf("\npilot_lever and squat_switch:");
fflush(stdout);
scanf("%d\n %d",&Pilot, &Squat);
if(Pilot==rising&&Squat==open){//condition checking two at a time
char light[100]="Green";                                    //giving output to print output
char pilot_lever[100]="Rising";                            //giving output to print output
char squat_switch[100]="Opened";                       //giving output to print output
printf("light:%s\n",light);
printf("pilot lever:%s\n",pilot_lever);
printf("squat_switch:%s",squat_switch);
current_state=gear_down;
}
if(Pilot==rising&&Squat==open){
char light[100]="Red";                                           //giving output to print output
char pilot_lever[100]="Rising";                              //giving output to print output
char squat_switch[100]="Opened";                       //giving output to print output
printf("light:%s\n",light);
printf("pilot lever:%s\n",pilot_lever);
printf("squat_switch:%s",squat_switch);
current_state=checking_before_take_off;
}


}
static void(*state_table[])(void)={Gear_down,Checking_Before_take_off,Rising_gear,Gear_up,Checking_before_landing,
Lowering_gear,};                                                 //here we mentioning in small letters to calling
//functions
int main()
{
init_state_machine();
while(1){
state_table[current_state]();

}
return 0;
}

Output:

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.