Sensor Calibration Class

#include <iostream>
using namespace std;

// Define Sensor class here
// <write your code>
class Sensor {
public:
    Sensor(int raw, int off) : rawValue(raw), offset(off){}
    Sensor() : Sensor(0,0){}
    void setRaw(int value);
    void calibrate(int off);
    int read();
private:
    int rawValue;
    int offset;
};

void Sensor::setRaw(int val){
    this->rawValue = val;
}
void Sensor::calibrate(int off_val){
    this->offset = off_val;
}

int Sensor::read(){
    return (rawValue + 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