Challenge

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

implementing code for controlling 'retraction' and 'extension' of Airplanes landing gear:

program:

#include<stdio.h> //header file

typedef enum //creation of enumerated data type

{

gear_down,

checking_before_takeoff,

raising_gear,

gear_up,

checking_before_landing,

lowering_gear,

}gear;

gear gear_status; //declaration of enumerated datatype variable

typedef struct //creation of structure

{

char *limit_switch[2];

char *squat_switch[4];

gear gear_position[6];

char *l_position[4];

char *light[4];

char *direction_valve;

char *position;

}airoplane;

airoplane states[6]= //declaration and initialization of structure with each datatype

{

{{"close","open"},{"close","open"},{gear_down,checking_before_takeoff,raising_gear,gear_down,checking_before_landing,lowering_gear},{"landed","take0ff","airborne","landed"},{"green","green"},"up","gear_down"},

{{"close","open"},{"close","open"},{gear_down,checking_before_takeoff,raising_gear,gear_down,checking_before_landing,lowering_gear},{"landed","take0ff","airborne","landed"},{"red","red"},"up","checking_before_takeoff"},

{{"close","open"},{"close","open"},{gear_down,checking_before_takeoff,gear_up,checking_before_landing,lowering_gear,raising_gear},{"landed","take0ff","airborne","landing"},{"off","red"},"down","raising_gear"},

{{"open","open"},{"close","open"},{gear_down,checking_before_takeoff,raising_gear,checking_before_landing,gear_up,lowering_gear},{"landed","take0ff","airborne","landing"},{"red","red"},"enable","gear_up"},

{{"open","open"},{"close","open"},{lowering_gear,checking_before_takeoff,raising_gear,gear_up,checking_before_landing,lowering_gear},{"landing","take0ff","airborne","landed"},{"green","red"},"Down","cheking_before_landing"},

{{"close","open"},{"close","close"},{gear_down,checking_before_takeoff,raising_gear,gear_up,checking_before_landing,lowering_gear},{"landed","take0ff","airborne","landing"},{"red","red"},"up","lowering_gear"}

};

int main() //main function

{

gear_status=gear_down; //assigning value to the variable

int n,m,q; //declaration of integer variables

int p=1; //declaration and initialization of variable 'p'

while(1){ //unconditional loop

printf("present current_state: %s\n",states[gear_status].position);//to print in console

printf("\nenter the pilot_position\n"); //to read data from console

printf("down=1, raising=2, up=3, falling=4\n");

fflush(stdout);

scanf("%d",&n); //assigning value to 'n'

if(gear_status== 0) //conditional statement for gear_down

{

printf("enter squat switch \n close=0, open=1\n"); //to read data from console

fflush(stdout);

scanf("%d",&m); //assigning value to m

if(n != 2 && m != 1) //nested if condition

{

gear_status=gear_down;

}

}

q=m; //assigning 'm' value to 'q'

if( gear_status== 1) //conditional if statement for checking_before_landing

{

if(n != 3) //nested if conditional statement

{

printf("enter squat switch \n close=0, open=1\n"); //to read data from console

fflush(stdout);

scanf("%d",&m); //assigning value to 'm'

if(m == 0 || n==4) //nested if condition

{

states[gear_status].direction_valve="down";

states[gear_status].light[q]="red";

}

}

else

{

states[gear_status].direction_valve="up";

}

printf("time delay is 3 sec\n");

}

if( gear_status== 2 ) //condition statement for raising_gear

{

if(n != 4)

{

printf("enter limit switch \n close=0, open=1\n");

fflush(stdout);

scanf("%d",&p);

states[gear_status].direction_valve="disable";

if( p != 0)

{

gear_status=raising_gear;

}

else{

q=p;

}

}

else

{

states[gear_status].direction_valve="down";

}

}

if( gear_status== 5 ) //conditional statement for lowering_gear

{

if(n ==1)

{

printf("enter limit switch \n close=0, open=1\n");

fflush(stdout);

scanf("%d",&p);

states[gear_status].light[q]="green";

states[gear_status].direction_valve="down";

if( p != 1)

{

gear_status=lowering_gear;

}

else

{

q=n;

m=1;

}

}

else

{

states[gear_status].light[q]="red";

states[gear_status].direction_valve="up";

}

}

n=n-1;

//to print o/p on console

printf("plain is: %s\n",states[gear_status].l_position[n]);

printf("direction_valve: %s\n",states[gear_status].direction_valve);

printf("limit-switch: %s\n",states[gear_status].limit_switch[p]);

printf("squat-switch: %s\n",states[gear_status].squat_switch[m]);

printf("lighting: %s\n",states[gear_status].light[q]);

gear_status=states[gear_status].gear_position[n]; //assigning gear position to next statement

printf("\n");

}

return 0;

}

#include<stdio.h>           //header file


typedef enum                //creation of enumerated data type
{
	gear_down,
	checking_before_takeoff,
	raising_gear,
	gear_up,
	checking_before_landing,
	lowering_gear,
}gear;

gear gear_status;           //declaration of enumerated datatype variable

typedef struct              //creation of structure
{
	char *limit_switch[2];
	char *squat_switch[4];
	gear gear_position[6];
	char *l_position[4];
	char *light[4];
	char *direction_valve;
	char *position;
}airoplane;

airoplane states[6]=        //declaration and initialization of structure with each datatype
{
  {{"close","open"},{"close","open"},{gear_down,checking_before_takeoff,raising_gear,gear_down,checking_before_landing,lowering_gear},{"landed","take0ff","airborne","landed"},{"green","green"},"up","gear_down"},
  {{"close","open"},{"close","open"},{gear_down,checking_before_takeoff,raising_gear,gear_down,checking_before_landing,lowering_gear},{"landed","take0ff","airborne","landed"},{"red","red"},"up","checking_before_takeoff"},
  {{"close","open"},{"close","open"},{gear_down,checking_before_takeoff,gear_up,checking_before_landing,lowering_gear,raising_gear},{"landed","take0ff","airborne","landing"},{"off","red"},"down","raising_gear"},
  {{"open","open"},{"close","open"},{gear_down,checking_before_takeoff,raising_gear,checking_before_landing,gear_up,lowering_gear},{"landed","take0ff","airborne","landing"},{"red","red"},"enable","gear_up"},
  {{"open","open"},{"close","open"},{lowering_gear,checking_before_takeoff,raising_gear,gear_up,checking_before_landing,lowering_gear},{"landing","take0ff","airborne","landed"},{"green","red"},"Down","cheking_before_landing"},
  {{"close","open"},{"close","close"},{gear_down,checking_before_takeoff,raising_gear,gear_up,checking_before_landing,lowering_gear},{"landed","take0ff","airborne","landing"},{"red","red"},"up","lowering_gear"}
};

int main()                  //main function
{
	gear_status=gear_down;  //assigning value to the variable
	int n,m,q;              //declaration of integer variables
	int p=1;                //declaration and initialization of variable 'p'
	while(1){               //unconditional loop
		printf("present current_state: %s\n",states[gear_status].position);//to print in console
		printf("\nenter the pilot_position\n");                            //to read data from console
		printf("down=1, raising=2, up=3, falling=4\n");
		fflush(stdout);
		scanf("%d",&n);              //assigning value to 'n'

		if(gear_status== 0)          //conditional statement for gear_down
		{
			printf("enter squat switch \n close=0, open=1\n");         //to read data from console
			fflush(stdout);
			scanf("%d",&m);          //assigning value to m
			if(n != 2 && m != 1)     //nested if condition
			{
                gear_status=gear_down;
			}
		}
		q=m;                //assigning 'm' value to 'q'

		if( gear_status== 1)         //conditional if statement for checking_before_landing
		{
			if(n != 3)               //nested if conditional statement
			{
				printf("enter squat switch \n close=0, open=1\n");      //to read data from console
				fflush(stdout);
				scanf("%d",&m);      //assigning value to 'm'
				if(m == 0 || n==4)   //nested if condition
				{
					states[gear_status].direction_valve="down";
					states[gear_status].light[q]="red";
				}
			}
			else
			{
				states[gear_status].direction_valve="up";
			}
			printf("time delay is 3 sec\n");
		}

		if( gear_status== 2 )        //condition statement for raising_gear
		{
			if(n != 4)
			{
				printf("enter limit switch \n close=0, open=1\n");
				fflush(stdout);
				scanf("%d",&p);
				states[gear_status].direction_valve="disable";
				if( p != 0)
				{
					gear_status=raising_gear;
				}
				else{
					q=p;
				}
			}
			else
			{
				states[gear_status].direction_valve="down";
			}
		}

		if( gear_status== 5 )        //conditional statement for lowering_gear
		{
			if(n ==1)
			{
				printf("enter limit switch \n close=0, open=1\n");
				fflush(stdout);
				scanf("%d",&p);
				states[gear_status].light[q]="green";
				states[gear_status].direction_valve="down";
				if( p != 1)
				{
					gear_status=lowering_gear;
				}
				else
				{
					q=n;
					m=1;
				}
			}
			else
			{
				states[gear_status].light[q]="red";
				states[gear_status].direction_valve="up";
			}
		}

		n=n-1;
		//to print o/p on console
		printf("plain is: %s\n",states[gear_status].l_position[n]);
		printf("direction_valve: %s\n",states[gear_status].direction_valve);
		printf("limit-switch: %s\n",states[gear_status].limit_switch[p]);
		printf("squat-switch: %s\n",states[gear_status].squat_switch[m]);
		printf("lighting: %s\n",states[gear_status].light[q]);
		gear_status=states[gear_status].gear_position[n];                   //assigning gear position to next statement
		printf("\n");
	}
	return 0;
}

the output of the program is:

output:

present current_state: gear_down

enter the pilot_position
down=1, raising=2, up=3, falling=4
2
enter squat switch 
 close=0, open=1
1
plain is: take0ff
direction_valve: up
limit-switch: open
squat-switch: open
lighting: green

present current_state: checking_before_takeoff

enter the pilot_position
down=1, raising=2, up=3, falling=4
3
time delay is 3 sec
plain is: airborne
direction_valve: up
limit-switch: open
squat-switch: open
lighting: red

present current_state: raising_gear

enter the pilot_position
down=1, raising=2, up=3, falling=4
3
enter limit switch 
 close=0, open=1
0
plain is: airborne
direction_valve: disable
limit-switch: close
squat-switch: open
lighting: off

present current_state: gear_up

enter the pilot_position
down=1, raising=2, up=3, falling=4
4
plain is: landing
direction_valve: enable
limit-switch: open
squat-switch: open
lighting: red

present current_state: cheking_before_landing

enter the pilot_position
down=1, raising=2, up=3, falling=4
1
plain is: landing
direction_valve: Down
limit-switch: open
squat-switch: open
lighting: red

present current_state: lowering_gear

enter the pilot_position
down=1, raising=2, up=3, falling=4
1
enter limit switch 
 close=0, open=1
1
plain is: landed
direction_valve: down
limit-switch: open
squat-switch: close
lighting: green

present current_state: gear_down

enter the pilot_position
down=1, raising=2, up=3, falling=4
2
enter squat switch 
 close=0, open=1
1
plain is: take0ff
direction_valve: up
limit-switch: open
squat-switch: open
lighting: green

present current_state: checking_before_takeoff

enter the pilot_position
down=1, raising=2, up=3, falling=4
4
enter squat switch 
 close=0, open=1
0
time delay is 3 sec
plain is: landed
direction_valve: down
limit-switch: open
squat-switch: close
lighting: red

present current_state: gear_down

enter the pilot_position
down=1, raising=2, up=3, falling=4
2
enter squat switch 
 close=0, open=1
1
plain is: take0ff
direction_valve: up
limit-switch: open
squat-switch: open
lighting: green

present current_state: checking_before_takeoff

enter the pilot_position
down=1, raising=2, up=3, falling=4
3
time delay is 3 sec
plain is: airborne
direction_valve: up
limit-switch: open
squat-switch: open
lighting: red

present current_state: raising_gear

enter the pilot_position
down=1, raising=2, up=3, falling=4
4
plain is: landing
direction_valve: down
limit-switch: open
squat-switch: open
lighting: red

present current_state: cheking_before_landing

enter the pilot_position
down=1, raising=2, up=3, falling=4
1
plain is: landing
direction_valve: Down
limit-switch: open
squat-switch: open
lighting: red

present current_state: lowering_gear

enter the pilot_position
down=1, raising=2, up=3, falling=4
2
plain is: take0ff
direction_valve: up
limit-switch: open
squat-switch: close
lighting: red

present current_state: checking_before_takeoff

enter the pilot_position
down=1, raising=2, up=3, falling=4
4
enter squat switch 
 close=0, open=1
1
time delay is 3 sec
plain is: landed
direction_valve: down
limit-switch: open
squat-switch: open
lighting: red

present current_state: gear_down

enter the pilot_position
down=1, raising=2, up=3, falling=4
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.