







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An example of c++ inheritance using the classes sphere and ball. It includes the definition of constructors, destructors, overloaded operators, and virtual functions. The document also discusses the rule of the big three and the concept of subclass substitution.
Typology: Study notes
1 / 13
This page cannot be seen from the preview
Don't miss anything!








public protected private
class sphere { public: sphere(); sphere(double r); … double getVolume(); void setRadius(double r); … void display(); private: double theRadius; }; class ball:public sphere { public: ball(); ball(double r string n); … string getName(); void setName(string n); … void display(); private: string name; };
class sphere { public: sphere(); sphere(double r); … double getVolume(); void setRadius(double r); … void display(); private: double theRadius; }; class ball:public sphere { public: ball(); ball(double r string n); … string getName(); void setName(string n); … void display(); private: string name; };
class flower { public: flower(); virtual void drawBlossom() = 0; virtual void drawStem() = 0; virtual void drawFoliage() = 0; … }; class daisy:public flower { public: virtual void drawBlossom(); virtual void drawStem(); virtual void drawFoliage(); … private: int blossom; // number of petals int stem; // length of stem int foliage // leaves per inch };