C++判断圆点关系代码

代码。

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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值