用c++编写程序:求圆形circle的周长和面积,请编写一个基于对象的程序。数据成员包括R(半径)
1个回答
展开全部
#include <iostream.h>
#define PI 3.141593
class Circle
{
public:
Circle():m_radius(1)
{
}
~Circle()
{
}
void SetRadius(double radius)
{
if(radius<1e-6) radius=1e-6;
m_radius=radius;
}
double GetRadius()
{
return m_radius;
}
double Perimeter()
{
return 2*PI*m_radius;
}
double Area()
{
return PI*m_radius*m_radius;
}
private:
double m_radius;
};
int main()
{
Circle c;
double r;
cout<<"Please input R:"<<endl;
cin>>r;
c.SetRadius(r);
cout<饥慎<"It's perimeter is "<<c.Perimeter()<<endl;
cout<<搜肢碰"It's perimeter is "<世谈<c.Area()<<endl;
return 0;
}
#define PI 3.141593
class Circle
{
public:
Circle():m_radius(1)
{
}
~Circle()
{
}
void SetRadius(double radius)
{
if(radius<1e-6) radius=1e-6;
m_radius=radius;
}
double GetRadius()
{
return m_radius;
}
double Perimeter()
{
return 2*PI*m_radius;
}
double Area()
{
return PI*m_radius*m_radius;
}
private:
double m_radius;
};
int main()
{
Circle c;
double r;
cout<<"Please input R:"<<endl;
cin>>r;
c.SetRadius(r);
cout<饥慎<"It's perimeter is "<<c.Perimeter()<<endl;
cout<<搜肢碰"It's perimeter is "<世谈<c.Area()<<endl;
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询