Modify the program no. 1 as follows:
Derive a class named as CYLINDER from CIRCLE class. Take necessary
data & member functions for this class to calculate the volume of the
cylinder. Show the result by accessing the area method of circle and
rectangle through object of rectangle class and the area of circle and volume
method of cylinder class through the objects of cylinder class.
#include<iostream>
#include<cmath>
using namespace std;
class CIRCLE{
private:
double rad;
public:
CIRCLE(){
}
CIRCLE(double r){
rad = r;
}
void setData(double r){
rad = r;
}
double area(){
return 3.142 * pow(rad, 2);
}
};
class CYLINDER: CIRCLE{
private:
double height;
public:
CYLINDER(double rad, double h){
setData(rad);
height = h;
}
void volume(){
cout<<"Volume is: "<<area() * height<<endl;
}
};
int main(){
CYLINDER cy(7, 10);
cy.volume();
}
Comments
Leave a comment