Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //struct Apple
- //{
- // int health = 10;
- //};
- //
- //struct Orange
- //{
- // int health = 5;
- //};
- //
- //class Cat
- //{
- //public:
- //
- // void Meow() const
- // {
- // cout << "meow! " << endl;
- // }
- // void Eat(const Apple& a)
- // {
- // cout << "Cat eats apple. " << a.health << "hp." << endl;
- // }
- // void Eat(const Orange& o)
- // {
- // cout << "Cat eats orange. " << o.health << "hp." << endl;
- // }
- //};
- //
- //class Dog
- //{
- //public:
- //
- // void Eat(const Apple& a)
- // {
- // cout << "Dog eats apple. " << a.health << "hp." << endl;
- // }
- // void Eat(const Orange& o)
- // {
- // cout << "Dog eats orange. " << o.health << "hp." << endl;
- // }
- //};
- //------------------------------------------------------------------------------------
- //struct Fruit
- //{
- // int health = 0;
- // string type = "fruit";
- //
- //};
- //struct Apple : public Fruit
- //{
- // Apple()
- // {
- // health = 10;
- // type = "apple";
- // }
- //};
- //
- //struct Orange : public Fruit
- //{
- // Orange()
- // {
- // health = 5;
- // type = "orange";
- // }
- //};
- //
- //struct PineApple : public Fruit
- //{
- // PineApple()
- // {
- // health = 15;
- // type = "pineapple";
- // }
- //};
- //
- //class Cat
- //{
- //public:
- //
- // void Meow() const
- // {
- // cout << "meow! " << endl;
- // }
- // void Eat(const Fruit& f)
- // {
- // cout << "Cat eats " << f.type << ". " << f.health << "hp." << endl;
- // }
- //
- //};
- //
- //class Dog
- //{
- //public:
- //
- // void Eat(const Fruit& f)
- // {
- // cout << "Cat eats " << f.type << ". " << f.health << "hp." << endl;
- // }
- //
- //};
- //------------------------------------------------------------------------------------
- #include <iostream>
- using namespace std;
- struct Fruit
- {
- int health = 0;
- string type = "fruit";
- };
- struct Apple : public Fruit
- {
- Apple()
- {
- health = 10;
- type = "apple";
- }
- };
- struct Orange : public Fruit
- {
- Orange()
- {
- health = 5;
- type = "orange";
- }
- };
- struct PineApple : public Fruit
- {
- PineApple()
- {
- health = 15;
- type = "pineapple";
- }
- };
- class Animal
- {
- public:
- void Eat(const Fruit& f)
- {
- cout << type << " eats " << f.type << ". " << f.health << "hp." << endl;
- }
- string type = "animal";
- };
- class Cat : public Animal
- {
- public:
- Cat()
- {
- type = "cat";
- }
- void Meow() const
- {
- cout << "meow! " << endl;
- }
- };
- class Dog : public Animal
- {
- public:
- Dog()
- {
- type = "dog";
- }
- };
- void DoMeal(Animal& a, Fruit& f)
- {
- a.Eat(f);
- a.type += "*";
- }
- int main()
- {
- /*Cat c;
- c.Meow();
- Apple a;
- c.Eat(a);
- Orange o;
- c.Eat(o);*/
- Dog d;
- /*d.Eat(a);*/
- PineApple p;
- DoMeal(d, p);
- DoMeal(d, p);
- DoMeal(d, p);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement