有用请采纳
#include<iostream>
#include<cmath> // 使用sqrt
#define PI 3.14159265358
using namespace std;
class Circle{
private:
double x, y, r;
public:
Circle(double x, double y, double r);
void printCenter();
void printArea();
void printPerimeter();
void judgeTangent(double otherX, double otherY, double otherR);
};
Circle::Circle(double x, double y, double r){
this->x = x;
this->y = y;
this->r = r;
}
void Circle::printCenter(){
cout << this->x << " " << this->y << endl;
}
void Circle::printArea(){
double area;
area = PI * this->r * this->r;
printf("%.8lf\n", area);
}
void Circle::printPerimeter(){
double perimeter;
perimeter = 2 * PI * this->r;
printf("%.8lf\n", perimeter);
}
void Circle::judgeTangent(double otherX, double otherY, double otherR){
double distance; // 圆心之间的距离
distance = sqrt((otherX - this->x) * (otherX - this->x) + (otherY - this->y) * (otherY - this->y));
double addR = otherR + this->r; // 判断外切
double subR = fabs(otherR - this->r); // 判断内切
double judgeRange = 0.00001;
if(fabs(distance - addR) < judgeRange || fabs(distance - subR) < judgeRange)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
int main(){
double x, y, r;
int choose, num;
cin >> x >> y >> r;
Circle circle = Circle(x, y, r);
double otherX, otherY, otherR;
cin >> choose;
for (int i = 0; i < choose; i++){
cin >> num;
switch(num){
case 1:
circle.printCenter();
break;
case 2:
circle.printArea();
break;
case 3:
circle.printPerimeter();
break;
case 4:
cin >> otherX >> otherY >> otherR;
circle.judgeTangent(otherX, otherY, otherR);
break;
default:
break;
}
}
}