Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
#include
// Structure representing the landing gear
typedef struct {
int is_retracted;
} LandingGear;
// Function to retract the landing gear
void retract(LandingGear* gear) {
if (gear->is_retracted) {
printf("Landing gear is already retracted.n");
} else {
printf("Retracting landing gear.n");
// Code to retract the landing gear goes here
gear->is_retracted = 1;
}
}
// Function to extend the landing gear
void extend(LandingGear* gear) {
if (!gear->is_retracted) {
printf("Landing gear is already extended.n");
} else {
printf("Extending landing gear.n");
// Code to extend the landing gear goes here
gear->is_retracted = 0;
}
}
int main() {
// Create an instance of LandingGear
LandingGear gear;
gear.is_retracted = 0;
// Retract the landing gear
retract(&gear);
// Try to retract the landing gear again
retract(&gear);
// Extend the landing gear
extend(&gear);
// Try to extend the landing gear again
extend(&gear);
return 0;
}