Challenge

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

Q1.

C-Program:

#include 
typedef enum
{
	Before_take_off_state = 0,
	Before_landing_state,
	Gear_down_state,
	Lowering_gear_state,
	Raising_gear_state,
	Gear_up_state
} state_type; // different states of the Aeroplane as per the state diagram //

typedef struct
{
	state_type states[2]; //structure  variables
	char* plane_state[2];
}state;

state state_machine[6] ={
		{{Raising_gear_state, Gear_down_state}, {"Raising gear", "Gear down"}},
		{{Lowering_gear_state}, {"Loweing 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"); //Taking user input about pilot lever//
	fflush(stdout);
	scanf("%d", &pilotlever);
	printf("please enter the direction value: \n0 for direction down\n1 for direction up\n"); //taking user input about direction//
	fflush(stdout);
	scanf("%d", &directionvalue);
	printf("please enter the lights: \n0 for red\n1 for green\n2 for lights off\n"); //taking user input about lights//
	fflush(stdout);
	scanf("%d", &lights);
	printf("please enter squat switch value: \n0 for squat switch close\n1 for squat switch open\n"); //taking user input about squat switches//
	fflush(stdout);
	scanf("%d", &squatswitch);
	printf("please enter limit switch value: \n0 for limit switch close\n1 for limit switch open\n"); //taking user input about limit switches//
	fflush(stdout);
	scanf("%d", &limitswitch);
	printf("please enter the control value: \n0 for disabled\n1 for enabled\n"); //taking user input about control values//
	fflush(stdout);
	scanf("%d", &control);

	if((pilotlever==2 && squatswitch==1)||lights==1) //condition for state transition from gear down to before take off//
	{
		printf("\n the plane is in before take off state \n");
		fflush(stdout);
	}
	else if ((pilotlever==1 || directionvalue==1) && lights==0) //condition for state transition from before take off to raising gear//
	{
		printf("\n the plane is in raising gear state \n");
		fflush(stdout);
	}
	else if ((limitswitch==0 || lights==2) && control==0) //condition for state transition from raising gear t0 gear up state//
	{
		printf("\n the plane is in gear up state \n");
		fflush(stdout);
	}
	else if (pilotlever==3 || lights==0) //condition for state transition from raising gear to checking before landing//
	{
		printf("\n plane is in checking for landing state \n");
		fflush(stdout);
	}
	else if ((pilotlever==3 || control==1) && lights==0) //condition for state transition from gear up to checking before landing//
	{
		printf("\n plane is in checking for landing state \n");
		fflush(stdout);
	}
	else if (pilotlever==0 || directionvalue==0) //condition for state transition from checking before landing to lowering gear state//
	{
		printf("\n plane is in lowering gear state \n");
		fflush(stdout);
	}
	else if (pilotlever==2|| lights==0) //condition for state transition from lowering gear to checking before take off//
	{
		printf("\n plane is in checking before take off state \n");
		fflush(stdout);
	}
	else if (squatswitch==0 || pilotlever==3|| lights==0) // condition for state transition from checking before take off to gear down
	{
		printf("\n plane is in gear down state \n");
		fflush(stdout);
	}
	else if (limitswitch==1 || lights==1) // condition for state transition from lowering gear to gear down
	{
		printf("\n plane is in gear down state \n");
		fflush(stdout);
	}
	return 0;
}

Result:

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.