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.

Respuesta :

Answer:

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;

}

Explanation: