All submissions

Object Accessing Inherited Variables

#include <iostream>
using namespace std;

class Device {
public:
    int id;
};

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

int main() {
    // your code here: declare Sensor object, assign id and value, and print them
    Sensor my_sensor;
    my_sensor.id = 101;
    my_sensor.value = 75;
    printf("Device ID: %d, Sensor Value: %d", my_sensor.id, my_sensor.value);
    return 0;
}
Loading...

Input

Expected Output

Device ID: 101, Sensor Value: 75