c++小练手

判断两个圆是否相交

// panduan.cpp: 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
#include<math.h>

using namespace std;
class point {
public:
	void setxy(int x,int y)
	{
		m_x = x;
		m_y = y;
	}
	
	double point_distance(point &another)
	{
		int d_x = m_x - another.m_x;
		int d_y = m_y - another.m_y;
		double dis = sqrt(d_x*d_x + d_y * d_y);
		return dis;
	}

private:
	int m_x;
	int m_y;
};
class circle {
public:
	void setr(int r)
	{
		m_r = r;
	}
	void serxy(int x, int y)
	{
		p.setxy(x, y);

	}
	bool judge(circle &another)
	{
		int rr = m_r + another.m_r;
		double diss = p.point_distance(another.p);
		if (rr > diss)
			return true;
		else return false;

	}
private:
	int m_r;
	point p;
};
int main()
{
	circle c1, c2;
	int x, y, r;
	cout << "输入第一个圆de半径" << endl;
	cin >> r;
	cout << "输入第一个圆的x" << endl;
	cin >> x;
    cout << "输入第一个圆的y" << r << endl;
	cin >> y;
	c1.serxy(x, y);
	c1.setr(r);
	cout << "输入第2个圆de半径"  << endl;
	cin >> r;
	cout << "输入第2个圆的x" << endl;
	cin >> x;
	cout << "输入第2个圆的y" << endl;
	cin >> y;
	c2.serxy(x, y);
	c2.setr(r);
	if (c1.judge(c2) == true)
		cout << "相交" << endl;
	else cout << "不相交" << endl;

    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值