ADC Offset Calibration

#include <iostream>

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

    ADCSensor() : offset_val(100) {}

    // TODO: Add a method to process raw values and return calibrated data.
    int getCalibratedSample(int raw_val){
        if (raw_val-offset_val < 0) {
            return 0;
        }
        return raw_val- offset_val;
    }
};

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.
        ADCSensor adcs;
        // TODO: Fix the bug where (raw - offset) can be negative.
        int result = adcs.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