#include #include #include #include using namespace std; class Tree { public: Tree (int longitude, int latitude) :height{}, longitude{longitude}, latitude{latitude} {} virtual ~Tree() = default; virtual string get_resources () const { ostringstream oss{}; oss << "Coordinates - " << "LON. " << longitude << ", " << "LAT. " << latitude << "\n" << "Height: " << height; return oss.str(); } virtual int get_value() const = 0; virtual void grow() { ++height; } protected: int height; private: int longitude; int latitude; }; class Oak : public Tree { public: using Tree::Tree; string get_resources () const override { ostringstream oss{}; oss << "Oak tree\n" << Tree::get_resources(); return oss.str(); } int get_value() const override { return height * 5; } }; class Apple_tree : public Tree { public: Apple_tree(int longitude, int latitude) : Tree{longitude, latitude}, fruits{} {} string get_resources () const override { ostringstream oss{}; oss << "Apple tree\n" << Tree::get_resources(); return oss.str(); } int get_value() const override { return (height * 3) + fruits; } void grow() override { Tree::grow(); ++fruits; } private: int fruits; }; int main () { vector forest{}; forest.push_back( new Oak{3,4} ); forest.push_back( new Apple_tree{5,7} ); for (int i{}; i < 5; ++i) { for (Tree* tree : forest) { tree -> grow(); } } for (Tree* tree : forest) { cout << tree -> get_resources() << "\nWorth: " << tree -> get_value() << "\n" << endl; } for (Tree* tree : forest) { delete tree; } }