Challenge

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

#include<stdio.h>
#include<stdlib.h>

typedef enum
{
Gear_Down_State,
Before_Take_Off_State,
Before_Landing_State,
Lowering_Gear_State,
Raising_Gear_State,
Gear_Up_State
}state_type;

typedef struct
{
state_type states[6];
char* plane_state[6];
}state;

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");
fflush(stdout);
}

else if((pilotlever==1 || directionvalue==1) && lights==0)
{
printf("\nAeroplane is in Raising Gear State\n");
fflush(stdout);
}

else if((limitswitch==0 || lights==2) && control==0)
{
printf("\nAeroplane is in Gear Up State\n");
fflush(stdout);
}


else if(pilotlever==3 || lights==0)
{
printf("\nAeroplane is in Checking for Landing State\n");
fflush(stdout);
}

else if((pilotlever==3 || control==1) && lights==0)
{
printf("\nAeroplane is in Checking for Landing State\n");
fflush(stdout);
}

else if(pilotlever==0 || directionvalue==0)
{
printf("\nAeroplane is in Lowering Gear State\n");
fflush(stdout);
}


else if(pilotlever==2 || lights==0)
{
printf("\nAeroplane is in Checking before Take Off State\n");
fflush(stdout);
}


else if(squatswitch==0 || pilotlever==3 || lights==0)
{
printf("\nAeroplane is in Gear Down State\n");
fflush(stdout);
}


else if(limitswitch==1 || lights==1)
{
printf("\nAeroplane is in Gear Down State\n");
fflush(stdout);
}

}
return 0;
}

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.