fork download
  1. #include <cassert>
  2. #include <string>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. enum weekday {
  8. SUNDAY,
  9. MONDAY,
  10. TUESDAY,
  11. WEDNESDAY,
  12. THURSDAY,
  13. FRIDAY,
  14. SATURDAY,
  15. WEEKDAY_SIZE
  16. };
  17.  
  18. bool getWeekday(int index, weekday& result) {
  19. result = static_cast<weekday>(index);
  20.  
  21. return index >= 0 && index < static_cast<int>(WEEKDAY_SIZE);
  22. }
  23.  
  24. bool getName(weekday& index, string& result) {
  25. switch (static_cast<weekday>(index)) {
  26. case SUNDAY:
  27. result = "Sunday";
  28. break;
  29. case MONDAY:
  30. result = "Monday";
  31. break;
  32. case TUESDAY:
  33. result = "Tuesday";
  34. break;
  35. case WEDNESDAY:
  36. result = "Wednesday";
  37. break;
  38. case THURSDAY:
  39. result = "Thursday";
  40. break;
  41. case FRIDAY:
  42. result = "Friday";
  43. break;
  44. case SATURDAY:
  45. result = "Saturday";
  46. break;
  47. default:
  48. assert("Short Circut Failed");
  49. return false;
  50. }
  51. return true;
  52. }
  53.  
  54. int main() {
  55. const int index = 0;
  56. weekday Weekday;
  57. string Name;
  58.  
  59. getWeekday(index, Weekday) && getName(Weekday, Name);
  60.  
  61. cout << Name << endl;
  62. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
Sunday