📄 rect.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 + -