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: 3649765 • 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

Explanation / Answer

////////////////////////////////////////////////////////////////////
// circle.h
////////////////////////////////////////////////////////////////////
#ifndef CIRCLE_H
#define CIRCLE_H //only define circle.h if not already defined

#include //cout
using namespace std;

const double PI=3.14;//PI is a constant variable


class circle
{
protected:
double radius;//only member of class circle
public:
circle(){// 0-argument Constructor
radius=1.0;
}
circle(double r){
radius=r;
}
double calcVal(){//area of a circle
return (PI * radius * radius);
}
/* usual fxn for accessing/chaging private/protected members (not needed for your assignment)
void setRadius(double r){
radius=r;
}
double getRadius(){
return radius;}
*/
};//end of class circle

#endif

////////////////////////////////////////////////////////////////////
// rectangle.h
////////////////////////////////////////////////////////////////////
#ifndef RECTANGLE_H
#define RECTANGLE_H
#include
#include "circle.h" //including class circle's headerfile

class rectangle{
protected:
double length;
circle top;
public:
rectangle(){
length=1;
top.radius=1;
}
calcVal(){//volume of the cylinder
return (length*top.calcVal());
}
};//end of rectangle class
#endif;
//youll need to write a main that includes both header files to test the class

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