Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- class Tail
- {
- protected:
- int length;
- public:
- Tail() // конструктор по умолчанию
- {
- length = NULL;
- }
- Tail(int length) // конструктор с параметром
- {
- this->length = length;
- }
- int GetTailLength()
- {
- return length;
- }
- };
- class Dogs
- {
- protected:
- Tail* tail;
- string color;
- int age;
- public:
- Dogs() // конструктор по умолчанию
- {
- tail = new Tail();
- color = "";
- age = NULL;
- }
- Dogs(int tailLength, string color, int age) // с параметрами
- {
- tail = new Tail(tailLength);
- this->color = color;
- this->age = age;
- }
- ~Dogs() {} // деструктор
- };
- class Dog : Dogs
- {
- private:
- string nickname;
- public:
- Dog() : Dogs() // конструктор по умолчанию
- {
- nickname = "";
- }
- Dog(string nickname, int tailLength, string color, int age) : Dogs(tailLength, color, age) // с параметрами
- {
- this->nickname = nickname;
- }
- void PrintInfo()
- {
- cout << "Кличка: " << nickname << endl;
- cout << "Длина хвоста: " << tail->GetTailLength() << endl;
- cout << "Цвет: " << color << endl;
- cout << "Возраст: " << age << endl;
- }
- ~Dog() {} // деструктор
- };
- int main()
- {
- Dog dog("Шарик", 12, "Черный", 4);
- dog.PrintInfo();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement