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_.insert(move);
- }
- bool CanMove(string move)const {
- return move_.count(move);
- }
- void ShowMove() {
- for (auto a : move_) {
- cout << a << " ";
- }
- cout << endl;
- }
- void ShowEat() {
- for (auto a : food_) {
- cout << a << " ";
- }
- cout << endl;
- }
- private:
- set<string> food_;
- set<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.CanMove("run") << endl;
- my_dog.AddFood("milk");
- my_dog.AddFood("chiken");
- my_dog.ShowEat();
- }
Advertisement
Add Comment
Please, Sign In to add comment