Challenge

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

CODING:

#include <stdio.h>
#include <stdlib.h>
typedef enum
{
// Initialization
Before_Take_Off_State=0,
Before_Landing_State,
Gear_Down_State,
Lowering_Gear_State,
Raising_Gear_State,
Gear_Up_State,
}state_type;
// Define structure
typedef struct
{
state_type states[10];
char* plane_state[10];
}state;
state state_machine[10]={
{{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 LEVER VALUE:\n 0 for Lever Down\n 1 for Lever up\n 2 for Lever Raising\n 3 for Lever Falling\n");
scanf("%d", &pilotlever);
printf("ENTER THE DIRECTION VALUE:\n 0 for Direction Down \n 1 for Direction Up\n");
scanf("%d", &directionvalue);
printf("ENTER THE LIGHT SIGNAL:\n 0 for Red\n 1 for Green\n 2 for Lights Off\n");
scanf("%d",&lights);
printf("ENTER THE SQUATSWITCH VALUE:\n 0 for squad switch close\n 1 for squad switch open\n");
scanf("%d",&squatswitch);
printf("ENTER THE LIMITSWITCH VALUE:\n 0 for limit switch close\n 1 for limit switch open\n");
scanf("%d",&limitswitch);
printf("ENTER THE CONTROL VALUE:\n 0 for Disabled\n 1 for Enabled\n");
scanf("%d",&control);
if((pilotlever==2&&squatswitch==1)||lights==1)
printf("\n The plane is in Before take off state\n");
else
if((pilotlever==1||directionvalue==1)&&lights==0)
printf("\n The plane is in Raising Gear state\n");
else
if((limitswitch==0||lights==2)&&control==0)
printf("\n The plane is in Gear up state\n");
else
if(pilotlever==3||lights==0)
printf("\n Plane is in Checking for Landing state\n");
else
if((pilotlever==3||control==1)&&lights==0)
printf("\n plane is in checking for landing state\n");
else
if(pilotlever==0||directionvalue==0)
printf("\nPlane is in Lowering Gear State\n");
else
if(pilotlever==2||lights==0)
printf("\n Plane is in checking before Take off state\n");
else
if(squatswitch==0||pilotlever==3||lights==0)
printf("\n Plane is in Gear Down State\n");
else
if(limitswitch==1||lights==1)
printf("\n Plane is in Gear Down State\n");
return 0;
}

OUTPUT:

ENTER THE PILOT LEVER VALUE:
0 for Lever Down
1 for Lever up
2 for Lever Raising
3 for Lever Falling
1
ENTER THE DIRECTION VALUE:
0 for Direction Down
1 for Direction Up
1
ENTER THE LIGHT SIGNAL:
0 for Red
1 for Green
2 for Lights Off
1
ENTER THE SQUATSWITCH VALUE:
0 for squad switch close
1 for squad switch open
1
ENTER THE LIMITSWITCH VALUE:
0 for limit switch close
1 for limit switch open
1
ENTER THE CONTROL VALUE:
0 for Disabled
1 for Enabled
1

The plane is in Before take off 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.