35657

Untitled

Jul 21st, 2023
1,163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.70 KB | None | 0 0
  1. #include <set>
  2. #include <string>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6. class Pet {
  7. public:
  8.  
  9.     Pet(string name, int age, string  color) : name_(name), age_(age), color_(color) {};
  10.  
  11.     string GetName() const {
  12.         return name_;
  13.     }
  14.  
  15.  
  16.     int GetAge() const {
  17.         return age_;
  18.     }
  19.  
  20.  
  21.     string GetColor() const {
  22.         return color_;
  23.     }
  24.  
  25.  
  26.  
  27. private:
  28.     string name_;
  29.     int age_;
  30.     string color_;
  31. };
  32.  
  33. class Dog : public Pet {
  34. public:
  35.     Dog(string name, int age, string color) : Pet(name, age, color) {};
  36.  
  37.     void AddFood(string food) {
  38.         food_.insert(food);
  39.     }
  40.     bool CanEat(string food) const {
  41.         return food_.count(food);
  42.     }
  43.  
  44.     void SetMove(string move) {
  45.         move_.insert(move);
  46.     }
  47.  
  48.     bool CanMove(string move)const {
  49.         return move_.count(move);
  50.     }
  51.  
  52.     void ShowMove() {
  53.         for (auto a : move_) {
  54.             cout << a << " ";
  55.         }
  56.         cout << endl;
  57.      }
  58.  
  59.     void ShowEat() {
  60.         for (auto a : food_) {
  61.             cout << a << " ";
  62.         }
  63.         cout << endl;
  64.     }
  65.  
  66.  
  67. private:
  68.     set<string> food_;
  69.     set<string> move_;
  70. };
  71.  
  72.  
  73. int main() {
  74.     setlocale(LC_ALL, "ru");
  75.  
  76.     Dog my_dog("Dingo", 4, "black");
  77.     my_dog.AddFood("meat");
  78.     my_dog.SetMove("run");
  79.     cout << "my favourite dog is " << my_dog.GetName() << " " << "it is" << " " << my_dog.GetAge() << " years old" << endl;
  80.     cout << "Yur dog can eat meat? " << endl;
  81.     cout << boolalpha << my_dog.CanEat("meat") << endl;
  82.     cout << my_dog.GetName() << " " << "like" << " " << my_dog.CanMove("run") << endl;
  83.  
  84.  
  85.     my_dog.AddFood("milk");
  86.     my_dog.AddFood("chiken");
  87.  
  88.     my_dog.ShowEat();
  89. }
Advertisement
Add Comment
Please, Sign In to add comment