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