60. Sensor Calibration Class

Design and implement a simple Embedded C++ class that models a calibrated sensor.

You must define a class named Sensor that stores raw sensor readings and applies a calibration offset before reporting the final value.

Requirements

  1. Class Definition
    • Define a class Sensor.
  2. Private Data Members
    • int rawValue — stores the most recent raw sensor reading.
    • int offset — stores the calibration offset.
  3. Public Member Functions
    • void setRaw(int value)
      • Stores a new raw sensor reading.
    • void calibrate(int off)
      • Sets the calibration offset.
    • int read()
      • Returns the calibrated sensor value (rawValue + offset).
  4. Main Function Behavior
    • Read three integers from standard input in the following order:
      1. Initial raw sensor value
      2. Calibration offset
      3. New raw sensor value
    • Create a Sensor object.
    • Call setRaw() using the initial raw value.
    • Call calibrate() using the offset.
    • Call setRaw() again using the new raw value.
    • Print the final calibrated sensor reading using read().

 

Input Format

Three signed integers provided via standard input, each separated by a newline:

raw
offset
newRaw

Output Format

A single integer printed to standard output:

calibrated_value 

Example Input

100
-5
120

Example Output

115

Explanation

The final calibrated reading is:

120 + (-5) = 115

Constraints

  • rawValue and offset must be private.
  • These variables may only be modified using class member functions.
  • Signed integer arithmetic is used.
  • No overflow handling is required beyond standard C++ int behavior.
  • Output must match exactly with no extra spaces or newlines.

 

 

 

Loading...

Input

100 -5 120

Expected Output

115