ADC Offset Calibration

#include <iostream>

class ADCSensor {
    // TODO: The offset should be an internal implementation detail.
    // TODO: Encapsulate this to prevent external modification.
    int offset_val;
public:


    ADCSensor() : offset_val(100) {};
    int getCalibratedSample(int raw_val)
    {
        int calibrated_value = raw_val - offset_val;
        if ( calibrated_value < 0 ) return 0;
        return calibrated_value;
    }

    // TODO: Add a method to process raw values and return calibrated data.
};

int main() {
    int N;
    if (!(std::cin >> N)) return 0;

    ADCSensor sensor;

    for (int i = 0; i < N; ++i) {
        int raw;
        std::cin >> raw;

        // TODO: Move this logic inside the class.
        // TODO: Fix the bug where (raw - offset) can be negative.
        int result = sensor.getCalibratedSample(raw);

        std::cout << "Sample: " << result << std::endl;
    }

    return 0;
}

Solving Approach

 

 

 

 

Upvote
Downvote
Loading...

Input

3 250 100 50

Expected Output

Sample: 150 Sample: 0 Sample: 0