#include<iostream>
#define PI 3.14
using std::cin;
using std::cout;
using std::endl;
class Circle{
private:
double radius;
public:
Circle();
Circle(double radius);
void setRadius(double radius);
double Getradius();
double Area();
};
Circle::Circle()
{
radius=1;
}
Circle::Circle(double radius)
{
this->radius=radius;
}
void Circle::setRadius(double radius)
{
this->radius=(radius>0)?radius:0;
}
double Circle::Getradius()
{
return radius;
}
double Circle::Area()
{
return PI*radius*radius;
}
double sum(Circle circleArray[],int size)
{
double sum=0;
for(int i=0;i<size;i++)
sum+=circleArray[i].Area();
return sum;
}
int main()
{
int size;
Circle *circleArray,a;
double *radius;
cout << "请输入圆的个数:"<<endl;
cin >> size;
circleArray=new Circle[size];
radius=new double[size];
for(int i=0;i<size;i++)
{
cout << "请输入第"<<i+1<<"个圆的半径:"<<endl;
cin >> radius[i];
circleArray[i].setRadius(radius[i]);
}
cout << "这些圆的面积之和为:" << sum(circleArray,size) <<endl;
return 0;
}
网友评论