Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.96 KB | None | 0 0
  1. #include <iostream>
  2. class BlackPanther {
  3.  
  4. private:
  5.     int age;
  6.     std::string habitat;
  7.     double weight;
  8.     bool gender;  // true --> 1 --> females // false --> 0 --> males
  9.     bool birth;
  10.  
  11. public:
  12.     BlackPanther() {
  13.         age = 0;
  14.         habitat = "";
  15.         weight = 0;
  16.         gender = false;
  17.         birth = false;
  18.     }
  19.     BlackPanther(int a, std::string h, double w, bool g, bool b) {
  20.         age = a;
  21.         habitat = h;
  22.         weight = w;
  23.         gender = g;
  24.         birth = b;
  25.     }
  26.     BlackPanther(int a) {
  27.         age = a;
  28.         habitat = "";
  29.         weight = 0;
  30.         gender = 0;
  31.         birth = 0;
  32.     }
  33.     //setters
  34.     void setAge(int a) {
  35.         age = a;
  36.     }
  37.  
  38.     void setHabitat(std::string h) {
  39.         habitat = h;
  40.     }
  41.  
  42.     void setWeight(double w) {
  43.         weight = w;
  44.     }
  45.  
  46.     void setGender(bool g) {
  47.         gender = g;
  48.     }
  49.  
  50.     void setBirth(bool b) {
  51.         birth = b;
  52.     }
  53.  
  54.     //getters
  55.  
  56.     int getAge() {
  57.         return age;
  58.     }
  59.  
  60.     std::string getHabitat() {
  61.         return habitat;
  62.     }
  63.  
  64.     double getWeight() {
  65.         return weight;
  66.     }
  67.  
  68.     bool getGender() {
  69.         return gender;
  70.     }
  71.  
  72.     bool getBirth() {
  73.         return birth;
  74.     }
  75.  
  76.  
  77.  
  78.  
  79.     void eatAnimal(int prey_weight) {
  80.         weight += (double)prey_weight / 100;
  81.     }
  82.     void breed(std::string h, bool g) {
  83.         if (habitat == h && gender != g) {
  84.             //std::cout << "H anaparagwgh pragmatopoihthike" << std::endl;
  85.             printf("H anaparagwgh pragmatopoihthike\n");
  86.             birth = true;
  87.         }
  88.         else {
  89.             //std::cout << "H anaparagwgh den pragmatopoihthike" << std::endl;
  90.             printf("H anaparagwgh den pragmatopoihthike\n");
  91.         }
  92.  
  93.     }
  94.  
  95.     void searchFood() {
  96.         age++;
  97.     }
  98.     void printAll() {
  99.         std::cout << "Age: " << age << ", Habitat: " << habitat << ", Weight: " << ((gender) ? "female" : "male") <<((birth) ? "gave birth" : "didnt give birth") << std::endl;
  100.     }
  101.  
  102.     void has_mated() {
  103.         (birth) ? age = age : age += 2;
  104.     }
  105.  
  106. };
  107.  
  108.  
  109.  
  110.  
  111.  
  112. int main() {
  113.     BlackPanther b1 = BlackPanther(4, "Afriki", 65, true, false);
  114.     BlackPanther b2 = BlackPanther(4, "Afriki", 65, false, false);
  115.     BlackPanther b3 = BlackPanther(4, "N. Asia", 65, true, false);
  116.  
  117.     b1.eatAnimal(7);
  118.     b2.eatAnimal(5);
  119.     b3.eatAnimal(13);
  120.  
  121.     //cout<<b1.getWeight()<<endl<<b2.getWeight()<<endl<<b3.getWeight()<<endl;
  122.  
  123.    
  124.  
  125.     if (b1.getWeight() > b2.getWeight()) {
  126.         std::cout << "b11" << std::endl;
  127.         if (b1.getWeight() > b3.getWeight()) {
  128.             b1.breed(b2.getHabitat(), b2.getGender());
  129.             b1.breed(b3.getHabitat(), b3.getGender());
  130.         }
  131.     }
  132.     if (b2.getWeight() > b1.getWeight()) {
  133.         std::cout << "b21" << std::endl;
  134.         if (b2.getWeight() > b3.getWeight()) {
  135.             b2.breed(b1.getHabitat(), b1.getGender());
  136.             b2.breed(b3.getHabitat(), b3.getGender());
  137.         }
  138.     }
  139.     if (b3.getWeight() > b1.getWeight()) {
  140.         std::cout << "b31" << std::endl;
  141.         if (b3.getWeight() > b2.getWeight()) {
  142.             b3.breed(b1.getHabitat(), b1.getGender());
  143.             b3.breed(b2.getHabitat(), b2.getGender());
  144.         }
  145.     }
  146.  
  147.     if (b1.getWeight() < b2.getWeight()) {
  148.         std::cout << "b11" << std::endl;
  149.         if (b1.getWeight() < b3.getWeight()) {
  150.             b1.breed(b2.getHabitat(), b2.getGender());
  151.             b1.breed(b3.getHabitat(), b3.getGender());
  152.         }
  153.     }
  154.     if (b2.getWeight() < b1.getWeight()) {
  155.         std::cout << "b21" << std::endl;
  156.         if (b2.getWeight() < b3.getWeight()) {
  157.             b2.breed(b1.getHabitat(), b1.getGender());
  158.             b2.breed(b3.getHabitat(), b3.getGender());
  159.         }
  160.     }
  161.     if (b3.getWeight() < b1.getWeight()) {
  162.         std::cout << "b31" << std::endl;
  163.         if (b3.getWeight() < b2.getWeight()) {
  164.             b3.breed(b1.getHabitat(), b1.getGender());
  165.             b3.breed(b2.getHabitat(), b2.getGender());
  166.         }
  167.     }
  168.  
  169.     b1.searchFood();
  170.     b3.searchFood();
  171.  
  172.     if (b3.getAge() < b1.getAge()) {
  173.         std::cout << "b31" << std::endl;
  174.         if (b3.getAge() < b2.getAge()) {
  175.             b3.breed(b1.getHabitat(), b1.getGender());
  176.             b3.breed(b2.getHabitat(), b2.getGender());
  177.         }
  178.     }
  179.  
  180.     if (b1.getAge() < b2.getAge()) {
  181.         std::cout << "b11" << std::endl;
  182.         if (b1.getAge() < b3.getAge()) {
  183.             b1.breed(b2.getHabitat(), b2.getGender());
  184.             b1.breed(b3.getHabitat(), b3.getGender());
  185.         }
  186.     }
  187.     if (b2.getAge() < b1.getAge()) {
  188.         std::cout << "b21" << std::endl;
  189.         if (b2.getAge() < b3.getAge()) {
  190.             b2.breed(b1.getHabitat(), b1.getGender());
  191.             b2.breed(b3.getHabitat(), b3.getGender());
  192.         }
  193.     }
  194.    
  195.     b1.has_mated();
  196.     b2.has_mated();
  197.     b3.has_mated();
  198.  
  199.  
  200.    
  201.     b1.printAll();
  202.     b2.printAll();
  203.     b3.printAll();
  204. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement