Create a class LEDController that simulates controlling an LED on a microcontroller using RAII (Resource Acquisition Is Initialization) principles.
When an object of this class is created, the LED must turn ON.
When the object is destroyed (goes out of scope), the LED must turn OFF automatically.
The LED state must be stored in a static class member so that it can be read even after the object has been destroyed.
Class Requirements:
state0 → LED OFF1 → LED ON0 (LED OFF)state = 1 (LED ON)state = 0 (LED OFF)print() that outputs exactly:LED=<state>
Program Behavior:
x from standard input.x will be either 0 or 1 only.0 → do not print LED state inside the scope1 → print LED state inside the scope{ ... }:LEDController object.x == 1, print the LED state inside the block.The final print must reflect the destructor turning the LED OFF.
Example Timeline:
Example 1
Input:
1
Output:
LED=1 LED=0
Example 2
Input:
0
Output:
LED=0
Explanation:
x == 1, the LED state is printed while the object is alive inside the scope.x == 0, the LED state is not printed inside the scope.
Constraints:
x ∈ {0, 1}
Input
1
Expected Output
LED=1 LED=0