Challenge

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

#include<stdio.h>//preprocessor directive
#include<stdlib.h>
typedef enum//user defined function for gear position
{
down,//0
raising,//1
up,//2
falling//3
}liverpos;
typedef enum//user defined function for limit switch
{
open,//0
close//1

}limit;

typedef enum//user defined function for limit switch
{
closee,
openn
}squat;
typedef enum//user defined function for limit switch
{
working,
malfunctioning
}hydra;

typedef struct finite//structure function
{
char *currentstatus;//members ofstructure
char *light;
char *nextstate;
char *gearstate;
int squatsw;
int limitsw;
int hydralic;

}state;

state machine[6]={{"plane is parked at a bay","green","Enter '0' for check before takeoff","gear is down",1,0,0},//assigning value directly to structure member
{"plane ready to takeoff","red","Enter '1' to rise the gear ","gear is down",1,0,0},
{"taking off","red","Enter '2' for to continue airborne ","gear is up",1,1,0},
{"plane is airborne ","off","Enter '3' to check for landing","gear is up",1,1,1},
{"checking for landing at a station","red","Enter '0' to lower the gear","gear is down",1,0,0},
{"plane is successfully landed","green","Enter '0' to park the plane","gear is down",0,0,0}};

void geardown()//function definition
{
int lp,ss;
printf("\n Enter the lever position ::");
scanf("%d",&lp);
printf("enter the squat switch condition: ");
scanf("%d",&ss);
if(lp==down && ss==openn && machine[0].hydralic==working)//if condtion
{
printf("\n Light status is::%s",machine[0].light);//printing the structure objects
printf("\n Current status ::%s",machine[0].currentstatus);
printf("\n Gear status ::%s",machine[0].gearstate);
printf("\n Next state ::%s\n",machine[0].nextstate);
checkbeforetakeoff();//condition is true then function goes to next corresponding function
}
else
{
printf("\n Next state ::%s\n",machine[0].nextstate);
geardown();//if condition is false it get back to its current function
}
}
void checkbeforetakeoff()//function definition
{
int lp;
printf("\n Enter the lever position :: ");
scanf("%d",&lp);
if(lp==down && machine[1].squatsw==openn && machine[1].limitsw==open && machine[1].hydralic==working)//if condition
{
printf("\n Light status is ::%s",machine[1].light);//printing the structure objects
printf("\n Current status ::%s",machine[1].currentstatus);
printf("\n Gear status ::%s",machine[1].gearstate);
printf("\n Next state ::%s\n",machine[1].nextstate);
gearrising();//condition is true then function goes to next corresponding function
}
else
{
printf("\n Please check the given input .....ERROR");
printf("\n Next state ::%s\n",machine[0].nextstate);
geardown();//if condition is false it get back to its current function
}
}
void gearrising()//function definition
{
int lp;
printf("\n Enter the lever position :: ");
scanf("%d",&lp);
if(lp==raising &&machine[2].squatsw==openn && machine[2].limitsw==close && machine[2].hydralic==working)//if condition
{
printf("\n Light status is ::%s",machine[2].light);//printing structure member
printf("\n Current status ::%s",machine[2].currentstatus);
printf("\n Gear status ::%s",machine[2].gearstate);
printf("\n Next state ::%s\n",machine[2].nextstate);
gearup();//condition is true then function goes to next corresponding function
}
else if(lp==falling )
{
printf("\n Gear is falling......malfunction");
printf("\n Next state ::%s\n",machine[4].nextstate);
checkbeforelanding();
}
else
{
printf("\n Next state ::%s\n",machine[1].nextstate);
gearrising();//if condition is false it get back to its current function
}
}
void gearup()//function definition
{
int lp,ls;
printf("\n Enter the lever position :: ");
scanf("%d",&lp);
printf("enter the limit switch condition: ");
scanf("%d",&ls);
if(lp==up &&machine[3].squatsw==openn && ls==close && machine[3].hydralic==malfunctioning)//if condition
{
printf("\n Light status is ::%s",machine[3].light);//printing structure member
printf("\n Current status ::%s",machine[3].currentstatus);
printf("\n Gear status ::%s",machine[3].gearstate);
printf("\n Next state ::%s\n",machine[3].nextstate);
checkbeforelanding();//condition is true then function goes to next corresponding function
}
else
{
printf("\n Next state ::%s\n",machine[2].nextstate);
gearup();//if condition is false it get back to its current function
}
}

void checkbeforelanding()//function definition
{
int lp;
printf("\n Enter the lever position :: ");
scanf("%d",&lp);
if(lp==falling && machine[4].squatsw==openn && machine[4].limitsw==open && machine[2].hydralic==working)//if condition
{
printf("\n Light status is ::%s",machine[4].light);//printing structure member
printf("\n Current status ::%s",machine[4].currentstatus);
printf("\n Gear status ::%s",machine[4].gearstate);
printf("\n Next state ::%s\n",machine[4].nextstate);
gearlanding();//condition is true then function goes to next corresponding function
}
else
{
printf("\n Please check the given input .....ERROR");
printf("\n Next state ::%s\n",machine[3].nextstate);
gearup();//if condition is false it get back to its current function
}
}
void gearlanding()//function definition
{
int lp;
printf("\n Enter the lever position : ");
scanf("%d",&lp);
if(lp==down && machine[5].squatsw==closee &&machine[5].limitsw==open && machine[2].hydralic==working)
{
printf("\n Light status is ::%s",machine[5].light);//printing structure member
printf("\n Current status ::%s",machine[5].currentstatus);
printf("\n Gear status ::%s",machine[5].gearstate);
printf("\n Next state ::%s\n",machine[5].nextstate);
geardown();//condition is true then function goes to next corresponding function
}
else if(lp==raising)
{
printf("\n Due to bad weather, pilot decided to not to land on bay ");
printf("\n Next state ::%s\n",machine[4].nextstate);
checkbeforetakeoff();//condition is true then function goes to next corresponding function
}
else
{
printf("\n Next state ::%s\n",machine[4].nextstate);
gearlanding();//if condition is false it get back to its current function
}
}

int main()//main function
{
printf("Lever positions:: \n\n 0=Down\n 1=Raising\n 2=Up\n 3=Falling \n\n Squat switch is always '1'(Open) Except gear landing \n Limit switch is '1'(close) only for gear rising and gear up condition \n");
geardown();//function call
}

OUTPUT::

Lever positions::

0=Down
1=Raising
2=Up
3=Falling

Squat switch is always '1'(Open) Except gear landing
Limit switch is '1'(close) only for gear rising and gear up condition

Enter the lever position ::0
enter the squat switch condition: 1

Light status is::green
Current status ::plane is parked at a bay
Gear status ::gear is down
Next state ::Enter '0' for check before takeoff

Enter the lever position :: 0

Light status is ::red
Current status ::plane ready to takeoff
Gear status ::gear is down
Next state ::Enter '1' to rise the gear

Enter the lever position :: 1

Light status is ::red
Current status ::taking off
Gear status ::gear is up
Next state ::Enter '2' for to continue airborne

Enter the lever position :: 2
enter the limit switch condition: 1

Light status is ::off
Current status ::plane is airborne
Gear status ::gear is up
Next state ::Enter '3' to check for landing

Enter the lever position :: 3

Light status is ::red
Current status ::checking for landing at a station
Gear status ::gear is down
Next state ::Enter '0' to lower the gear

Enter the lever position : 0

Light status is ::green
Current status ::plane is successfully landed
Gear status ::gear is down
Next state ::Enter '0' to park the plane

Enter the lever position ::0
enter the squat switch condition: 1

Light status is::green
Current status ::plane is parked at a bay
Gear status ::gear is down
Next state ::Enter '0' for check before takeoff

Enter the lever position ::

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.