2种差不多的方法,自己在VC6.0上面试试
#include<iostream>
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<<endl
<<"请输入半径:";
cin>>radius;
}
int main()
{
circle CIR;
CIR.cinradius();
cout<<"半径:"
<<CIR.coutradius();
cout<<endl
<<"圆的周长为"
<<CIR.circumference()
<<endl
<<"圆的面积为"
<<CIR.area();
return 0;
}
或者
#include<iostream.h>
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<<"请输入圆半径:"<<endl;
yuan.registCircle(rr);
cout<<"圆的半径为:"<<yuan.outr();
cout<<"圆的周长为:"<<yuan.outc();
cout<<"圆的面积为:"<<yuan.outs();
温馨提示:答案为网友推荐,仅供参考