subject

Light Switches Consider the following logic puzzle I have a board of light switches, numbered 0,1.2...1023 Each light switch can be switched on or off. All switches are initially off. Step 1: All of the switches are flipped starting at 0. At this point, all of the light switches are on. Step 2 Every second switch is flipped, starting at 0. At this point, lights 0,2.4.6,8... are off. Lights 1,3,5,7,9 are still on. Step 3: Every third switch is flipped, starting at 0. So switches 0.3,6,9,12,... are flipped So if a switch is on, it is flipped off. And if a switch is off, it is flipped on Step 1023 Every 1023 rd switch is flipped, starting at 0 So switches 0 and 1023 are flipped. The question is: "After step 1023, which switches are on and which are off?" To answer this question, you will be using object oriented programming though tech- nically you could solve it using a "trick (as) Light Switch Create a class called LaightSwitch with following properties. . When a LightSwitch is created, it's default state should be attable using an argument to the constructor. If the input argument is "on", it should start off us on, if the input argument is "off" it should start of as "off". • It should be posible to turn the switch on using a method called turno. • It should be posible to turn off the switching a method called turn off • There should also be a flip method that flips the current the current state of the Light Switch (on to off or off to on) • If a switch is printed, it should print "I am on" or "I am off' depending on the the current state (they are smart switches). Write a str. method to accomplish this. • You shouldn't store the state of the switch using a string, use a 'bool' attribute instead. (b) SwitchBoard Build a SwitchBoard class with the following properties: • When a switchboard is created, it should be possible to specify the number of switches it contains. You should represent a SwitchBoard as a list of Light Switches. • All switches should start in the "off" position. . If a switchboard is printed, it should print like the following: " The following switches are on: 0 2 4 6 8". It is fine for everything to be printed on the same line. Write a str , method to accomplish this. • There should be a method called which switch, that should return a list of integers representing which switches are on in order (e. g. (1,3,5,7,9]). • There should a method called flip, which takes a single integer argument, n and flips the state of the n'th light switch. • There should be a flip_every method that takes one argument, n and flips the state of every n'th switch, starting at 0. So flip. every(2) would flip switches 0, 2, 4, 6, etc. • There should be a method reset(), which should turn off all the sitches in the board. . If flip is called with an input argument outside the bounds of the list (e. g. 100 is passed in when there are only 16 switches), then your program should not crash, instead an message you printed to user stating the switch specified does not exist Finally, create an instance of the Switch Board class in your main program to solve the original question of which light switches will still be on after step 1023. Print the SwitchBoard at the end.

ansver
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 22:00, suewignall
During physical science class ben and jerry connected three identical lightbulbs in parallel to a battery where happens when ben removes one of the lightbulbs from it’s socket
Answers: 2
image
Computers and Technology, 23.06.2019 12:00, daelinrobinson
If you're using an existing powerpoint presentation that will receive new slides based on a word outline, select the a. slide that will appear after the new slides. b. first slide in the presentation. c. slide that will appear before the new slides. d. last slide in the presentation.
Answers: 2
image
Computers and Technology, 23.06.2019 23:40, lexiecooley
4. what is the reason for including the following code snippet in the header file animal. h? #ifndef animal_h #define animal_h class animal { public: animal(); animal(double new_area_hunt); void birth(); void hunt(double new_area_hunt); void death(); double get_area_hunt() const; private: double area_hunt; }; #endif
Answers: 3
image
Computers and Technology, 24.06.2019 15:20, 710jonathan
Local area networks use many of the same network technologies and the internet, only on a smaller scale. devices that access lans are equipped with a network interface that contains circuitry for wireless or wired connections. devices also have a physical address, in addition to the ip addresses acquired from a dhcp server. the most popular wired technology is . the most popular wireless technology is , which can be configured as a(n) or star topology. setting up a lan and configuring its router is fairly easy. the first step is to change the standard to one that is secure. next, create a(n) that uniquely identifies the network by name. it is also important to activate wireless to prevent wireless signals from being intercepted during transmission. a limited-access network can be created for visitors to use. by activating , the router will be able to assign ip addresses to each device that joins the network. to connect to a secure lan that is protected by encryption, an encryption , or password, is required. lans can be used to access data collected by iot devices and the networks that tie these devices together. technologies such as rfid, nfc, bluetooth smart, zigbee, and z-wave offer -power links, essential for battery-powered devices that can’t expend excess amounts of energy transmitting data.
Answers: 1
You know the right answer?
Light Switches Consider the following logic puzzle I have a board of light switches, numbered 0,1.2....

Questions in other subjects:

Konu
Mathematics, 12.12.2020 16:10