Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <set>
- #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_;
- }
- 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) : Pet(name, age, color) {};
- void AddFood(string food) {
- food_.insert(food);
- }
- bool CanEat(string food) const {
- return food_.count(food);
- }
- void SetMove(string move) {
- move_ = move;
- }
- string GetMove()const {
- return move_;
- }
- private:
- set<string> food_;
- string move_;
- };
- //class Cat : public Pet {
- //public:
- //
- //private:
- // string Food;
- // string Voice;
- // string Move;
- //
- //};
- //class Parrot : public Pet {
- //public:
- //
- //private:
- // string Food;
- // string Voice;
- // string Move;
- //};
- int main() {
- setlocale(LC_ALL, "ru");
- Dog my_dog("Dingo", 4, "black");
- my_dog.AddFood("meat");
- my_dog.SetMove("run");
- cout << "my favourite dog is " << my_dog.GetName() << " " << "it is" << " " << my_dog.GetAge() << " years old" << endl;
- cout << "Yur dog can eat meat? " << endl;
- cout << boolalpha << my_dog.CanEat("meat") << endl;
- cout << my_dog.GetName() << " " << "like" << " " << my_dog.GetMove() << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment