⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rect.cpp

📁 高等教育出版社出版的C++程序设计同步实验范例 希望对用这本教材得同学有点帮助
💻 CPP
字号:
#include <iostream.h>
#include "rect.h"
// 构造函数,带缺省参数,缺省值为全0
Rectangle::Rectangle(int l , int t , int r , int b )
 {
	left = l; top = t;
	right = r; bottom = b; 
}
void Rectangle::Assign(int l, int t, int r, int b)
{
	left = l; top = t;
	right = r; bottom = b;
}
void Rectangle::Show()
{
	cout<<"left-top point is ("<<left<<","<<top<<")"<<'\n';
	cout<<"right-bottom point is ("<<right<<","<<bottom<<")"<<'\n';
}

void Rectangle::operator+=(Rectangle& rect)
{
	int x = rect.right - rect.left;
	int y = rect.bottom - rect.top;
	right += x;
	bottom += y;
}

void Rectangle::operator-=(Rectangle& rect)
{
	int x = rect.right - rect.left;
	int y = rect.bottom - rect.top;
	right -= x;
	bottom -= y;
}

Rectangle operator+ ( Rectangle &rect1 , Rectangle& rect2)
{
	//矩形相加,从rect1中加上rect2的长度和宽度
	rect1 += rect2;
	return rect1;
}

Rectangle operator- ( Rectangle &rect1, Rectangle& rect2)
{
	//矩形相减,从rect1中减去rect2的长度和宽度
	rect1 -= rect2;
	return rect1;
}
/*void Rectangle::Draw(CDC * pDC) 
{ 
pDC->Rectangle(left, top, right, bottom ); 
}*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -