#pragma once//header file #include <iostream> #include <string>using namespace std;//// 1. Implement the member functions of the following classes// 2. Implements the override of a virtual function and calls// 3. Handles diamond inheritance issues. Plant Class botany{public:botany (const string& name); Virtual ~botany (); Virtual void display (); Botany (const botany& b);p rotected:string _name;//name static size_t _scount;}; class tree : public botany{public://... Implement the default member function tree (const string& name, const int hight);virtual void Display (); Virtual ~tree (); Tree (const tree& t);p rotected:int _hight;// height};class flower : public botany{public://... Implement the default member function flower (const string&, const string& color);virtual void Display (); Virtual ~flower (); Flower (const flower& f);p rotected:string _colour;// color};// white orchid, that is, the tree is sometimes spent. Class miCheliaalba : public flower, public tree{public:micheliaalba (const string& name, const string& color, const int hight);virtual void Display (); Virtual ~micheliaalba (); Micheliaalba (const micheliaalba& m);p rotected:// ...}; #include <iostream>//function file #include<string> #include "plant.h" using namespace std;size_ T botany::_scount = 0;void botany::D isplay () {cout<< "botany: " << _ Name << endl;cout << _scount << endl;} Botany::botany (const string& name): _name (name) {++_scount;cout << "Botany" << endl;} Tree::tree (const string& name, const int hight): Botany (name), _ Hight (hight) {cout << "Tree" &NBSP;<<&NBSP;ENDL;} Flower::flower (Const string& name,&nbsP;const string& color): Botany (name), _colour (color) {cout << "Flower" << endl;} Micheliaalba::micheliaalba (const string& name, const string& Color, const int hight): Flower (Name,color), tree (name,hight) {cout << " Micheliaalba "&NBSP;<<&NBSP;ENDL;} Void tree::D isplay () {cout << "Tree:" << _name << endl; Cout << _scount << endl;} Void flower::D isplay () {cout << "flower " << _name << endl;cout << _scount << endl;} Void micheliaalba::D isplay () {cout << "micheliaalba " << flower:: _name << " " <<Flower::_colour<< " " <<Tree::_hight< < endl;cout << _scount << endl;} botany::~botany () { cout << "~botany" &NBSP;<<&NBSP;ENDL;} tree:: ~tree () { cout << "~tree" << endl; } Flower:: ~flower () { cout << "~flower" << endl; } Micheliaalba::~micheliaalba () { cout << "~micheliaalba" << endl; } botany::botany (const botany& b) :_name (b._name) { } Tree::Tree ( const tree& t) : botany (t._name) , _hight (t._hight) { } Flower::flower (const flower& f) : botany (f._name) , _colour (f._colour) { } micheliaalba::micheliaalba (const micheliaalba& m) : tree (m.Tree::_name,m . _hight) , flower (m.flower::_name,m._colour) { } #include <iostream> Main function test file #include<string>#include "plant.h" Using namespace std;void test () {micheliaalba m ("White orchid", "Red", "M"); Display (); MICHELIAALBA&NBSP;M2 (m); m2. Display (); M.display ();} Int main () {test (); return 0;}
C + + Plant inheriting polymorphic diamond inheritance