Advertisement
koyukix

t2

Jan 11th, 2020
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. #include <iostream>
  2. #define ELFY 5
  3.  
  4. using namespace std;
  5.  
  6. class elfiaZygota
  7. {
  8. protected:
  9. int prod;
  10. public:
  11. virtual ~elfiaZygota(){};
  12. virtual int zwrocProd()=0;
  13. };
  14.  
  15. class elf : public elfiaZygota
  16. {
  17. public:
  18. elf();
  19. virtual int zwrocProd();
  20. };
  21. elf::elf()
  22. {
  23. cout<<"Tu elf."<<endl;
  24. prod=5;
  25. }
  26. int elf::zwrocProd()
  27. {
  28. return prod;
  29. }
  30.  
  31. class superElf : public elf
  32. {
  33. protected:
  34. int sila;
  35. public:
  36. superElf(int a, int b);
  37. virtual int zwrocProd();
  38. };
  39. superElf::superElf(int a, int b)
  40. {
  41. cout<<"Tu superElf."<<endl;
  42. prod=a;
  43. sila=b;
  44. }
  45. int superElf::zwrocProd()
  46. {
  47. return sila*prod;
  48. }
  49. class elfMutant : public elfiaZygota
  50. {
  51. public:
  52. elfMutant();
  53. virtual int zwrocProd();
  54. };
  55. elfMutant::elfMutant()
  56. {
  57. cout<<"Tu elfMutant."<<endl;
  58. prod=-2;
  59. }
  60. int elfMutant::zwrocProd()
  61. {
  62. return prod;
  63. }
  64. class goblin : public elfMutant
  65. {
  66. protected:
  67. int sila;
  68. public:
  69. goblin(int a, int b);
  70. virtual int zwrocProd();
  71. goblin operator+(elf& arg);
  72. };
  73. goblin::goblin(int a, int b)
  74. {
  75. cout<<"Tu goblin."<<endl;
  76. int c;
  77. c=a*-1;
  78. prod=c;
  79. sila=b;
  80. }
  81. int goblin::zwrocProd()
  82. {
  83. return prod*sila;
  84. }
  85. goblin goblin::operator+(elf& arg)
  86. {
  87. goblin tmp(elf.zwrocProd(), 2);
  88.  
  89. return tmp;
  90. }
  91.  
  92. void obliczProdukcje(elfiaZygota* tablicaElfow[ELFY])
  93. {
  94.  
  95. int suma=0;
  96. cout<<endl;
  97. for (int i=0; i<ELFY; i++)
  98. {
  99. suma= suma+tablicaElfow[i]->zwrocProd();
  100. }
  101. if(suma>0)
  102. cout<<"tak";
  103. else cout<< "nie";
  104.  
  105. }
  106.  
  107.  
  108. int main () {
  109. elfiaZygota* tablicaElfow[ELFY];
  110. elf Lesnik;
  111. tablicaElfow[0] = (elfiaZygota*)&Lesnik;
  112. tablicaElfow[1] = new elfMutant();
  113. tablicaElfow[2] = new elf();
  114. tablicaElfow[3] = new superElf(6, 3);
  115. tablicaElfow[4] = new goblin(5, 3);
  116. obliczProdukcje(tablicaElfow);
  117. cout << "Oj, jeden z elfów zmutował..." << endl;
  118. goblin Gobus(1,1);
  119. Gobus = Gobus+Lesnik;
  120. tablicaElfow[0] = (elfiaZygota*)&Gobus;
  121. obliczProdukcje(tablicaElfow);
  122. for (int i=1; i<ELFY; i++)
  123. {
  124. delete tablicaElfow[i];
  125. }
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement