10. LED Control Class

 Frame a class LED with the following:

  • Private data members:
    • pin (integer, pin number of LED)
    • state (boolean, ON = true, OFF = false)
       
  • Public methods:
    • void turnOn() → sets state to ON
    • void turnOff() → sets state to OFF
    • void toggle() → flips the current state
    • string getState() const → returns "ON" if state is true, otherwise "OFF"
       

The input will contain:

  • pin (integer, pin number)
  • n (number of operations)
  • followed by n operations, each of the form: on, off, or toggle
     

The output should be the final state of the LED (ON or OFF).

The output should be the final state of the LED (ON or OFF).

 

Example
 Input:

13 3
on
toggle
toggle

Output:

ON

Here, pin = 13, operations = on → toggle → toggle.

  • After on → state = ON
  • After first toggle → state = OFF
  • After the second toggle → state = ON

 

Input:

7 2
on
off

Output:

OFF

Here, pin = 7, operations = on → off.

  • After on → ON
  • After off → OFF
Loading...

Input

13 3 on toggle toggle

Expected Output

ON