Multilevel Driver Initialization

#include <iostream>
using namespace std;

// Core driver layer
class CoreDriver {
public:
    CoreDriver() {
        cout << "Core driver initialized" << endl;
    }
};

// Communication driver layer
class CommDriver : public CoreDriver {
public:
    CommDriver() {
        cout << "Comm driver initialized" << endl;
    }
};

// SPI device driver layer
class SpiDriver : public CommDriver {
public:
    SpiDriver(int s) : speed(s) {
        cout << "SPI driver initialized" << endl;
    }

    void printSpeed() const {
        cout << "SPI speed " << speed << endl;
    }

private:
    int speed;
};

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

    SpiDriver spi(speed);
    spi.printSpeed();

    return 0;
}

Solving Approach

 

 

 

 

 

Upvote
Downvote
Loading...

Input

8

Expected Output

Core driver initialized Comm driver initialized SPI driver initialized SPI speed 8