Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
#include <stdio.h>
#include <stdbool.h>
// Define the states
typedef enum {
RETRACTED, // Landing gear is retracted
EXTENDED, // Landing gear is extended
TRANSITIONING // Landing gear is moving
} LandingGearState;
// Define the system state
LandingGearState gearState = RETRACTED; // Initial state of the landing gear
// Function to simulate the valve control
void controlValve(LandingGearState state) {
if (state == RETRACTED) {
printf("Valve is controlling retraction of the landing gear.\n");
} else if (state == EXTENDED) {
printf("Valve is controlling extension of the landing gear.\n");
} else {
printf("Valve is in transition mode.\n");
}
}
// Function to simulate the extension of the landing gear
void extendLandingGear() {
if (gearState == RETRACTED) {
gearState = TRANSITIONING;
printf("Landing gear is transitioning to extended position...\n");
controlValve(EXTENDED);
gearState = EXTENDED;
printf("Landing gear is now extended.\n");
} else {
printf("Landing gear is already extended.\n");
}
}
// Function to simulate the retraction of the landing gear
void retractLandingGear() {
if (gearState == EXTENDED) {
gearState = TRANSITIONING;
printf("Landing gear is transitioning to retracted position...\n");
controlValve(RETRACTED);
gearState = RETRACTED;
printf("Landing gear is now retracted.\n");
} else {
printf("Landing gear is already retracted.\n");
}
}
// Function to simulate the pilot's control switch
void handleControlSwitch(bool extend) {
if (extend) {
extendLandingGear();
} else {
retractLandingGear();
}
}
// Function to simulate a speed/altitude check (conditions to ensure safe retraction/extension)
bool checkConditionsForLandingGear() {
// For this example, the conditions are simplified
// In reality, speed, altitude, and other sensors would be used
// Let's assume the conditions allow operation for simplicity:
return true; // In reality, you'd check the sensor data here
}
int main() {
char userInput;
bool extend;
printf("Welcome to the Airplane Landing Gear Control System.\n");
printf("Enter 'e' to extend the landing gear, 'r' to retract, or 'q' to quit:\n");
// Main loop for user input
while (1) {
userInput = getchar();
getchar(); // To consume the newline character
if (userInput == 'e') {
extend = true;
} else if (userInput == 'r') {
extend = false;
} else if (userInput == 'q') {
break; // Exit the loop
} else {
printf("Invalid input. Please enter 'e' to extend, 'r' to retract, or 'q' to quit.\n");
continue;
}
// Check if conditions for controlling the landing gear are safe
if (checkConditionsForLandingGear()) {
printf("Conditions are safe to proceed.\n");
handleControlSwitch(extend);
} else {
printf("Conditions are not safe to change the landing gear.\n");
}
}
printf("Exiting the Airplane Landing Gear Control System.\n");
return 0;
}