Challenge

Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear

#include <stdio.h>

// States of the landing gear

enum State {

RETRACTED,

EXTENDED

};

// Inputs to the landing gear control system

enum Input {

PILOT_LEVER_UP,

PILOT_LEVER_DOWN,

SWITCH_ON,

SWITCH_OFF

};

// Functions to control the landing gear

void extend_landing_gear() {

printf("Extending landing gear...\n");

}

void retract_landing_gear() {

printf("Retracting landing gear...\n");

}

// Main function

int main() {

enum State landing_gear_state = RETRACTED;

while (1) {

enum Input input = (enum Input)rand() % 4;

switch (input) {

case PILOT_LEVER_UP:

retract_landing_gear();

break;

case PILOT_LEVER_DOWN:

extend_landing_gear();

break;

case SWITCH_ON:

landing_gear_state = EXTENDED;

break;

case SWITCH_OFF:

landing_gear_state = RETRACTED;

break;

}

printf("Landing gear state: %d\

n", landing_gear_state);

}

return 0;

}gcc -o landing_gear landing_gear.c

./landing_gea

r

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.