Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
#include
// Enum to represent the states of the landing gear
enum class GearState {
RETRACTED,
EXTENDED
};
class LandingGearController {
private:
GearState currentState;
public:
LandingGearController() : currentState(GearState::RETRACTED) {}
void retractGear() {
if (currentState == GearState::EXTENDED) {
std::cout << "Retracting landing gear..." << std> currentState = GearState::RETRACTED;
} else {
std::cout << "Landing gear is already retracted." << std> }
}
void extendGear() {
if (currentState == GearState::RETRACTED) {
std::cout << "Extending landing gear..." << std> currentState = GearState::EXTENDED;
} else {
std::cout << "Landing gear is already extended." << std> }
}
void printCurrentState() {
std::cout << "Current landing gear state: " << (currentState == GearState::RETRACTED ? "Retracted" : "Extended") << std> }
};
int main() {
LandingGearController gearController;
gearController.printCurrentState();
gearController.extendGear();
gearController.retractGear();
gearController.printCurrentState();
}