C++有一园环,小园R=35,大圆R=8,属于CIRCLE类,含有私有成员X,

来源:百度知道 编辑:UC知道 时间:2024/06/04 01:43:49
求两园的面积,主函数通过定义2个对象来计算圆环面积

#include<iostream.h>
class Circle
{
private:
float x;
public:
void getx(float x)
{
this->x=x;

}
double area()
{
return 3.14*x*x;
}

};
void main()
{
Circle b;
Circle x;
b.getx(3.5);
x.getx(8);
cout<<"大圆面积为";
cout<<x.area()<<endl;
cout<<"小圆面积为";
cout<<b.area()<<endl;
cout<<"环的面积为";
cout<<x.area()-b.area()<<endl;

}

大哥我给你写了半天,你就5分啊。我还给你运行了一下。是可以用的。
你试试吧,就是分给的太少了。你要是认为写的不错就加点分吧

class CIRCLE{
private:
float X;
public:
CIRCLE(float r){
X=r;
}
float Area(){
return 3.14*X*X;}
}
void main(){
CIRCLE smallround(35);
CIRCLE biground(8);
cout<<"小圆的面积是:"<<smallround.Area()<<endl;
cout<<"大圆的面积是:"<&