SensorConfig Initialization

#include <iostream>
using namespace std;

// Define SensorConfig class here
class SensorConfig{
    private:
    int id;
    int offset;
    int lastvalue=0;
    public:SensorConfig(int sensorId, int calibrationOffset){
        id=sensorId;
        offset=calibrationOffset;
        lastvalue=0;
    }
    void update(int raw){
        lastvalue=offset+raw;
    }
    int read(){
        return lastvalue;
    }
};

int main() {
    int id, offset;
    cin >> id >> offset;

    SensorConfig cfg(id, offset);  // must use parameterized constructor

    int r1, r2;
    cin >> r1 >> r2;

    cfg.update(r1);
    cfg.update(r2);

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

Solving Approach

 

 

 

 

 

Upvote
Downvote
Loading...

Input

10 3 20 25

Expected Output

28