Object Declaration and Variable Access

#include <iostream>
using namespace std;

class Device {
public:
    int id;
    void assignID(int n){
        id =n; 
    }
    void printDevice(){
        cout << "Device ID: " << id << endl;
    }
};

int main() {
    // your code here: declare Device object, assign id, and print it
    Device d; 
    int n = 101; 
    d.assignID(n); 
    d.printDevice(); 

    return 0;
}
Upvote
Downvote
Loading...

Input

Expected Output

Device ID: 101