Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- class Copac {
- protected:
- int height;
- int growingRate;
- int leafType;
- int threshold;
- string name;
- public:
- Copac() {
- height = 0;
- growingRate = 1;
- leafType = 0;
- threshold = 25;
- }
- virtual void grow() {
- height += growingRate;
- }
- virtual void afisare() {
- cout << "[" << name << "] ";
- cout << "Inaltime: " << height;
- cout << " Frunza: " << leafType;
- }
- };
- class Brad : public Copac {
- // ace nu cad
- private:
- int anotimpuri;
- public:
- Brad() {
- height = 0;
- growingRate = 2;
- leafType = 1;
- anotimpuri = 0;
- name = "Brad";
- }
- virtual void grow() {
- height += growingRate;
- }
- void afisare() {
- cout << "[" << name << "] ";
- cout << "Inaltime: " << height;
- cout << " Frunza: " << leafType;
- }
- };
- class Stejar: public Copac {
- // marime frunze si culoare
- private:
- int leafSize;
- int leafColor;
- int anotimpuri;
- int leafGrowingRate;
- public:
- Stejar() {
- height = 0;
- growingRate = 3;
- leafType = 2;
- leafSize = 0;
- leafColor = 0;
- name = "Stejar";
- threshold = 70;
- anotimpuri = 0;
- leafGrowingRate = 2;
- }
- void grow() {
- height += growingRate;
- if (height % threshold == 0) {
- leafSize = 0;
- }
- else {
- leafSize += leafGrowingRate;
- }
- if (anotimpuri % 4 == 0)
- leafColor = 2;
- else if (anotimpuri % 2 == 0)
- leafColor = 1;
- }
- void afisare() {
- cout << "[" << name << "] ";
- cout << "Inaltime: " << height;
- cout << " Frunza: " << leafType;
- cout << " Marime frunza: " << leafSize;
- if(leafSize)
- cout << " Culoare frunza: " << leafColor;
- }
- };
- class Platan : public Copac {
- // marime frunze si culoare
- private:
- int leafSize;
- int leafColor;
- int anotimpuri;
- int leafGrowingRate;
- public:
- Platan() {
- height = 0;
- growingRate = 4;
- leafType = 3;
- leafSize = 0;
- leafColor = 0;
- anotimpuri = 0;
- name = "Platan";
- leafGrowingRate = 3;
- }
- void grow() {
- height += growingRate;
- if (height % threshold == 0) {
- leafSize = 0;
- }
- else {
- leafSize += leafGrowingRate;
- }
- if (anotimpuri % 4 == 0)
- leafColor = 2;
- else if (anotimpuri % 2 == 0)
- leafColor = 1;
- }
- void afisare() {
- cout << "[" << name << "] ";
- cout << "Inaltime: " << height;
- cout << " Frunza: " << leafType;
- cout << " Marime frunza: " << leafSize;
- if (leafSize)
- cout << " Culoare frunza: " << leafColor;
- }
- };
- class Tisa : public Copac {
- // ace nu cad
- private:
- int anotimpuri;
- public:
- Tisa() {
- height = 0;
- growingRate = 5;
- leafType = 1;
- name = "Tisa";
- threshold = 150;
- anotimpuri = 0;
- }
- void afisare() {
- cout << "[" << name << "] ";
- cout << "Inaltime: " << height;
- cout << " Frunza: " << leafType;
- }
- };
- int main() {
- Copac** copaci = new Copac * [4];
- copaci[0] = new Brad;
- copaci[1] = new Stejar;
- copaci[2] = new Platan;
- copaci[3] = new Tisa;
- int n;
- cout << "Numarul de iteratii: ";
- cin >> n;
- // cresc copacii
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < 4; j++) {
- copaci[j]->grow();
- }
- }
- // afisare copaci
- for (int i = 0; i < 4; i++) {
- copaci[i]->afisare();
- cout << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement