Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string>
- #include <iostream>
- using namespace std;
- // домашнее животное
- class Pet {
- public:
- Pet(string name, int age, string color) : name_(name), age_(age), color_(color) {}
- string GetName() const {
- return name_;
- }
- void SetAge(int age) {
- age_ = age;
- }
- int GetAge() const {
- return age_;
- }
- string GetColor() const {
- return color_;
- }
- private:
- string name_;
- int age_;
- string color_;
- };
- class Dog : public Pet {
- public:
- Dog(string name, int age, string color, string breed) : Pet(name, age, color), breed_(breed) {}
- string GetBreed() const {
- return breed_;
- }
- private:
- string breed_;
- };
- class Cat : public Pet {
- public:
- Cat(string name, int age, string color, bool longhair) : Pet(name, age, color), longhair_(longhair) {}
- string Longhair() const {
- return longhair_ ? "longhair" : "shorthair";
- }
- private:
- bool longhair_;
- };
- class Parrot : public Pet {
- public:
- Parrot(string name, int age, string color, bool talking) : Pet(name, age, color), talking_(talking) {}
- string Talking() const {
- return talking_ ? "talking" : "not talking";
- }
- private:
- bool talking_;
- };
- int main() {
- setlocale(LC_ALL, "ru");
- Dog dog("Rex", 2, "black", "shepherd");
- Cat cat("Lucky", 1, "white", true);
- Parrot parrot("Gosha", 3, "yellow", true);
- cout << dog.GetName() << " " << dog.GetAge() << " " << dog.GetColor() << " " << dog.GetBreed() << endl;
- cout << cat.GetName() << " " << cat.GetAge() << " " << cat.GetColor() << " " << cat.Longhair() << endl;
- cout << parrot.GetName() << " " << parrot.GetAge() << " " << parrot.GetColor() << " " << parrot.Talking() << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement