拷贝构造、赋值构造、获取面积、获取IOU面积、获取交集面积、并集面积、面积大小比较、是否为同一长方形比较、自定义cout << 打印函数
Rectangular(double l=0, double t=0, double w=0, double h=0)
{
if (w < 0 || h < 0)
{
cout << "width or height cannot be negative" << endl;
}
else
{
left = l;
top = t;
width = w;
height = h;
area = width*height;
}
}
其中 l表示left,t表示top,left,top表示长方形最上角定点的坐标。w表示width(宽度),h表示height(高度)
主函数测试如下:
int main(int argc, char *argv[])
{
Rectangular a(0, 0, 10, 20);
Rectangular b(0, 0, 20, 10);
Rectangular c(0, 0, 20, 11);
Rectangular b2(b);
cout << "a information: " << endl;
cout << a << endl;
cout << "b information: " << endl;
cout << b << endl;
cout << "b2 information: " << endl;
cout << b2 << endl;
cout << "c information: " << endl;
cout << c << endl;
cout << "a == b : " << (a == b) << endl;
cout << "b == b2 : " << (b == b2) << endl;
cout << "b > b2 : " << (b > b2) << endl;
cout << "b >= b2 : " << (b >= b2) << endl;
cout << "a < c : " << (a < c) << endl;
cout << "a - b : " << a - b << endl;
cout << "a - c : " << a - c << endl;
cout << "a + b : " << a + b << endl;
cout << "a + c : " << a + c << endl;
return 0;
}