#include <iostream>
#include <cstdint>
using namespace std;
enum class ErrorCode : uint8_t {
None = 0,
Timeout = 1,
Overflow = 2,
Invalid = 3
};
const char* toString(ErrorCode e) {
switch (e) {
case ErrorCode::None: return "None";
case ErrorCode::Timeout: return "Timeout";
case ErrorCode::Overflow: return "Overflow";
case ErrorCode::Invalid: return "Invalid";
}
}
int main() {
int x;
cin >> x;
// Input is guaranteed to be in the range 0–3 by problem definition
ErrorCode e = static_cast<ErrorCode>(x);
cout << toString(e);
return 0;
}
Explanation & Logic Summary:
The ErrorCode enum defines a fixed set of firmware-style error identifiers with explicit numeric values from 0 to 3.
Each numeric value corresponds directly to a valid ErrorCode.
The input integer is guaranteed to be within this range, so it can be safely cast to the enum type.
The toString(ErrorCode) function converts each enum value to its human-readable string representation.
All enum cases are explicitly handled, ensuring deterministic behavior.
Firmware Relevance & Real Embedded Meaning:
Embedded systems commonly represent status and error conditions using small integer codes.
This problem demonstrates:
enum class for strong type safetyThese patterns are typical in firmware drivers, hardware abstraction layers, and diagnostic reporting code.
Input
0
Expected Output
None