#include<iostream>
#include<iomanip>
using namespace std;
class circleType
{
public:
void setRadius(double cRadius);
double getRadius() ;
double calcArea() ;
double calcCir() ;
void print() ;
circleType ();
circleType(double cRradius);
private:
double radius;
};
void circleType::setRadius(double cRadius)
{
radius = cRadius;
}
void circleType::print()
{
cout << "The radius of the circle is: " << getRadius() << endl;
cout << "The area of the circle is: " << calcArea() << endl;
cout << "The circumference of the circle is: " << calcCir() << endl <<endl;
}
double circleType::getRadius()
{
return radius ;
}
double circleType::calcArea()
{
double pi = 3.14159;
return (pi * (radius * radius));
}
double circleType::calcCir()
{
double pi = 3.14159;
return (2 * pi * radius);
}
circleType::circleType() //Default rutor
{
radius;
}
circleType::circleType(double cRadius)
{
radius = cRadius;
}
class cylinderType: public circleType
{
public:
void setHeight(double cHeight);
void print() ;
double getHeight() ;
double calcVolume();
double calcSurface() ;
cylinderType();
cylinderType(double cHeight);
private:
double height;
};
void cylinderType::setHeight(double cHeight)
{
height = cHeight;
}
void cylinderType::print()
{
cout << "The height of the cylinder is: " << getHeight() << endl;
cout << "The radius of the cylinder base is: " << getRadius() << endl;
cout << "The volume of the cylinder is: " << calcVolume() << endl;
cout << "The surface area of the cylinder is: " << calcSurface() << endl;
}
double cylinderType::getHeight()
{
return height;
}
double cylinderType::calcVolume()
{
double pi = 3.14159;
return (height * pi) * (getRadius() * getRadius());
}
double cylinderType::calcSurface()
{
double pi = 3.14159;
return (2 * calcArea()) + (calcCir() * height);
}
cylinderType::cylinderType()
{
height ;
}
cylinderType::cylinderType(double cHeight)
{
height = cHeight;
}
int main()
{
circleType circle;
double r ;
cout << "Enter the radius of the circle: ";
cin >> r;
circle.setRadius(r);
circle.print();
cylinderType cylinder;
double h;
cout << "Enter the height of the cylinder: ";
cin >> h;
cylinder.setHeight(h);
cylinder.print();
system("pause");
return 0;
}
jimmy.teohmingsiong
0
Newbie Poster
Recommended Answers
Jump to PostIn cylinder class,
getRadius()
,calcArea()
are of circle class, and you are using them in cylinder class, you might want to write separate functions for both of these classes. If you see, you will realize that whengetRadius()
is called in Cylinder class, it has value 0.And never use …
Jump to PostYou can code setHeight() such that it takes the height and radius, from the circle part.
cylinder.setHeight(h, r)
.
All 7 Replies
np complete
8
Newbie Poster
jimmy.teohmingsiong
0
Newbie Poster
np complete
8
Newbie Poster
jimmy.teohmingsiong
0
Newbie Poster
NathanOliver
429
Veteran Poster
Featured Poster
jimmy.teohmingsiong
0
Newbie Poster
np complete
8
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.