Ask Question
11 January, 05:38

Simulate a circuit for controlling a hallway light that has switches at both ends of the hallway. Each switch can be up or down, and the light can be on or off. Toggling either switch turns the lamp on or off. Provide member functions.

+4
Answers (1)
  1. 11 January, 08:04
    0
    int switch_1, switch_2;

    int get_first_switch_state ()

    {

    return switch_1;

    }

    int get_second_switch_state ()

    {

    return switch_1;

    }

    int get_lamp_state ()

    {

    if ((get_first_switch_state ())

    if (get_second_switch_state ()) return 1;

    else

    if (! get_second_switch_state ()) return 1;

    return 0;

    }

    void toggle_first_switch ()

    {

    if (get_first_switch_state ()) switch_1=0;

    else switch_1=1;

    }

    void toggle_second_switch ()

    {

    if (get_second_switch_state ()) switch_2=0;

    else switch_2=1;

    }
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Simulate a circuit for controlling a hallway light that has switches at both ends of the hallway. Each switch can be up or down, and the ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers