2. Sensor Class

#include <iostream>
using namespace std;

class Sensor {
public:
    int read() { return 100; }
};

int main() {
    Sensor s;
    cout << "Sensor reading: " << s.read();
    return 0;
}

Solution Explanation

  • read() is a trivial method that returns a constant.
  • main() prints the returned value with a fixed prefix.

     

Layman’s Terms

Sensor is like a little box that always answers “100” when you ask for a reading. The program shows that answer.

Significance for Embedded Developers

In real projects, read() might poll ADC, fetch cached data, or trigger a conversion. You’ll repeatedly create such thin wrappers to keep high-level code hardware-agnostic and testable—e.g., swapping a mock sensor in unit tests or changing the ADC channel without touching the rest of the code.

Loading...

Input

Expected Output

Sensor reading: 100