Abstract Sensor Debugging

#include <iostream>
using namespace std;

class Sensor{
   public:
      virtual int readValue() const = 0;
};

class TemperatureSensor : public Sensor{
   private:
      int temperature;
   
   public:
      TemperatureSensor(int t): temperature(t){};

      int readValue() const {
         return temperature;
      }
};
int main() {
   int t;
   cin >> t;
   TemperatureSensor ts(t);
   Sensor* ptr = &ts;
   cout << "Temperature=" << ptr->readValue();
   return 0;
}

Upvote
Downvote
Loading...

Input

25

Expected Output

Temperature=25