In clean code, we often want function parameters to have descriptive names (like speed or config). However, if a class has a member variable with the exact same name, the parameter "shadows" the member. Writing speed = speed; does nothing (it assigns the parameter to itself).
To fix this, we use the this pointer to explicitly refer to the member variable: this->speed = speed;.
Your task is to implement a class Timer.
int period (initialized to 0).void setPeriod(int period):period.this-> to assign the argument to the member.void log(): Print Timer Period: <period> ms.Program Flow:
Timer.N.N times.p.timer.setPeriod(p).timer.log().Input Format:
N.N lines: Integer p.Output Format:
Timer Period: <value> msExample:
Example 1
Input:
2
100
500Output:
Timer Period: 100 ms
Timer Period: 500 msConstraints:
setPeriod must be named period (same as the member).this->period to resolve the conflict.
Input
2 100 500
Expected Output
Timer Period: 100 ms Timer Period: 500 ms