#include <iostream.h>
#include<math.h>
#define PI 3.14159
class column
{
public:
column(double x,double y,double r,double h);
~column();
//增加友员函数读入输数据
friend void input(column &t);
//增加友元函数输出数据
friend void output(column &t);
double area();
double volume();
private:
double height;
double radius;
double x;
double y;
};
column ::column(double x,double y,double r,double h)
{
x=x;
y=y;
radius=r;
height=h;
}
column ::~column()
{cout<<"\n\n已执行该对象的析构函数."<<endl;
}
double column::area()
{
return (2*PI*pow(radius,2)+2*PI*radius*height);
}
double column::volume()
{
return height*PI*pow(radius,2);
}
//友元函数的定义不用类域::作用符,且可以写在任意位置,和普通函数的定义一样
void input(column &t)
{
cout<<"输入圆柱高、底圆半径、圆心横坐标、纵坐标:\n";
cin>>t.height>>t.radius>>t.x>>t.y;
}
void output(column &t)
{
cout<<"\n下面是圆柱的基本参数信息:\n\n高度 半径 圆心坐标 ∏的取值\n\n";
cout<<t.height<<" "<<t.radius<<" "<<"("<<t.x<<","<<t.y<<")"<<" "<<PI<<endl;
cout<<"圆柱面积:\n"<<t.area()<<endl;
cout<<"圆柱体积:\n"<<t.volume()<<endl;
}
int main()
{
//double a,b,c,d;
//cin>>a>>b>>c>>d;
//column s(a,b,c,d);//因为构造函数有形参,所以这里得传入实参
column s(1,1,1,1);//因为构造函数有形参,所以这里得传入实参
input(s);
output(s);
return 0;
}