fork download
  1. #include <iostream>
  2.  
  3. class Color {
  4. public:
  5. enum Value { RED, GREEN, BLUE};
  6. Color(Color::Value value);
  7. bool operator ==(const Color &other);
  8. bool isHappy() const;
  9. Color rotate() const;
  10. int intensity() const;
  11.  
  12. private:
  13. Color::Value color;
  14. };
  15.  
  16.  
  17. bool Color::operator ==(const Color &other) {
  18. return other.color == this->color;
  19. }
  20.  
  21. Color::Color(Color::Value value) : color(value) {}
  22.  
  23. bool Color::isHappy() const {
  24. return color == RED || color==GREEN;
  25. }
  26.  
  27. Color Color::rotate() const {
  28. if(color == RED) return Color(GREEN);
  29. if(color == GREEN) return Color(BLUE);
  30. return Color(RED);
  31. }
  32.  
  33.  
  34. int Color::intensity() const {
  35. if(color == RED) return 11;
  36. if(color == GREEN) return 4;
  37. return 42;
  38. }
  39.  
  40. int main() {
  41. Color c1 = Color(Color::RED);
  42. return 0;
  43. }
Success #stdin #stdout 0s 3336KB
stdin
Standard input is empty
stdout
Standard output is empty