自考新教材-p90_5(4)
源程序:
#include <iostream>
#define PI 3.1415926
using namespace std;
class Cylinder
{
private:
double r, h;
public:
Cylinder(double rr, double hh)
{
r = rr;
h = hh;
}
double circle_length()
{
return 2 * PI*r;
}
double circle_area()
{
return PI*r*r;
}
double Cylin_tiji();
};
double Cylinder::Cylin_tiji()
{
return circle_area()*h;
}
int main()
{
double radius, height;
cout << "请输入圆柱的底面半径和高:";
cin >> radius >> height;
Cylinder C(radius, height);
cout << "圆柱体的底面周长为:" << C.circle_length() << endl;
cout << "圆柱体的底面积为:" << C.circle_area() << endl;
cout << "圆柱体的体积为:" << C.Cylin_tiji() << endl;
system("pause");
return 1;
}
运行结果: