C++编程:定义一个圆类要求属性为半径,操作为计算圆的周长和面积。
若以下回答无法解决问题,邀请你更新回答
展开全部
2种差不多的方法,自己在vc6.0上面试试
#include
using
namespace
std;
#define
pi
3.14
class
circle
{
public:
circle(double
r=0.0){}
circle(circle
&c){}
double
circumference();
double
area();
void
cinradius();
double
coutradius(){return
radius;}
private:
double
radius;
};
double
circle::circumference()
{
return
2*pi*radius;
}
double
circle::area()
{
return
pi*radius*radius;
}
void
circle::cinradius()
{
cout<
>radius;
}
int
main()
{
circle
cir;
cir.cinradius();
cout<<"半径:"
<
class
circle{
private:
float
r;//半径
const
float
pi;//pi
public:
void
circle::registcircle(float);
float
outr(void);
float
outc(void);
float
outs(void);
};
void
circle::registcircle(float
r)
{
r=r;
pi=3.1415926;
}
float
circle::outr(void)
{
return(r);
}
float
circle::outc(void)
{
float
c;
c=2*pi*r;
return(c);
}
float
circle::outs(void)
{
float
s;
s=pi*r*r;
return(s);
}
void
main()
{
circle
yuan;
float
rr;
cout<<"请输入圆半径:"<
评论
0
0
加载更多
#include
using
namespace
std;
#define
pi
3.14
class
circle
{
public:
circle(double
r=0.0){}
circle(circle
&c){}
double
circumference();
double
area();
void
cinradius();
double
coutradius(){return
radius;}
private:
double
radius;
};
double
circle::circumference()
{
return
2*pi*radius;
}
double
circle::area()
{
return
pi*radius*radius;
}
void
circle::cinradius()
{
cout<
>radius;
}
int
main()
{
circle
cir;
cir.cinradius();
cout<<"半径:"
<
class
circle{
private:
float
r;//半径
const
float
pi;//pi
public:
void
circle::registcircle(float);
float
outr(void);
float
outc(void);
float
outs(void);
};
void
circle::registcircle(float
r)
{
r=r;
pi=3.1415926;
}
float
circle::outr(void)
{
return(r);
}
float
circle::outc(void)
{
float
c;
c=2*pi*r;
return(c);
}
float
circle::outs(void)
{
float
s;
s=pi*r*r;
return(s);
}
void
main()
{
circle
yuan;
float
rr;
cout<<"请输入圆半径:"<
评论
0
0
加载更多
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询