Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
#include
// LandingGear class
class LandingGear {
private:
bool extended; // Flag to track the status of the landing gear
public:
// Constructor
LandingGear() : extended(false) {}
// Function to extend the landing gear
void extend() {
if (extended) {
std::cout << "Landing gear is already extended.\n";
} else {
// Perform the necessary actions to extend the landing gear
std::cout << "Extending the landing gear.\n";
// Additional code to control the hardware for gear extension
extended = true; // Update the status flag
}
}
// Function to retract the landing gear
void retract() {
if (!extended) {
std::cout << "Landing gear is already retracted.\n";
} else {
// Perform the necessary actions to retract the landing gear
std::cout << "Retracting the landing gear.\n";
// Additional code to control the hardware for gear retraction
extended = false; // Update the status flag
}
}
// Function to check the status of the landing gear
void checkStatus() {
std::cout << "Landing gear status: " << (extended ? "Extended" : "Retracted") << std::endl;
}
};
int main() {
LandingGear landingGear;
landingGear.checkStatus(); // Initial status - Retracted
landingGear.extend();
landingGear.checkStatus(); // Status after extension - Extended
landingGear.retract();
landingGear.checkStatus(); // Status after retraction - Retracted
return 0;
}