#include <iostream>
using namespace std;
// Create CoreDriver class
// Constructor prints "Core driver initialized"
class CoreDriver {
public:
CoreDriver() {
cout << "Core driver initialized" << endl;
}
};
// Create CommDriver class
// Publicly inherits from CoreDriver
// Constructor prints "Comm driver initialized"
class CommDriver : public CoreDriver {
public:
CommDriver() {
cout << "Comm driver initialized" << endl;
}
};
// Create SpiDriver class
// Publicly inherits from CommDriver
// Constructor takes int speed
// Prints "SPI driver initialized"
// Stores speed
// Function prints "SPI speed <speed>"
class SpiDriver : public CommDriver {
private:
int speed;
public:
SpiDriver(int sp) {
cout << "SPI driver initialized" << endl;
speed = sp;
}
void print() {
cout << "SPI speed " << speed << endl;
}
};
int main() {
int speed;
cin >> speed;
// Create SpiDriver object
SpiDriver spi(speed);
// Call function to print SPI speed
spi.print();
return 0;
}Input
8
Expected Output
Core driver initialized Comm driver initialized SPI driver initialized SPI speed 8