Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Derive the cylinder class from the base circle class. Assume the circle class ha

ID: 3649775 • Letter: D

Question

Derive the cylinder class from the base circle class. Assume the circle class has a protected member variable representing the radius called radius and declared as a double with a default value of 1.0. It also has a public function called calcVal that evaluates the area of a circle as PI * radius * radius where PI is a constant 3.14.

In your derived class include an additional protected member representing the length of the cylinder. Call this variable length. Have the default values for the cylinder class be 1 for both the radius and the length. For this derived cylinder class include a public function calcVal that evaluates the volume of the cylinder. (Hint: The volume of the cylinder is length * circle :: calcVal)

Here is the code that I have so far:

#include <iostream>


using namespace std;

class circle
{
protected:
double radius, area, volume, length;
double PI;
double calcVal()
{
PI = 3.14;
area = PI*radius*radius;
return area;
}

circle(double n = 1)
{
radius = n;
}
}; // end of class square

class cylinder:public circle
{
public:
double calcVal()
{
volume = (length*circle::calcVal());
return volume;
}
cylinder(double N = 1) : circle( N )
{
}
}; // end of class cube

int main()
{
cylinder obj(1);
cout << obj.calcVal() << endl;
system("pause");
return 0;
}

Explanation / Answer

#include using namespace std; class circle { protected: double radius, area, volume, length; double PI; double calcVal() { PI = 3.14; area = PI*radius*radius; return area; } circle(double n = 1) { radius = n; } }; // end of class square class cylinder:public circle { public: double calcVal() { volume = (length*circle::calcVal()); return volume; } cylinder(double N = 1) : circle( N ) { } }; // end of class cube int main() { cylinder obj(1); cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote