fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Cat
  5. {
  6. public:
  7. string name;
  8. int age;
  9.  
  10. Cat(string c, int a)
  11. {
  12. name = c;
  13. age = a;
  14. }
  15.  
  16. void getData()
  17. {
  18. cout << "Yours cat name is " << name << endl;
  19. cout << "And he/she is " << age << " years old." << endl;
  20. }
  21.  
  22. // Перевантаження оператора +
  23. Cat operator+(const Cat& other)
  24. {
  25. string newName = name + "_" + other.name;
  26. int newAge = age + other.age;
  27. return Cat(newName, newAge);
  28. }
  29. };
  30.  
  31. int main()
  32. {
  33. string s1, s2;
  34. int d1, d2;
  35.  
  36. cin >> s1 >> d1;
  37. cin >> s2 >> d2;
  38.  
  39. Cat first(s1, d1);
  40. Cat second(s2, d2);
  41.  
  42. Cat result = first + second;
  43.  
  44. result.getData();
  45.  
  46. return 0;
  47. }
  48.  
  49.  
Success #stdin #stdout 0.01s 5308KB
stdin
ВАся
Буч
stdout
Yours cat name is ВАся_
And he/she is -2006564054 years old.