Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
#include <iostream>
using namespace std;
// Define states of the landing gear FSM
enum class GearState {
RETRACTED,
EXTENDED,
IN_TRANSITION
};
class LandingGearControl {
private:
GearState current_state;
public:
LandingGearControl() : current_state(GearState::RETRACTED) {}
void retract() {
if (current_state == GearState::EXTENDED) {
cout << "Retracting landing gear..." << endl;
current_state = GearState::IN_TRANSITION;
}
}
void extend() {
if (current_state == GearState::RETRACTED) {
cout << "Extending landing gear..." << endl;
current_state = GearState::IN_TRANSITION;
}
}
void transition_complete() {
// Simulate transition time
// For simplicity, assume transition completes immediately
current_state = (current_state == GearState::EXTENDED) ? GearState::RETRACTED : GearState::EXTENDED;
}
GearState getState() const {
return current_state;
}
};
int main() {
LandingGearControl landingGear;
// Extend the landing gear
landingGear.extend();
landingGear.transition_complete();
cout << "Current Gear State: ";
if (landingGear.getState() == GearState::RETRACTED)
cout << "Retracted" << endl;
else
cout << "Extended" << endl;
// Retract the landing gear
landingGear.retract();
landingGear.transition_complete();
cout << "Current Gear State: ";
if (landingGear.getState() == GearState::RETRACTED)
cout << "Retracted" << endl;
else
cout << "Extended" << endl;
return 0;
}