fork download
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <cstring>
  4. #include <algorithm>
  5.  
  6. class Hero {
  7. private:
  8. std::string name;
  9. int level;
  10. public:
  11. Hero(std::string name) : name(name), level(0) {}
  12. std::string getName() { return name; }
  13. int getLevel() { return level; }
  14. void levelAdd(int num) { level += num; }
  15. };
  16.  
  17. class RevNameQuest {
  18. private:
  19. Hero& hero;
  20. public:
  21. RevNameQuest(Hero& hero) : hero(hero) {}
  22.  
  23. void start() {
  24. std::string answer;
  25. std::cout << "Podaj swoje imie wspak: " << std::endl;
  26. std::cin >> answer;
  27. std::reverse(answer.begin(),answer.end());
  28. if(answer == hero.getName()) {
  29. hero.levelAdd(1);
  30. std::cout << "Brawo"<<hero.getName()
  31. <<" wykonales quest!" << std::endl;
  32. }
  33. }
  34. };
  35.  
  36. using namespace std;
  37.  
  38. int main() {
  39. string name;
  40. cout << "Podaj imie dla swojej postaci: " << endl;
  41. cin >> name;
  42. Hero hero(name);
  43. cout << "level twojej postaci: " << hero.getLevel() << endl;
  44. RevNameQuest quest(hero);
  45. quest.start();
  46. cout << "level twojej postaci: " << hero.getLevel() << endl;
  47. return 0;
  48. }
  49.  
Success #stdin #stdout 0s 3480KB
stdin
Ala
alA
stdout
Podaj imie dla swojej postaci: 
level twojej postaci: 0
Podaj swoje imie wspak: 
BrawoAla wykonales quest!
level twojej postaci: 1