C++程序设计-3.25

判断两矩形关系

#include<iostream>
#include<algorithm>
#include<string>
#include<ctime>
#include<cstdlib>
#include<cmath>
#include<iomanip>
#include<typeinfo>
#define _CRT_SECURE_NO_WARNINGS
using namespace std;
/*void Switch(int a1, int a2)
{
	int temp;
	temp = a1;
	a1 = a2;
	a2 = temp;
}
void BubbleSort(int a[])
{
	int Number = 3;
	for (int i = 0; i < Number; i++)
		for (int j = i; j < Number; j++)
			if (a[i] > a[j])
			{
				int temp;
				temp = a[j];
				a[j] = a[i];
				a[i] = temp;
			}
}*/


int main(char argc)
{
	
	class angle
	{
	public:
		double x;
		double y;
	};


	cout << "Enter r1's center x-,y-coordinates, width, and height: ";
	double x1, y1, w1, h1;
	cin >> x1 >> y1 >> w1 >> h1;
	cout << "Enter r2's center x-,y-coordinates, width, and height: ";
	double x2, y2, w2, h2;
	cin >> x2 >> y2 >> w2 >> h2;
	angle angle11, angle12, angle21, angle22;
	angle11.x = x1 + w1;
	angle11.y = y1 + h1;
	angle12.x = x1 - w1;
	angle12.y = y1 - h1;
	angle21.x = x2 + w2;
	angle21.y = y2 + h2;
	angle22.x = x2 - w2;
	angle22.y = y2 - h2;
	if (min(angle11.x, angle21.x) < max(angle12.x, angle22.x))
		cout << "r2 does not overlap r1";
	else
	{
		if (min(angle11.x, angle21.x) == angle21.x&&
			min(angle11.y, angle21.y) == angle21.y&&
			max(angle12.x, angle22.x) == angle22.x&&
			max(angle12.y, angle22.y) == angle22.y)
			cout << "r2 is inside r1";
		else
			cout << "r2 overlaps r1";
	}
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值