#include <iostream>
class ADCSensor {
private:
int offset_val = 100;
int value;
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.
void getCalibratedSample(int raw_val){
if(raw_val < offset_val){
value = 0;
}
else{
value = raw_val - offset_val;
}
}
int print() const{
return value;
}
};
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.
sensor.getCalibratedSample(raw);
std::cout << "Sample: " << sensor.print() << std::endl;
}
return 0;
}
Input
3 250 100 50
Expected Output
Sample: 150 Sample: 0 Sample: 0