设计程序计算圆的面积(要求:定义一个circle类,包含数据成员int radius)
1个回答
展开全部
#include<iostream.h>
const float PI=(float)3.14159;
class Circle
{
public:
Circle(float r);
float Area();
private:
float radius;
};
Circle::Circle(float r){radius=r;}
float Circle::Area()
{
return PI*radius*radius;
}
void main()
{
float radius;
float FenceCost;
cout<<"请输入半径"<<endl;
cin>>radius;
Circle pool(radius);
FenceCost=pool.Area();
cout<<"圆的面积为:"<<FenceCost<<endl;
}
打得好辛苦,多加点分吧
const float PI=(float)3.14159;
class Circle
{
public:
Circle(float r);
float Area();
private:
float radius;
};
Circle::Circle(float r){radius=r;}
float Circle::Area()
{
return PI*radius*radius;
}
void main()
{
float radius;
float FenceCost;
cout<<"请输入半径"<<endl;
cin>>radius;
Circle pool(radius);
FenceCost=pool.Area();
cout<<"圆的面积为:"<<FenceCost<<endl;
}
打得好辛苦,多加点分吧
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询