fork download
  1. #include <iostream>
  2. class Animal
  3. {
  4. private:
  5. int a_CUR_food_lvl;
  6. int food_chain_level;
  7. const int a_MAX_food_lvl;
  8. const int a_hunger_rate;
  9.  
  10. public:
  11. Animal(int curr, int max, int rate, int food_chain)
  12. : a_CUR_food_lvl(curr), a_MAX_food_lvl(max),
  13. a_hunger_rate(rate), food_chain_level(food_chain) {}
  14.  
  15. bool canEat(Animal& theAnimal) const
  16. { return food_chain_level > theAnimal.food_chain_level; }
  17. //...
  18. };
  19.  
  20. class Carnivore : public Animal
  21. {
  22. public:
  23. Carnivore(int curr, int max, int rate) : Animal(curr, max, rate, 2) {}
  24. };
  25.  
  26. class Herbivore : public Animal
  27. {
  28. public:
  29. Herbivore(int curr, int max, int rate) : Animal(curr, max, rate, 1) {}
  30. };
  31.  
  32. class Insect : public Animal
  33. {
  34. public:
  35. Insect(int curr, int max, int rate) : Animal(curr, max, rate, 0) {}
  36. };
  37.  
  38. Carnivore Wolf(150, 200, 2);
  39. Carnivore Cheetah(75,125,2);
  40. Herbivore Squirrel(150,200,2);
  41.  
  42. using namespace std;
  43.  
  44. int main()
  45. {
  46. cout << (Wolf.canEat(Squirrel)?"true":"false") << endl;
  47. cout << (Squirrel.canEat(Cheetah)?"true":"false") << endl;
  48. }
  49.  
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
true
false