Infiniti_Inter

персонаж(Алиса)

Dec 19th, 2019
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.46 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <algorithm>
  4. #include <fstream>
  5. #include <queue>
  6.  
  7. using namespace std;
  8.  
  9.  
  10. ifstream in("input.txt");
  11. ofstream out("output.txt");
  12.  
  13. class Character {
  14. private:
  15.     string nick;
  16.     int type;
  17.     int difficulty;
  18.    
  19.  
  20.  
  21.  
  22.     string IntToStirng(int d)
  23.     {
  24.         string res = "0";
  25.         res[0] += d;
  26.         return res;
  27.     }
  28.  
  29. public:
  30.     static int count[3];
  31.     Character(string name, int type = 1)
  32.     {
  33.         nick = name;
  34.         difficulty = 1;
  35.         if (type > 0 && type < 4)
  36.         {
  37.             count[type - 1]++;
  38.             this->type = type;
  39.         }
  40.     }
  41.     Character(string name, int type, int difficulty) : Character(name, type)
  42.     {
  43.         if (difficulty > 0 && difficulty < 6)
  44.             this->difficulty = difficulty;
  45.     }
  46.     Character() {};
  47.     void ChangeName(string name)
  48.     {
  49.         out << nick << "----> successfully changed his name to "
  50.             << name << endl;
  51.         nick = name;
  52.     }
  53.     void SetType(int type)
  54.     {
  55.         if (type > 0 && type < 4)
  56.         {
  57.             out << nick << "----> Class " << Character::GetType(this->type) << " successfully changed to "
  58.                 << Character::GetType(type) << endl;
  59.             count[this->type - 1]--;
  60.             count[type - 1]++;
  61.             this->type = type;
  62.         }
  63.  
  64.     }
  65.     void SetDifficulty(int difficulty)
  66.     {
  67.         if (difficulty > 0 && difficulty < 6)
  68.         {
  69.             out << nick << "----> difficulty changed from " << this->difficulty << " to "
  70.                 << difficulty << endl;
  71.             this->difficulty = difficulty;
  72.         }
  73.     }
  74.     static string GetType(int type)
  75.     {
  76.         return type == 1 ? "Damage dealer" : type == 2 ? "Healer" : "Tank";
  77.     }
  78.  
  79.     string GetCharacterToPrint()
  80.     {
  81.         string res = "Nickname : " + nick + "\nClass : " +
  82.             Character::GetType(type) + "\nDifficulty : " +
  83.             IntToStirng(difficulty) + "\n\n";
  84.         return res;
  85.     }
  86.  
  87.     bool operator != (Character object)
  88.     {
  89.         if (this->type != object.type || this->difficulty != object.difficulty)
  90.             return true;
  91.         return false;
  92.     }
  93.  
  94.     bool operator <=(Character object)
  95.     {
  96.         if (this->type < object.type)
  97.             return true;
  98.         if (this->type == object.type && this->difficulty <= object.difficulty)
  99.             return true;
  100.         return false;
  101.     }
  102.  
  103.  
  104. };
  105.  
  106. int Character::count[3] = { 0, 0, 0 };
  107.  
  108. int main()
  109. {
  110.     int n;
  111.     in >> n;
  112.     Character * a = new Character[n];
  113.     out << "count of characters\n";
  114.     for (int i = 0; i < 3; ++i)
  115.         out << Character::GetType(i + 1) << " : " << Character::count[i] << "\n";
  116.     for (int i = 0; i < n; ++i)
  117.     {
  118.         string name; int t, d;
  119.         in >> name >> t >> d;
  120.         a[i] = Character(name, t, d);
  121.     }
  122.     out << "\n" << n << " characters was created!\n\n";
  123.     out << "new count of characters\n";
  124.     for (int i = 0; i < 3; ++i)
  125.         out << Character::GetType(i + 1) << " : " << Character::count[i] << "\n";
  126.  
  127.    
  128.  
  129.  
  130.     //использование методов
  131.  
  132.     out << "\nchange log:\n";
  133.     a[1].SetDifficulty(5);
  134.     a[1].SetType(1);
  135.     a[2].SetType(3);
  136.  
  137.  
  138.     // проверка оператора !=
  139.     Character Dad = Character("Dad", 1, 1);
  140.     out << (Dad != a[3] == 0 ? "false" : "true") << endl;
  141.     a[3].ChangeName("BigDaddyCoolNecit");
  142.     a[3].SetDifficulty(3);
  143.     out << (Dad != a[3] == 0 ? "false" : "true") << endl << endl;
  144.  
  145.     //проверка оператора <=
  146.     for (int i = 0; i < n; ++i)
  147.         out << (a[i] <= a[(i + 1)%n] ? "false" : "true") << endl;
  148.  
  149.     out << "\n\n\n";
  150.     for (int i = 0; i < n; ++i)
  151.         out << a[i].GetCharacterToPrint();
  152.     out << Dad.GetCharacterToPrint();
  153.  
  154.     out << "count of \n";
  155.     for (int i = 0; i < 3; ++i)
  156.         out << Character::GetType(i + 1) << " : " << Character::count[i] << "\n";
  157.  
  158. }
  159. /*
  160. 4
  161. Decibit 2 5
  162. Mud 3 2
  163. Kirokyri 1 4
  164. Dad 1 1
  165. */
Add Comment
Please, Sign In to add comment