awsmpshk

Классы, Кузичкин 141 группа

May 21st, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.41 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Boss
  6. {
  7. private:
  8.   string name;
  9.   int health;
  10.   bool isFinal;
  11.   string abilities;
  12. public:
  13.   static int countFinal, countNotFinal;
  14.  
  15.   bool isCorrect()
  16.   {
  17.     if (health >= 1e5 && health <= 1e7) return true;
  18.     return false;
  19.   }
  20.  
  21.   Boss() == default;
  22.  
  23.   Boss(const Boss& b)
  24.   {
  25.     this->name = b.name;
  26.     this->health = b.health;
  27.     this->isFinal = b.isFinal;
  28.     this->abilities = b.abilities;
  29.   }
  30.  
  31.   Boss(string name, int health, bool isFinal, string abilities)
  32.   {
  33.     if (isFinal) countFinal++;
  34.     else countNotFinal++;
  35.  
  36.     this->name = name;
  37.     if (isCorrect()) this->health = health;
  38.     else this->health = 1e5;
  39.     this->isFinal = isFinal;
  40.     this->abilities = abilities;
  41.   }
  42.  
  43.   void setName(string name)
  44.   {
  45.     this->name = name;
  46.   }
  47.  
  48.   void setHealth(int health)
  49.   {
  50.     this->health = health;
  51.   }
  52.  
  53.   void setIsFinal(bool isFinal)
  54.   {
  55.     if (isFinal) countFinal++;
  56.     else countNotFinal++;
  57.     this->isFinal = isFinal;
  58.   }
  59.  
  60.   void setAbilities(string abilities)
  61.   {
  62.     this->abilities = abilities;
  63.   }
  64.  
  65.   friend bool operator==(const Boss& b)
  66.   {
  67.     if (this->isFinal() && b.isFinal() || !this->isFinal() && !b.isFinal())
  68.     {
  69.       if (this->health == b.health)
  70.       {
  71.         if (this->abilities.length() == b.abilities.length())
  72.         {
  73.           return true;
  74.         }
  75.       }
  76.     }
  77.     return false;
  78.   }
  79.  
  80.   friend bool operator<(const Boss& b)
  81.   {
  82.     if (!this->isFinal && b.isFinal) return true;
  83.     else if ((this->isFinal && b.isFinal || !this->isFinal && !b.isFinal) && this->health < b.health) return true;
  84.     else if (this->health == b.health && this->abilities.length() < b.abilities.length()) return true;
  85.     return false;
  86.   }
  87.  
  88.   friend ostream& operator<<(ostream& out, const Boss& b)
  89.   {
  90.     out << b.name << " " << b.health << " " << (b.isFinal ? "true" : "false") << endl;
  91.     out << b.abilities << endl << endl;
  92.   }
  93. };
  94.  
  95. int Boss::countFinal = 0, Boss::countNotFinal = 0;
  96.  
  97. int main()
  98. {
  99.   string name, abilities;
  100.   int health;
  101.   bool isFinal;
  102.   Boss b1("pasha", 1e7 - 23, true, "he's very strong"), b2(b1);
  103.   Boss b3("rauf", 1e7 + 1000, false, "he's trying to cheat with health.");
  104.   cout << (b1 == b2) << " " << (b1 < b2) << " " << (b2 < b3) << " " << (b1 == b3);
  105.   cout << Boss::countFinal << " " << Boss:countNotFinal;
  106.   cout << b1 << b2 << b3;
  107.   return 0;
  108. }
Add Comment
Please, Sign In to add comment