35657

Untitled

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