fork(1) download
  1. # include <iostream>
  2. # include <map>
  3.  
  4. static std::map< int, std::string > map_sea = {
  5. { 0, "Winter" },
  6. { 1, "Spring" },
  7. { 2, "Summer" },
  8. { 3, "Autumn" }
  9. };
  10.  
  11. enum Seasons {
  12. Winter = 0,
  13. Spring,
  14. Summer,
  15. Autumn,
  16. };
  17.  
  18. class Year {
  19. public:
  20. Seasons sea;
  21. Year() {}
  22.  
  23. void getSeason() {
  24. std::cout << map_sea.at(sea) << std::endl;
  25. }
  26. void setSeason(Seasons s) {
  27. sea = s;
  28. }
  29. };
  30.  
  31. int main()
  32. {
  33. int index;
  34. Year y[4];
  35.  
  36. for (index = 0; index < 4; ++index) y[index].setSeason((Seasons)index);
  37. for (index = 0; index < 4; ++index) y[index].getSeason();
  38.  
  39. return 0;
  40. }
  41.  
Success #stdin #stdout 0.01s 5460KB
stdin
Standard input is empty
stdout
Winter
Spring
Summer
Autumn