Question: Inheritance and Polymorphism Assignment Referring to the packet immediately above( Inheritance and Polymorphism), Expand the program given on pg. 714 in the class to include

Inheritance and Polymorphism Assignment

Inheritance and Polymorphism Assignment Referring to the packet immediately above( Inheritance and

Referring to the packet immediately above( Inheritance and Polymorphism), Expand the program given on pg. 714 in the class to include a child class called sphere for which the original parent calcvaluI() function will be used to determine the surface area of a sphere and the volume of a sphere. give the child class sphere public access to the parent class circle.

Include a constructor function for sphere:

Sphere(double r =1.0): Circle (r){}

or written as:

Sphere( double r=1.0)

{Circle(r);

}

You will need a calculate surface area function,ex: calcSA(), to calculate the surface area of a sphere with a specified radius and a calculate volume function, ex: calcVol() to calculate the volume of the sphere with a certain radius. Use the circle constructor function Circle(r) to set the value of the radius. Use the calcval() function as part of the formula for calculating surface area and volume. Return the values of the surface area and the volume from the functions in which they were determined to the main function in a cout statement.

The return types for those functions - calcSA() and calcVol() - should be double.

In the main program, instantiate(create) an object of data type sphere, assign a radius at time of creation (constructor for circle will be used implicitly), then afterwards, use the object to call the functions for calculating the surface area and volume. Be sure to make the function calls in the main in a cout statement so the returned values have somewhere to go ( to the screen).

Program 12.8 include #include using namespace std; const double PI 2.0 asin( 1.0); * // declaration section class circle protected: double radius public: circle (double:# 1.0); // constructor double calcval); // implementation section for Circle Circle:scircle (double r) 1I constructor radius = r; 1/ calculate the area of a Circle double circle::calcval) return (PI radius * radius); I/ declaration section where cylinder is derived from circle class cylinder : public circle protected double lengthi// add one data member and // two member functions 1.o, double 1 1.0) public: cy1inder (double r double calcval( circle(r, iength() 0 // implementation section for cylinder double cylinder: :calcval(calculates a volume return (length circle: icalcvalote the base function o

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!