题目描述
定义点类为基类,其数据成员x和y为私有成员。再定义矩形类继承点类,该点为矩形的左下角,新增数据成员矩形的2条边长。计算并且显示矩形右上角的坐标。
输入
包含多组测试例, 每组数据的第1行是矩形左下角的坐标,第2行是矩形的2条边长。
输出
矩形右上角的坐标。
样例输入 Copy
-4 5
8 10
100 -60
52 32
样例输出 Copy
4 15
152 -28
# include <iostream>
using namespace std;
class Point
{
public:
Point(int a = 0, int b = 0)
{
x = a;
y = b;
}
void show()
{
cout << x << " " << y << endl;
}
void SetXY(int a, int b)
{
x = a;
y = b;
}
friend class CRectangle;
private:
int x;
int y;
};
class CRectangle :public Point
{
public:
CRectangle() {}
CRectangle(int a, int b, int c, int d):Point(a, b), width(c), height(d){}
void setWH(int a, int b)
{
width = a;
height = b;
}
void showRightTop()
{
int x1, y1;
x1 = width + x;
y1 = height + y;
cout << x1 << " " << y1 << endl;
}
private:
int width;
int height;
};
int main()
{
int a, b, c, d;
while (cin >> a >> b >> c >> d)
{
CRectangle r;
r.SetXY(a, b);
r.setWH(c, d);
r.showRightTop();
}
return 0;
}