定义一个圆类(Circle),属性为半径(radius)和圆周长、面积,操作为输入半径并计算周长、面积,输出半径、周长和面积。要求定义构造函数(以半径为参数,缺省值为0,周长和面积在构造函数中生成)和复制构造函数
#include<iostream>
using namespace std;
class Circle
{
private:
int r;
double c;
double s;
public:
Circle(int a=0,double c=0,double s=0);//定义构造函数,缺省项为零;
Circle(Circle&c);//复制构造函数;
void computec();
void computes();
double outputc();
double outputs();
int output();
};
Circle::Circle(Circle&c)
{
r=c.r;
}
Circle::Circle(int a,double b,double c)
{
r=a;
c=b;
s=c;
}
double Circle::outputc()
{
return 3.14*r*2;
}
double Circle::outputs()
{
return 3.14*r*r;
}
void Circle::computec()
{
c=3.14*r*2;
}
void Circle::computes()
{
s=3.14*r*r;
}
int Circle::output()
{
return r;
}
int main()
{
Circle t1(10);
Circle t2(20);
t1.computec();
t1.computes();
cout<<"圆的半径是:"<<t1.output()<<endl;
cout<<"圆的周长是:"<<t1.outputc()<<endl;
cout<<"圆的面积是:"<<t1.outputs()<<endl;
cout<<"圆的半径是:"<<t2.output()<<endl;
cout<<"圆的周长是:"<<t2.outputc()<<endl;
cout<<"圆的面积是:"<<t2.outputs()<<endl;
return 0;
}