#include <iostream>
using namespace std;
// TODO 1: Create BaseDriver class
class BaseDriver {
public:
void initBase() {
// Essential shared hardware setup (Clocks, Power, etc.)
cout << "Base driver init start" << endl;
cout << "Base driver init complete" << endl;
}
};
// TODO 2: Create SpiDriver class
class SpiDriver : public BaseDriver {
public:
void initSpi() {
// Mandatory: Initialize the base first
initBase();
cout << "SPI driver initialized" << endl;
}
};
// TODO 3: Create I2cDriver class
class I2cDriver : public BaseDriver {
public:
void initI2c() {
// Mandatory: Initialize the base first
initBase();
cout << "I2C driver initialized" << endl;
}
};
int main() {
int mode;
// Standard input for mode selection
if (!(cin >> mode)) return 0;
// TODO 4: If mode == 0, create SpiDriver and call initSpi()
if (mode == 0) {
SpiDriver spi;
spi.initSpi();
}
// TODO 5: If mode == 1, create I2cDriver and call initI2c()
else if (mode == 1) {
I2cDriver i2c;
i2c.initI2c();
}
return 0;
}
Expected Output
Base driver init start Base driver init complete SPI driver initialized