In firmware, we often need a single global object (like a PowerManager or Logger) accessible from anywhere. Using a raw global variable is dangerous because initialization order is undefined.
The C++ "Meyers' Singleton" pattern solves this using a Local Static Variable.
Your task is to implement a class SystemClock.
getInstance():static SystemClock instance.void tick(): Increments an internal counter.int getTime(): Returns the counter.Program Flow:
SystemClock::getInstance() to get a reference clk.N.N times.cmd.cmd is "TICK", call clk.tick().cmd is "SHOW", print Time: <value>.Input Format:
N (1 to 20).N lines: String cmd ("TICK" or "SHOW").Output Format:
Time: <value>Example:
Example 1
Input:
3
TICK
TICK
SHOWOutput:
Time: 2Constraints:
private.static local variable inside getInstance().
Input
3 TICK TICK SHOW
Expected Output
Time: 2