Challenge

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

project 2:-

#include<stdio.h>

#include<stdlib.h>

typedef enum //system state declaration

{

Gear_Down_State,

Before_Take_Off_State = 0,

Before_Landing_State,

Lowering_Gear_State,

Raising_Gear_State,

Gear_Up_State

}state_type;

typedef struct // state table attributes declaration

{

state_type states[6];

char* plane_state[6];

}state;

// state table formation using array of structure

state state_machine[6]={

{{Raising_Gear_State,Gear_Down_State},{"Raising Gear","Gear Down"}},

{{Lowering_Gear_State},{"Lowering Gear"}},

{{Before_Take_Off_State},{"Before Take Off"}},

{{Gear_Down_State,Before_Take_Off_State},{"Gear Down","Before Take Off"}},

{{Gear_Up_State,Before_Landing_State},{"Gear Up","Before Landing"}},

{{Before_Landing_State},{"Before Landing"}}

};

int currentstate;

int pilotlever, directionvalue, lights, limitswitch, squatswitch, control;

int main()

{

printf("enter the Pilot's gear value:\n0 for gear Down\n1 for gear Up\n2 for gear Rising\n3 for gear Falling\n");

fflush(stdout);

scanf("%d",&pilotlever);

printf("enter the Direction value:\n0 for Direction Down\n1 for Direction Up\n");

fflush(stdout);

scanf("%d",&directionvalue);

printf("enter the lights:\n0 for Red\n1 for Green\n2 for Lights Off\n");

fflush(stdout);

scanf("%d",&lights);

printf("enter Squat Switch value:\n0 for Squat Switch close\n1 for Squat Switch open\n");

fflush(stdout);

scanf("%d",&squatswitch);

printf("enter Limit Switch value:\n0 for Limit Switch close\n1 for Limit Switch open\n");

fflush(stdout);

scanf("%d",&limitswitch);

printf("enter the Control value:\n0 for Disabled\n1 for Enabled\n");

fflush(stdout);

scanf("%d",&control);

if((pilotlever==2 && squatswitch==1)||lights==1)

printf("\nAeroplane is in Before Take Off State\n");

else

if((pilotlever==1 || directionvalue==1) && lights==0)

printf("\nAeroplane is in Raising Gear State\n");

else

if((limitswitch==0 || lights==2) && control==0)

printf("\nAeroplane is in Gear Up State\n");

else

if(pilotlever==3 || lights==0)

printf("\nAeroplane is in Checking for Landing State\n");

else

if((pilotlever==3 || control==1) && lights==0)

printf("\nAeroplane is in Checking for Landing State\n");

else

if(pilotlever==0 || directionvalue==0)

printf("\nAeroplane is in Lowering Gear State\n");

else

if(pilotlever==2 || lights==0)

printf("\nAeroplane is in Checking before Take Off State\n");

else

if(squatswitch==0 || pilotlever==3 || lights==0)

printf("\nAeroplane is in Gear Down State\n");

else

if(limitswitch==1 || lights==1)

printf("\nAeroplane is in Gear Down State\n");

return 0;

}

output:-

enter the Pilot's gear value:

0 for gear Down

1 for gear Up

2 for gear Rising

3 for gear Falling

red green

enter the Direction value:

0 for Direction Down

1 for Direction Up

enter the lights:

0 for Red

1 for Green

2 for Lights Off

enter Squat Switch value:

0 for Squat Switch close

1 for Squat Switch open

enter Limit Switch value:

0 for Limit Switch close

1 for Limit Switch open

enter the Control value:

0 for Disabled

1 for Enabled

Aeroplane is in Gear Up State

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.