Create a header file and write a C++ class for objects ofcylinders.
The class should include two data members:
double radius;
double height;
and
default and non-default constructors
and
set and get member functions
and
a display function
Answer
class cylinder{
private:
double radius;
double height;
public:
cylinder();
cylinder(double,double);
void setRadius(double);
void setHeight(double);
double getRadius();
double getHeight();
void display();
};
cylinder::cylinder(){
radius=0;
height=0;
}
cylinder::cylinder(double r,doubleh){
radius=r;
height=h;
}
void cylinder:: setRadius(double r){
radius=r;
}
void cylinder::setHeight(doubleh){
height=h;
}
double cylinder::getRadius(){
return radius;
}
double cylinder::getHeight(){
return height;
}