Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <algorithm>
- #include <fstream>
- #include <queue>
- using namespace std;
- ifstream in("input.txt");
- ofstream out("output.txt");
- class Character {
- private:
- string nick;
- int type;
- int difficulty;
- string IntToStirng(int d)
- {
- string res = "0";
- res[0] += d;
- return res;
- }
- public:
- static int count[3];
- Character(string name, int type = 1)
- {
- nick = name;
- difficulty = 1;
- if (type > 0 && type < 4)
- {
- count[type - 1]++;
- this->type = type;
- }
- }
- Character(string name, int type, int difficulty) : Character(name, type)
- {
- if (difficulty > 0 && difficulty < 6)
- this->difficulty = difficulty;
- }
- Character() {};
- void ChangeName(string name)
- {
- out << nick << "----> successfully changed his name to "
- << name << endl;
- nick = name;
- }
- void SetType(int type)
- {
- if (type > 0 && type < 4)
- {
- out << nick << "----> Class " << Character::GetType(this->type) << " successfully changed to "
- << Character::GetType(type) << endl;
- count[this->type - 1]--;
- count[type - 1]++;
- this->type = type;
- }
- }
- void SetDifficulty(int difficulty)
- {
- if (difficulty > 0 && difficulty < 6)
- {
- out << nick << "----> difficulty changed from " << this->difficulty << " to "
- << difficulty << endl;
- this->difficulty = difficulty;
- }
- }
- static string GetType(int type)
- {
- return type == 1 ? "Damage dealer" : type == 2 ? "Healer" : "Tank";
- }
- string GetCharacterToPrint()
- {
- string res = "Nickname : " + nick + "\nClass : " +
- Character::GetType(type) + "\nDifficulty : " +
- IntToStirng(difficulty) + "\n\n";
- return res;
- }
- bool operator != (Character object)
- {
- if (this->type != object.type || this->difficulty != object.difficulty)
- return true;
- return false;
- }
- bool operator <=(Character object)
- {
- if (this->type < object.type)
- return true;
- if (this->type == object.type && this->difficulty <= object.difficulty)
- return true;
- return false;
- }
- };
- int Character::count[3] = { 0, 0, 0 };
- int main()
- {
- int n;
- in >> n;
- Character * a = new Character[n];
- out << "count of characters\n";
- for (int i = 0; i < 3; ++i)
- out << Character::GetType(i + 1) << " : " << Character::count[i] << "\n";
- for (int i = 0; i < n; ++i)
- {
- string name; int t, d;
- in >> name >> t >> d;
- a[i] = Character(name, t, d);
- }
- out << "\n" << n << " characters was created!\n\n";
- out << "new count of characters\n";
- for (int i = 0; i < 3; ++i)
- out << Character::GetType(i + 1) << " : " << Character::count[i] << "\n";
- //использование методов
- out << "\nchange log:\n";
- a[1].SetDifficulty(5);
- a[1].SetType(1);
- a[2].SetType(3);
- // проверка оператора !=
- Character Dad = Character("Dad", 1, 1);
- out << (Dad != a[3] == 0 ? "false" : "true") << endl;
- a[3].ChangeName("BigDaddyCoolNecit");
- a[3].SetDifficulty(3);
- out << (Dad != a[3] == 0 ? "false" : "true") << endl << endl;
- //проверка оператора <=
- for (int i = 0; i < n; ++i)
- out << (a[i] <= a[(i + 1)%n] ? "false" : "true") << endl;
- out << "\n\n\n";
- for (int i = 0; i < n; ++i)
- out << a[i].GetCharacterToPrint();
- out << Dad.GetCharacterToPrint();
- out << "count of \n";
- for (int i = 0; i < 3; ++i)
- out << Character::GetType(i + 1) << " : " << Character::count[i] << "\n";
- }
- /*
- 4
- Decibit 2 5
- Mud 3 2
- Kirokyri 1 4
- Dad 1 1
- */
Add Comment
Please, Sign In to add comment