Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. class Copac {
  7. protected:
  8. int height;
  9. int growingRate;
  10. int leafType;
  11. string name;
  12. public:
  13. Copac() {
  14. height = 0;
  15. growingRate = 1;
  16. leafType = 0;
  17. }
  18.  
  19. virtual void grow() {
  20. height += growingRate;
  21. }
  22.  
  23. virtual void afisare() {
  24. cout << "[" << name << "] ";
  25. cout << "Inaltime: " << height;
  26. cout << " Frunza: " << leafType;
  27. }
  28. };
  29.  
  30. class Brad : public Copac {
  31. // ace nu cad
  32. public:
  33. Brad() {
  34. height = 0;
  35. growingRate = 2;
  36. leafType = 1;
  37. name = "Brad";
  38. }
  39.  
  40. void afisare() {
  41. cout << "[" << name << "] ";
  42. cout << "Inaltime: " << height;
  43. cout << " Frunza: " << leafType;
  44. }
  45. };
  46.  
  47. class Stejar: public Copac {
  48. // marime frunze si culoare
  49. private:
  50. static int anotimpuri;
  51. int leafSize;
  52. int leafColor;
  53. public:
  54. Stejar() {
  55. height = 0;
  56. growingRate = 3;
  57. leafType = 2;
  58. leafSize = 0;
  59. leafColor = 0;
  60. name = "Stejar";
  61. }
  62.  
  63. void grow() {
  64. anotimpuri++;
  65. height += growingRate;
  66. }
  67.  
  68. void afisare() {
  69. cout << "[" << name << "] ";
  70. cout << "Inaltime: " << height;
  71. cout << " Frunza: " << leafType;
  72. cout << " Marime frunza: " << leafSize;
  73. cout << " Culoare frunza: " << leafColor;
  74. }
  75. };
  76.  
  77. class Platan : public Copac {
  78. // marime frunze si culoare
  79. private:
  80. static int anotimpuri;
  81. int leafSize;
  82. int leafColor;
  83. public:
  84. Platan() {
  85. height = 0;
  86. growingRate = 4;
  87. leafType = 2;
  88. name = "Platan";
  89. }
  90.  
  91. void grow() {
  92. anotimpuri++;
  93. height += growingRate;
  94. }
  95.  
  96. void afisare() {
  97. cout << "[" << name << "] ";
  98. cout << "Inaltime: " << height;
  99. cout << " Frunza: " << leafType;
  100. cout << " Marime frunza: " << leafSize;
  101. cout << " Culoare frunza: " << leafColor;
  102. }
  103. };
  104.  
  105. class Tisa : public Copac {
  106. // ace nu cad
  107. public:
  108. Tisa() {
  109. height = 0;
  110. growingRate = 2;
  111. leafType = 1;
  112. name = "Tisa";
  113. }
  114.  
  115. void afisare() {
  116. cout << "[" << name << "] ";
  117. cout << "Inaltime: " << height;
  118. cout << " Frunza: " << leafType;
  119. }
  120. };
  121.  
  122. int main() {
  123. Copac** copaci = new Copac * [4];
  124.  
  125. copaci[0] = new Brad;
  126. copaci[1] = new Stejar;
  127. copaci[2] = new Platan;
  128. copaci[3] = new Tisa;
  129.  
  130. int n;
  131. cout << "Numarul de iteratii: ";
  132. cin >> n;
  133.  
  134. // cresc copacii
  135. for (int i = 0; i < n; i++) {
  136. for (int j = 0; j < 4; j++) {
  137. copaci[j]->grow();
  138. }
  139. }
  140.  
  141. // afisare copaci
  142. for (int i = 0; i < 4; i++) {
  143. copaci[i]->afisare();
  144. }
  145.  
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement