Question

E9.3 C++ Simulate a circuit for controlling a hallway light that has switches at both ends...

E9.3

C++

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

int get_first_switch_state() // 0 for down, 1 for up
int get_second_switch_state()
int get_lamp_state() // 0 for off, 1 for on
void toggle_first_switch()
void toggle_second_switch()
0 0
Add a comment Improve this question Transcribed image text
Answer #1

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;
}

Add a comment
Know the answer?
Add Answer to:
E9.3 C++ Simulate a circuit for controlling a hallway light that has switches at both ends...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I am looking for help with a PLC lab using LogixPro that will perform the common...

    I am looking for help with a PLC lab using LogixPro that will perform the common electrical function of controlling a light from two different locations (example: a long hallway where there is usually one light switch at each end). Each switch can control the light on and off. The program should be set up so that if both switches are ON or if both switches are Off, then the light will go ON, and it will go off otherwise....

  • write in C language Decoration Lights Jojo is currently working in an office as a security....

    write in C language Decoration Lights Jojo is currently working in an office as a security. Every night, after everyone returned home, he needs to make sure all decoration lights in the office is turned off. The decoration lights are unique: each of them has a timer that will switch the light on or off every two seconds. The lights are also arranged so well that each two neighboring lights will have different state (on/off). As long as the timer...

  • can someone help me fix my jeopardy dice game I am having a hard time figuring...

    can someone help me fix my jeopardy dice game I am having a hard time figuring out what i am doing wrong #include #include using namespace std; //this function makes a number between 1 and 6 come out just like a dice int rollDie() { return (rand() % 6+1); } //this function asks the user with a printed statement if they want to roll the dice and gives instructions for yes and no (y/n) void askYoNs(){ cout<<"Do you want to...

  • write it in c++ Question 6 Consider a case of single inheritance where Landline phone is a base class and Mobile phone is the derived class. Both the classes are as follow: (a) Landline: It has su...

    write it in c++ Question 6 Consider a case of single inheritance where Landline phone is a base class and Mobile phone is the derived class. Both the classes are as follow: (a) Landline: It has subscriber name and number as data members. The member functions are to provide the features of calling on a subscriber's number and receiving a call Void call (int sub_number) Void receivel (b) Mobile: Apart from inheriting the features of a Landline phone, it provides...

  • Write a C++ program to simulate a stream path. In this problem you can make the...

    Write a C++ program to simulate a stream path. In this problem you can make the following assumptions 1. The elevation grid will be a n row, m column grid of integers, where n and m are constant. 2. Once the stream origin location is specified, then the stream flows to whichever of the four adjacent locations in the grid represents the largest descent. 3. If more than one of the adjacent locations have the largest descent, then the water...

  • Program is for an Arduino 1. Add the letters “A”, “b”, “c”, “d”, “E”, “F” to...

    Program is for an Arduino 1. Add the letters “A”, “b”, “c”, “d”, “E”, “F” to your homework program. Continually display “0123”, “4567”, “89Ab”, “cdEF” with a one second delay between each one. HINT: Expand pickNumber() to use numbers 10-15 (a-f in hex). Create new functions for a-f. (THIS IS THE CODE FROM THE HOMEWORK) /*************************************** name:Stopwatch function: you can see the number increases by one per second on the 4-digit 7-segment display. ***********************************/ //Email:support@sunfounder.com //Website:www.sunfounder.com /**************************************/ #include //the pins...

  • A current sensor is measuring the DC current that is flowing through a power circuit. The output of the current sensor...

    A current sensor is measuring the DC current that is flowing through a power circuit. The output of the current sensor is a raw voltage signal which varies according to the following equation V 2.50.02 Where I is the flowing current in A (value can be positive or negative). An engineer would like a microcontroller to be able to measure this current so that it can be used for control purposes. The available ADC is 12-bit in resolution and measures...

  • C++ #include <iostream> using namespace std; bool checkinventoryid(int id) {    return id > 0; }...

    C++ #include <iostream> using namespace std; bool checkinventoryid(int id) {    return id > 0; } bool checkinventoryprice(float price) {    return price > 0; } void endProgram() {    system("pause");    exit(0); } void errorID(string str) {    cout << "Invalid Id!!! " << str << " should be greater than 0" << endl; } void errorPrice(string str) {    cout << "Invalid Price!!!" << str << " should be greater than 0" << endl; } int inputId() {...

  • A current sensor is measuring the DC current that is flowing through a power circuit. The output f the current sensor i...

    A current sensor is measuring the DC current that is flowing through a power circuit. The output f the current sensor is a raw voltage signal which varies according to the following equation: V 2.5 0.02 Where I is the flowing current in A (value can be positive or negative). An engineer would like a microcontroller to be able to measure this current so that it can be used for control purposes. The available ADC is 12-bit in resolution and...

  • Suppose an antiques dealer decides to reuse class Checker, that you wrote last week, for a...

    Suppose an antiques dealer decides to reuse class Checker, that you wrote last week, for a program they are writing to keep track of fancy or antique checker pieces. Modify your checker game from last week as described below. Add a class FancyChecker that is a child of class Checker. In addition to the members and member functions of class Checker, class FancyChecker should have a member named material which stores strings such as "wood" or "plastic". FancyChecker should also...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT