Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
1)
/*
* main.c
*
* Created on: 25 Dec 2022
* Author: P Rohit
*/
#include <stdio.h>
typedef enum
{
To_land,same_state,To_fly //to define all floor
}Air;
typedef struct{ // structure to define attributes
char* liver[3] ;
Air dir_to_go[3];
char* c_state_indentation[3];
}state;
state state_machine[3] = { // all state table
{{"Push","No_change","Pull"},{To_land,same_state,To_fly},{"To_land","same_state","To_fly"}},
{{"Push","No_change","Pull"},{To_land,same_state,To_fly},{"To_land","same_state","To_fly"}},
{{"Push","No_change","Pull"},{To_land,same_state,To_fly},{"To_land","same_state","To_fly"}}
};
Air current_state; //declaration
static int control_ip; // declaration
int main()
{
current_state = To_land;
while(1){ // to keep in infinite loop
printf("\n Currently Air Plane is in %s state \n ",state_machine[current_state].c_state_indentation[control_ip]);
printf("enter \n 0 to land \n 1 to be in same state \n 2 to Fly ");
fflush(stdout);
scanf("%d",&control_ip);
printf("\n current state of air plane : %s \n ",state_machine[current_state].c_state_indentation[control_ip]);
printf("\n liver is : %s \n ",state_machine[current_state].liver[control_ip]);
current_state = state_machine[current_state].dir_to_go[control_ip]; // to change current state
}
}