Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
#include
#include "landing_gear_control.h" // Include the custom header file
int main() {
GearState currentState = CHECK_BEFORE_TAKEOFF; // Initial state before takeoff
SwitchState switchState;
do {
switch (currentState) {
case CHECK_BEFORE_TAKEOFF:
printf("Performing pre-takeoff checks...\n");
printf("Enter 1 to retract gear, 2 to exit: ");
scanf("%d", &switchState);
if (switchState == SWITCH_UP) {
currentState = GEAR_UP;
retractGear(); // Call the function from the header file
} else if (switchState == SWITCH_EXIT) {
currentState = EXIT;
} else {
currentState = ERROR;
}
break;
case GEAR_UP:
printf("Raising landing gear...\n");
currentState = CHECK_BEFORE_LANDING;
break;
case CHECK_BEFORE_LANDING:
printf("Performing pre-landing checks...\n");
printf("Enter 2 to lower gear, 8 to exit: ");
scanf("%d", &switchState);
if (switchState == SWITCH_LOWER) {
currentState = GEAR_DOWN;
lowerGear(); // Call the function from the header file
} else if (switchState == SWITCH_EXIT) {
currentState = EXIT;
} else {
currentState = ERROR;
}
break;
case GEAR_DOWN:
printf("Lowering landing gear...\n");
currentState = CHECK_BEFORE_TAKEOFF;
break;
case ERROR:
printf("Error state - Please check the system.\n");
currentState = EXIT;
break;
default:
printf("Invalid state encountered. Exiting...\n");
currentState = EXIT;
break;
}
} while (currentState != EXIT);
printf("Exiting the program...\n");
return 0;
}