Abstract Sensor Debugging

#include <iostream>
using namespace std;

// Sensor interface
class Sensor {
public:
    virtual int readValue() const = 0; // Required sensor operation
};

// Concrete sensor implementation (incomplete)
class TemperatureSensor : public Sensor {
private:
    int temperature;
public:
    TemperatureSensor(int t) : temperature(t) {}
    // TODO:
    // - Ensure this class fully satisfies the Sensor interface
    int readValue() const override{
        return temperature;
    }
};

int main() {
    int t;
    cin >> t;

    TemperatureSensor ts(t);
    Sensor* ptr = &ts;

    cout << "Temperature=" << ptr->readValue();
    return 0;
}

Solving Approach

 

 

 

 

Upvote
Downvote
Loading...

Input

25

Expected Output

Temperature=25