使用C++完成圆类小程序

题目描述:
要求编写一个类,来代表二维坐标系上的圆
要求实现函数:
1.打印圆心坐标
2.求圆的面积
3.求圆的周长
4.判断两圆是否相切(包括内切和外切)

输入格式:
第一行输入三个整数 x,y,r,代表圆心的坐标(x,y),半径r
第二行输入一个正整数case,代表测试数据的组数
对于每一组case,第一行输入一个数,代表要调用哪个函数,1 2 3 4对应题干函数
对于函数1,无后续输入
对于函数2,无后续输入
对于函数3,无后续输入
对于函数4,输入两个整数 p ,q , r1, ( p , q)代表第二个圆圆心坐标,r1代表第二个圆的半径

输出格式:
对于函数1,打印圆心坐标,用空格隔开
对于函数2,打印圆的面积,误差不超过10^-5
对于函数3,打印圆的周长,误差不超过10^-5
对于函数4,若点在两圆相切输出“Yes”,否则输出“No”

输入样例:
0 0 1
4
1
2
3
4
2 0 1

输出样例:
0 0
3.14159265
6.2831853
Yes

有用请采纳

#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;
        }
    }
}