Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
Project 2
#include <stdio.h>
typedef enum
{
STATE_GROUNDED,
STATE_RAISING,
STATE_LOWERED,
STATE_EXTENDING,
STATE_RETRACTING
} State; //enum to represent different states of landing gear
void raiseLandingGear()
{
printf("Raising the landing gear...\n");
// Simulate raising process (e.g., control hydraulic valves)
}
void lowerLandingGear()
{
printf("Lowering the landing gear...\n");
// Simulate lowering process (e.g., control hydraulic valves)
}
void extendLandingGear()
{
printf("Extending the landing gear...\n");
// Simulate extending process (e.g., control hydraulic valves)
}
void retractLandingGear()
{
printf("Retracting the landing gear...\n");
// Simulate retracting process (e.g., control hydraulic valves)
}
int main()
{
State currentState = STATE_GROUNDED; //To represent initial state of landing gear when airplane is on the ground
char input;
printf("Airplane's Landing Gear Control System\n");
while (1) //To run the code without terminating, user has to terminate manually
{
switch (currentState) //Switch statement based on current status of airplane
{
case STATE_GROUNDED:
printf("Airplane is on the ground. Press 'R' to raise the landing gear: ");
break;
case STATE_LOWERED:
printf("Airplane is airborne. Press 'E' to extend the landing gear or 'L' to lower it: ");
break;
default:
break;
}
fflush(stdout);
scanf(" %c", &input); //To get input from console for required operation
switch (currentState) //Switch statement for transition from one state to another
{
case STATE_GROUNDED:
if (input == 'R' || input == 'r')
{
currentState = STATE_RAISING;
raiseLandingGear();
currentState = STATE_LOWERED;
}
break;
case STATE_LOWERED:
if (input == 'E' || input == 'e')
{
currentState = STATE_EXTENDING;
extendLandingGear();
currentState = STATE_LOWERED;
}
else if (input == 'L' || input == 'l')
{
currentState = STATE_RETRACTING;
retractLandingGear();
currentState = STATE_GROUNDED;
}
break;
default:
break;
}
}
return (0);
}
