Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.19 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. int threshold;
  12. string name;
  13. public:
  14. Copac() {
  15. height = 0;
  16. growingRate = 1;
  17. leafType = 0;
  18. threshold = 25;
  19. }
  20.  
  21. virtual void grow() {
  22. height += growingRate;
  23. }
  24.  
  25. virtual void afisare() {
  26. cout << "[" << name << "] ";
  27. cout << "Inaltime: " << height;
  28. cout << " Frunza: " << leafType;
  29. }
  30. };
  31.  
  32. class Brad : public Copac {
  33. // ace nu cad
  34. private:
  35. int anotimpuri;
  36. public:
  37. Brad() {
  38. height = 0;
  39. growingRate = 2;
  40. leafType = 1;
  41. anotimpuri = 0;
  42. name = "Brad";
  43. }
  44.  
  45. virtual void grow() {
  46. height += growingRate;
  47. }
  48.  
  49. void afisare() {
  50. cout << "[" << name << "] ";
  51. cout << "Inaltime: " << height;
  52. cout << " Frunza: " << leafType;
  53. }
  54. };
  55.  
  56. class Stejar: public Copac {
  57. // marime frunze si culoare
  58. private:
  59. int leafSize;
  60. int leafColor;
  61. int anotimpuri;
  62. int leafGrowingRate;
  63. public:
  64. Stejar() {
  65. height = 0;
  66. growingRate = 3;
  67. leafType = 2;
  68. leafSize = 0;
  69. leafColor = 0;
  70. name = "Stejar";
  71. threshold = 70;
  72. anotimpuri = 0;
  73. leafGrowingRate = 2;
  74. }
  75.  
  76. void grow() {
  77. height += growingRate;
  78.  
  79. if (height % threshold == 0) {
  80. leafSize = 0;
  81. }
  82. else {
  83. leafSize += leafGrowingRate;
  84. }
  85.  
  86. if (anotimpuri % 4 == 0)
  87. leafColor = 2;
  88. else if (anotimpuri % 2 == 0)
  89. leafColor = 1;
  90. }
  91.  
  92. void afisare() {
  93. cout << "[" << name << "] ";
  94. cout << "Inaltime: " << height;
  95. cout << " Frunza: " << leafType;
  96. cout << " Marime frunza: " << leafSize;
  97. if(leafSize)
  98. cout << " Culoare frunza: " << leafColor;
  99. }
  100. };
  101.  
  102. class Platan : public Copac {
  103. // marime frunze si culoare
  104. private:
  105. int leafSize;
  106. int leafColor;
  107. int anotimpuri;
  108. int leafGrowingRate;
  109. public:
  110. Platan() {
  111. height = 0;
  112. growingRate = 4;
  113. leafType = 3;
  114. leafSize = 0;
  115. leafColor = 0;
  116. anotimpuri = 0;
  117. name = "Platan";
  118. leafGrowingRate = 3;
  119. }
  120.  
  121. void grow() {
  122. height += growingRate;
  123.  
  124. if (height % threshold == 0) {
  125. leafSize = 0;
  126. }
  127. else {
  128. leafSize += leafGrowingRate;
  129. }
  130.  
  131. if (anotimpuri % 4 == 0)
  132. leafColor = 2;
  133. else if (anotimpuri % 2 == 0)
  134. leafColor = 1;
  135. }
  136.  
  137. void afisare() {
  138. cout << "[" << name << "] ";
  139. cout << "Inaltime: " << height;
  140. cout << " Frunza: " << leafType;
  141. cout << " Marime frunza: " << leafSize;
  142. if (leafSize)
  143. cout << " Culoare frunza: " << leafColor;
  144. }
  145. };
  146.  
  147. class Tisa : public Copac {
  148. // ace nu cad
  149. private:
  150. int anotimpuri;
  151. public:
  152. Tisa() {
  153. height = 0;
  154. growingRate = 5;
  155. leafType = 1;
  156. name = "Tisa";
  157. threshold = 150;
  158. anotimpuri = 0;
  159. }
  160.  
  161. void afisare() {
  162. cout << "[" << name << "] ";
  163. cout << "Inaltime: " << height;
  164. cout << " Frunza: " << leafType;
  165. }
  166. };
  167.  
  168. int main() {
  169. Copac** copaci = new Copac * [4];
  170.  
  171. copaci[0] = new Brad;
  172. copaci[1] = new Stejar;
  173. copaci[2] = new Platan;
  174. copaci[3] = new Tisa;
  175.  
  176. int n;
  177. cout << "Numarul de iteratii: ";
  178. cin >> n;
  179.  
  180. // cresc copacii
  181. for (int i = 0; i < n; i++) {
  182. for (int j = 0; j < 4; j++) {
  183. copaci[j]->grow();
  184. }
  185. }
  186.  
  187. // afisare copaci
  188. for (int i = 0; i < 4; i++) {
  189. copaci[i]->afisare();
  190. cout << endl;
  191. }
  192.  
  193. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement