Sensor Calibration Class

#include <iostream>
using namespace std;

// Define Sensor class here
// <write your code>

class Sensor {
    private:
    int rawValue;
    int offset;

    public:
    void setRaw (int value) noexcept
    {
        this->rawValue = value;
    }

    void calibrate(int off) noexcept
    {
        this->offset = off;
    }

    int read () const noexcept
    {
        return this->rawValue + this->offset;
    }
};

int main() {
    int raw, offset, newRaw;
    cin >> raw >> offset >> newRaw;

    Sensor s;
    s.setRaw(raw);
    s.calibrate(offset);
    s.setRaw(newRaw);

    cout << s.read();
    return 0;
}

Solving Approach

 

 

 

 

 

Upvote
Downvote
Loading...

Input

100 -5 120

Expected Output

115