Advertisement
koyukix

t1

Jan 11th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. #include <iostream>
  2. #define ELFY 5
  3.  
  4. using namespace std;
  5.  
  6. class elf {
  7.  
  8. protected:
  9. int prod, zycie;
  10.  
  11. public:
  12. elf()
  13. {
  14. cout<<"Tu elf 1"<<endl;
  15. prod = 5;
  16. zycie = 5;
  17. liczbaElfow++;
  18. }
  19.  
  20. elf(int a, int b)
  21. {
  22. cout<<"Tu elf 2"<<endl;
  23. prod = a;
  24. zycie = b;
  25. liczbaElfow++;
  26. }
  27.  
  28. virtual ~elf(){};
  29. virtual int zrobZabawke(int dzien)
  30. {
  31. if(dzien<zycie)
  32. {
  33. return prod;
  34. } else {return 0;}
  35. }
  36. static int liczbaElfow;
  37. };
  38.  
  39.  
  40. class superElf : public elf {
  41.  
  42. protected:
  43. int sila;
  44.  
  45. public:
  46. superElf(int a, int b, int c)
  47. {
  48. cout<<"Tu superElf"<<endl;
  49. prod = a;
  50. sila = b;
  51. zycie = c;
  52. liczbaSuperElfow++;
  53. }
  54. virtual int zrobZabawke(int dzien)
  55. {
  56. if(dzien<zycie)
  57. {
  58. return sila*prod;
  59. } else {return 0;}
  60. }
  61. static int liczbaSuperElfow;
  62. };
  63.  
  64. int elf::liczbaElfow=0;
  65. int superElf::liczbaSuperElfow=0;
  66.  
  67. string czyElfySieWyrobia(elf* tablicaElfow[ELFY], int d, const int z) {
  68.  
  69. int praca=0;
  70. for(int i=0; i<ELFY;i++)
  71. {
  72. praca += tablicaElfow[i]->zrobZabawke(d);
  73. }
  74. if(praca>=z)
  75. {
  76. return "tak";
  77. }else {return "nie";}
  78. }
  79.  
  80. int main () {
  81. elf* tablicaElfow[ELFY];
  82. tablicaElfow[0] = new elf();
  83. tablicaElfow[1] = new elf(2,10);
  84. tablicaElfow[2] = new elf(3,6);
  85. tablicaElfow[3] = new superElf(4, 2, 5);
  86. tablicaElfow[4] = new superElf(2, 15, 1);
  87. cout << "Elfow jest: " << elf::liczbaElfow << endl;
  88. cout << "W tym super elfow jest: " << superElf::liczbaSuperElfow << endl;
  89. const int dni = 7;
  90. int tablicaZadan[dni] = {18, 33, 13, 12, 5, 2, 20};
  91. for (int i=0; i<dni; i++) {
  92. cout << "Dzien " << i << ". Czy elfy dadza rade: " << czyElfySieWyrobia(tablicaElfow, i,tablicaZadan[i]) << endl;
  93. }
  94. for (int i=0; i<ELFY; i++) {
  95. delete tablicaElfow[i];
  96. }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement