Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.28 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. using namespace std;
  4.  
  5. class Bohater {
  6. private:
  7. string pseudonim;
  8. string klasa;
  9. int sila_ataku; //pola prywatnne
  10. static int licznik;
  11. public:
  12.  
  13. Bohater()
  14. { //konstruktor domyślny
  15.  
  16.  
  17. }
  18. Bohater(Bohater* b, int sila_ataku)
  19. {
  20. this->pseudonim = b->getPseudonim();
  21. this->klasa = b->getKlasa();
  22. this->sila_ataku = sila_ataku; //kontruktor kopiujący
  23. wyswietl();
  24.  
  25. }
  26. ~Bohater()
  27. {
  28.  
  29. } //destruktor
  30.  
  31.  
  32. string getPseudonim()
  33. { //akcesor getter dzięki niemu możemy odczytać prywatne pole
  34. return this->pseudonim;
  35. }
  36. string getKlasa()
  37. {
  38. return this->klasa;
  39. }
  40. int getSila_ataku()
  41. {
  42. return this->sila_ataku;
  43. }
  44. static int getLicznik()
  45. {
  46. return licznik;
  47. }
  48. void setPseudonim(string p)
  49. {
  50. this->pseudonim = p; // setter pozwala na zmienianie prywatnego pola
  51.  
  52. }
  53. void setKlasa(string k)
  54. {
  55. this->klasa = k;
  56.  
  57. }
  58. void setSila_ataku(int s)
  59. {
  60. this->sila_ataku = s;
  61.  
  62. }
  63.  
  64.  
  65. void wyswietl()
  66. {
  67. cout << "pseudonim: " << this->pseudonim << endl;
  68. cout << "klasa: " << this->klasa << endl; //wyświetlanie
  69. cout << "sila: " << this->sila_ataku << endl;
  70. }
  71.  
  72.  
  73.  
  74. };
  75. class Ekwipunek // klasa ekwipuntek
  76. {
  77. private:
  78. string rodzaj; //pola prywantne klasy ekwipunek
  79. string material;
  80. float wartosc;
  81. Bohater* bohater_wsk;
  82.  
  83. public:
  84. Ekwipunek()
  85. {
  86. wyswietl();
  87. }
  88. Ekwipunek(string rodzaj, string material, float wartosc, Bohater* b)
  89. {
  90. this->rodzaj = getRodzaj();
  91. this->material = getMaterial();
  92. this->wartosc = getWartosc();
  93. this->bohater_wsk = b;
  94. }
  95. string getRodzaj()
  96. {
  97. return this->rodzaj;
  98.  
  99. }
  100. string getMaterial()
  101. {
  102. return this->material;
  103.  
  104. }
  105. float getWartosc()
  106. {
  107. return this->wartosc;
  108. }
  109. void setRodzaj(string r)
  110. {
  111. this->rodzaj = r;
  112. }
  113. void setMaterial(string m)
  114. {
  115. this->material = m;
  116. }
  117. void setWartosc(float w)
  118. {
  119. this->wartosc = w;
  120. }
  121. void setBohater_wsk(Bohater* b)
  122. {
  123. this->bohater_wsk = b;
  124. }
  125. void wyswietl()
  126. {
  127. cout << "rodzaj: " << this->rodzaj<< endl;
  128. cout << "material: " << this-> material << endl;
  129. cout << "wartość: " << this->wartosc << endl;
  130. cout << "klasa: " << bohater_wsk->getKlasa() << endl;
  131. }
  132.  
  133. };
  134.  
  135. int main()
  136. {
  137. Bohater* b1 = new Bohater;
  138. b1->setPseudonim("aaron");
  139. b1->setKlasa("mag");
  140. b1->setSila_ataku(10);
  141. b1->Bohater::wyswietl();
  142.  
  143.  
  144. Bohater b2(b1, 93);
  145. int suma_sily=0;
  146. Bohater** obiekty = new Bohater*[2];
  147.  
  148.  
  149.  
  150. obiekty[0][0].setPseudonim("xd");
  151. obiekty[0][0].setKlasa("mag");
  152. obiekty[0][0].setSila_ataku(55);
  153. obiekty[1][1].setPseudonim("bum");
  154. obiekty[1][1].setKlasa("złodziej");
  155. obiekty[1][1].setSila_ataku(56);
  156.  
  157. for (int i = 0; i < 2; i++)
  158. {
  159. for (int j = 0; j < 2; j++)
  160. {
  161. suma_sily = suma_sily + obiekty[i][j].getSila_ataku();
  162. obiekty[i][j].wyswietl();
  163. }
  164. }
  165.  
  166. cout << "suma sił ataku bohaterów:" << suma_sily << endl;
  167.  
  168. for (int i = 0; i < 2; i++)
  169. {
  170. delete[] obiekty[i];
  171. }
  172.  
  173. Ekwipunek obiekt_ekwip_1;
  174. obiekt_ekwip_1.setRodzaj("broń");
  175. obiekt_ekwip_1.setMaterial("stal");
  176. obiekt_ekwip_1.setWartosc(45.5);
  177. obiekt_ekwip_1.setBohater_wsk(&b2);
  178. obiekt_ekwip_1.wyswietl();
  179.  
  180. system("pause");
  181. return 0;
  182. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement