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;
- string name;
- public:
- Copac() {
- height = 0;
- growingRate = 1;
- leafType = 0;
- }
- virtual void grow() {
- height += growingRate;
- }
- virtual void afisare() {
- cout << "[" << name << "] ";
- cout << "Inaltime: " << height;
- cout << " Frunza: " << leafType;
- }
- };
- class Brad : public Copac {
- // ace nu cad
- public:
- Brad() {
- height = 0;
- growingRate = 2;
- leafType = 1;
- name = "Brad";
- }
- void afisare() {
- cout << "[" << name << "] ";
- cout << "Inaltime: " << height;
- cout << " Frunza: " << leafType;
- }
- };
- class Stejar: public Copac {
- // marime frunze si culoare
- private:
- static int anotimpuri;
- int leafSize;
- int leafColor;
- public:
- Stejar() {
- height = 0;
- growingRate = 3;
- leafType = 2;
- leafSize = 0;
- leafColor = 0;
- name = "Stejar";
- }
- void grow() {
- anotimpuri++;
- height += growingRate;
- }
- void afisare() {
- cout << "[" << name << "] ";
- cout << "Inaltime: " << height;
- cout << " Frunza: " << leafType;
- cout << " Marime frunza: " << leafSize;
- cout << " Culoare frunza: " << leafColor;
- }
- };
- class Platan : public Copac {
- // marime frunze si culoare
- private:
- static int anotimpuri;
- int leafSize;
- int leafColor;
- public:
- Platan() {
- height = 0;
- growingRate = 4;
- leafType = 2;
- name = "Platan";
- }
- void grow() {
- anotimpuri++;
- height += growingRate;
- }
- void afisare() {
- cout << "[" << name << "] ";
- cout << "Inaltime: " << height;
- cout << " Frunza: " << leafType;
- cout << " Marime frunza: " << leafSize;
- cout << " Culoare frunza: " << leafColor;
- }
- };
- class Tisa : public Copac {
- // ace nu cad
- public:
- Tisa() {
- height = 0;
- growingRate = 2;
- leafType = 1;
- name = "Tisa";
- }
- 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();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement