Advertisement
azMenRoxL

s

Jan 23rd, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. class Tail
  6. {
  7. protected:
  8.     int length;
  9. public:
  10.     Tail() // конструктор по умолчанию
  11.     {
  12.         length = NULL;
  13.     }
  14.     Tail(int length) // конструктор с параметром
  15.     {
  16.         this->length = length;
  17.     }
  18.     int GetTailLength()
  19.     {
  20.         return length;
  21.     }
  22. };
  23.  
  24. class Dogs
  25. {
  26. protected:
  27.     Tail* tail;
  28.     string color;
  29.     int age;
  30. public:
  31.     Dogs() // конструктор по умолчанию
  32.     {
  33.         tail = new Tail();
  34.         color = "";
  35.         age = NULL;
  36.     }
  37.     Dogs(int tailLength, string color, int age) // с параметрами
  38.     {
  39.         tail = new Tail(tailLength);
  40.         this->color = color;
  41.         this->age = age;
  42.     }
  43.     ~Dogs() {} // деструктор
  44. };
  45.  
  46. class Dog : Dogs
  47. {
  48. private:
  49.     string nickname;
  50. public:
  51.     Dog() : Dogs() // конструктор по умолчанию
  52.     {
  53.         nickname = "";
  54.     }
  55.     Dog(string nickname, int tailLength, string color, int age) : Dogs(tailLength, color, age) // с параметрами
  56.     {
  57.         this->nickname = nickname;
  58.     }
  59.     void PrintInfo()
  60.     {
  61.         cout << "Кличка: " << nickname << endl;
  62.         cout << "Длина хвоста: " << tail->GetTailLength() << endl;
  63.         cout << "Цвет: " << color << endl;
  64.         cout << "Возраст: " << age << endl;
  65.     }
  66.     ~Dog() {} // деструктор
  67. };
  68.  
  69.  
  70. int main()
  71. {
  72.     Dog dog("Шарик", 12, "Черный", 4);
  73.     dog.PrintInfo();
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement