rect.cpp

来自「高等教育出版社出版的C++程序设计同步实验范例 希望对用这本教材得同学有点帮助」· C++ 代码 · 共 54 行

CPP
54
字号
#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 + =
减小字号Ctrl + -
显示快捷键?