#include <iostream>
#include <cstdint>
using namespace std;
// your code here: declare enum class AdcConfig : uint8_t
// with ChannelEnable=1, InterruptEnable=2, DMAEnable=4
enum class AdcConfig{ChannelEnable =1, InterruptEnable =2, DMAEnable=4};
void printConfig(uint8_t cfg) {
// your code here: implement void printConfig(uint8_t cfg)
bool any = false;
if (cfg & static_cast<uint8_t>(AdcConfig::ChannelEnable)) {
cout << "ChannelEnable";
any = true;
}
if (cfg & static_cast<uint8_t>(AdcConfig::InterruptEnable)) {
if (any) cout << ' ';
cout << "InterruptEnable";
any = true;
}
if (cfg & static_cast<uint8_t>(AdcConfig::DMAEnable)) {
if (any) cout << ' ';
cout << "DMAEnable";
any = true;
}
if (!any) cout << "None";
}
int main() {
int ch, intr, dma;
cin >> ch >> intr >> dma;
uint8_t cfg = 0;
if (ch) cfg |= static_cast<uint8_t>(AdcConfig::ChannelEnable);
if (intr) cfg |= static_cast<uint8_t>(AdcConfig::InterruptEnable);
if (dma) cfg |= static_cast<uint8_t>(AdcConfig::DMAEnable);
printConfig(cfg);
return 0;
}
Input
1 0 1
Expected Output
ChannelEnable DMAEnable