Challenge

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();

}

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.