Challenge

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

1. Implement the Code for controlling the retraction and extension of Airplane’s landing gear

// program to implement the Code for controlling the retraction and extension of Airplane’s landing gear

#include

#include

#include

//declaring structure for states

typedef enum state{

    GEAR_DOWN,

    CHECK_BEFORE_TAKEOFF,

    RISING_GEAR,

    GEAR_UP,

    CHECK_BEFORE_LANDING,

    LOWERING_GEAR

}flight_state;

flight_state state;

//declaring functions

static volatile int clock;

void intial();

void gear_down();

void check_before_takeoff();

void rising_gear();

void gear_up();

void check_before_landing();

void lowering_gear();

//declaring function pointer

void (*gear[]) (void)={gear_down,check_before_takeoff,rising_gear,gear_up,check_before_landing,lowering_gear};

int main(){

    intial();//calling initial function

    while(1){

        printf("\n");

        gear[state]();//calls the  function according to the state set in the function

    }

}

void intial(){

 state=GEAR_DOWN;//state has been set

 printf("The flight state is in gear_down state with led light green");//output is printed

}

void gear_down(){

    char s1[10],s2[10];

    printf("Enter the lever status : ");

    scanf("%s",s1);

    printf("Enter squat switch status : ");

    scanf("%s",s2);

    if(strcmp(s1,"raising")==0&&strcmp(s2,"open")==0){//comparing the lever status and switch status

        state=CHECK_BEFORE_TAKEOFF;//state has been set

        printf("The flight is in 'ready to take off' state with led light 'green'");//output is printed

    }

    else{

        printf("please enter valid input");//if wrong input program flow redirects here

    }

}

void check_before_takeoff(){

    if(clock==3){

        char s[10];

        printf("Enter the lever status or squat switch status: ");

        scanf("%s",s);

        if(strcmp(s,"up")==0){//comparing the lever status

            state=RISING_GEAR;//state has been set

            //output is printed

            printf("The flight state is in 'rising_gear' state with led light 'RED' and directional value 'UP'");

        }

        else if(strcmp(s,"close")==0||strcmp(s,"falling")==0){//comparing the switch status

            state=GEAR_DOWN;//state has been set

            printf("The flight state is in gear_down state with led light 'RED'");//output is printed

        }

        else{

            printf("please enter valid input");//if wrong input program flow redirects here

        }

    }

    else{

    printf("clock value in seconds : %d",clock);//clock is updated and printed

        clock++;

    }

}

void rising_gear(){

    char s[10];

    printf("Enter the lever status or limit switch status : ");

    scanf("%s",s);

    if(strcmp(s,"closed")==0){//comparing the lever status

        state=GEAR_UP;//state has been set

        //output is printed

        printf("The flight state is in 'gear_up' state with led light 'OFF' and directional value is in 'Control of hydraulic pump for the landing gear part is disabled' state");

    }

    else if(strcmp(s,"falling")==0){//comparing the switch status

        state=CHECK_BEFORE_LANDING;//state has been set

        //output is printed

        printf("The flight state is in 'check_before_landing' state with led light 'RED'");

    }

    else{

        printf("please enter valid input");//if wrong input program flow redirects here

    }

}

void gear_up(){

    char s[10];

    printf("Enter the lever status : ");

    scanf("%s",s);

    if(strcmp(s,"falling")==0){//comparing the lever status

        state=CHECK_BEFORE_LANDING;//state has been set

        //output is printed

        printf("The flight state is in 'check_before_landing' state with led light 'RED'");

    }

    else{

        printf("please enter valid input");//if wrong input program flow redirects here

    }

}

void check_before_landing(){

    char s[10];

    printf("Enter the lever status : ");

    scanf("%s",s);

    if(strcmp(s,"down")==0){//comparing the lever status

        state=LOWERING_GEAR;//state has been set

        //output is printed

        printf("The flight state is in 'lowering_gear' state with led light 'RED'");

    }

    else{

        printf("please enter valid input");//if wrong input program flow redirects here

    }

}

void lowering_gear(){

    char s[10];

    printf("Enter the limit switch status or lever status : ");

    scanf("%s",s);

    if(strcmp(s,"opened")==0){//comparing the lever status

        state=GEAR_DOWN;//state has been set

        //output is printed

        printf("The flight state is in 'gear_down' state with led light 'GREEN'");

    }

    else if (strcmp(s,"raising")==0){//comparing the switch status

        state=CHECK_BEFORE_TAKEOFF;//state has been set

        //output is printed

        printf("The flight state is in 'check_before_takeoff' state with led light 'RED'");

    }

    else{

        printf("please enter valid input");//if wrong input program flow redirects here

    }

}

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.

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.