Object Accessing Inherited Variables

#include <iostream>
using namespace std;

class Device {
public:
    int id;
};

class Sensor : public Device {
public:
    int value;
};

int main() {
    Device d;
    d.id = 101;
    Sensor s;
    s.value = 75;

    cout << "Device ID: " << d.id  << ", "  << "Sensor Value: " << s.value << endl;
    // your code here: declare Sensor object, assign id and value, and print them
    return 0;
}
Upvote
Downvote
Loading...

Input

Expected Output

Device ID: 101, Sensor Value: 75