代码。
#include<cstdio>
#include<cmath>
#include<iostream>
using namespace std;
class circum{ //创建圆类。
public:
void send_m_r(int r){ //输入圆的半径。
if (r > 0){
m_r = r;
}
else{ //当输入数据不合法时设为默认值并提醒。
cout << "gui" << endl;
m_r = 1;
}
}
void send_mid (int m, int n){ //输入圆心位置。
x = m;
y = n;
}
int judge (int m, int n){ //判断圆点关系函数。
l = sqrt(pow(x - m, 2) + pow(y - n, 2)); //计算圆心与点的距离。
if (l < m_r) return 0;
else if (l == m_r) return 1;
else return 2;
//以上为三种情况。
}
private:
int m_r;
int x;
int y;
int l;
};
int main (){
int r, x1, y1, x2, y2, p1;
circum c;
cout << "请输入该圆的半径:" << endl;
cin >> r;
c.send_m_r(r);
cout << "请输入该圆圆心的位置:(输入x坐标与y坐标)" << endl;
cin >> x1 >> y1;
c.send_mid(x1, y1);
cout << "请输入该点坐标:" << endl;
cin >> x2 >> y2;
p1 = c.judge(x2, y2);
if (p1 == 0) cout << "该点在圆内。"; //当距离小于半径时就在圆内。
else if (p1 == 1) cout << "该点在圆上。"; //当距离刚好等于半径是就在圆上。
else cout << "该点在圆外。"; //当距离大于半径时就在圆外。
return 0;
}