Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
Code:
#include <stdio.h>
#include <stdlib.h>
typedef enum
{
Before_Take_Off_State = 0,
Before_Landing_State,
Gear_Down_State,
Lowering_Gear_State,
Raising_Gear_State,
Gear_Up_State
}state_type;
typedef struct
{
state_type states[4];
char* plane_state[4];
}state;
state state_machine[4]={
{{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("Please enter the Pilot's lever value:\n0 for Lever Down\n1 for Lever Up\n2 for Lever Rising\n3 for Lever Falling\n");
scanf("%d",&pilotlever);
printf("Please enter the Direction value:\n0 for Direction Down\n1 for Direction Up\n");
scanf("%d",&directionvalue);
printf("Please enter the lights:\n0 for Red\n1 for Green\n2 for Lights Off\n");
scanf("%d",&lights);
printf("Please enter Squat Switch value:\n0 for Squat Switch close\n1 for Squat Switch open\n");
scanf("%d",&squatswitch);
printf("Please enter Limit Switch value:\n0 for Limit Switch close\n1 for Limit Switch open\n");
scanf("%d",&limitswitch);
printf("Please enter the Control value:\n0 for Disabled\n1 for Enabled\n");
scanf("%d",&control);
if((pilotlever==2 && squatswitch==1)||lights==1)
printf("\nThe Plane is in Before Take Off State\n");
else
if((pilotlever==1 || directionvalue==1) && lights==0)
printf("\nThe Plane is in Raising Gear State\n");
else
if((limitswitch==0 || lights==2) && control==0)
printf("\nThe Plane is in Gear Up State\n");
else
if(pilotlever==3 || lights==0)
printf("\nPlane is in Checking for Landing State\n");
else
if((pilotlever==3 || control==1) && lights==0)
printf("\nPlane 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("\nPlane is in Checking before Take Off State\n");
else
if(squatswitch==0 || pilotlever==3 || lights==0)
printf("\nPlane is in Gear Down State\n");
else
if(limitswitch==1 || lights==1)
printf("\nPlane is in Gear Down State\n");
return 0;
}