144. Hardware Monitor

Encapsulation usually hides private data. However, in embedded systems, a "Hardware Monitor" or "Debug Console" often needs to inspect the raw internal state of a peripheral driver for diagnostics, even if that state is hidden from normal application code.

Your task is to implement a class TemperatureSensor.

  1. It has a private member int raw_adc_value (initialized to 0).
  2. It has a public method update(int val) to simulate a sensor reading (sets raw_adc_value).
  3. Implement a standalone function void debugMonitor(const TemperatureSensor& s).
    • This function is not a member of the class.
    • It needs to print Debug: Raw ADC = <value>.
    • To allow this, the class must declare this function as a friend.

Program Flow:

  1. Read integer N.
  2. Loop N times.
  3. Read string cmd.
  4. If cmd is "READ": Read integer val, update sensor.
  5. If cmd is "DEBUG": Call the global debugMonitor function with the sensor object.

Input Format:

  • First line: Integer N (1 to 20).
  • Next N lines: String cmd ("READ", "DEBUG").
  • Input is provided via standard input (stdin).

Output Format:

  • For "DEBUG": Debug: Raw ADC = <value>
  • Each output must be on a new line.

Example: Example 1

Input:

3
READ 1024
DEBUG
READ 2048

Output:

Debug: Raw ADC = 1024

Constraints:

  • raw_adc_value must be private.
  • debugMonitor must be a standalone function (not inside the class).
  • Must use the friend keyword.

 

 

 

Loading...

Input

3 READ 1024 DEBUG READ 2048

Expected Output

Debug: Raw ADC = 1024