输入格式
Rectangle的长和宽、初始坐标、坐标变化量
输出格式
Rectangle的面积、初始坐标离原点的距离、坐标变化后离原点的距离。四舍五入到整数
输入样例
3 4 2.5 3.0 -0.5 2.5
输出样例
12 4 6
示例:
#include <iostream>
#include <math.h>
using namespace std;
float pi = 3.1415926;
class Shape
{
protected:
float x, y;
//在矩形中x.y表示为长和宽,在圆形中都表示为半径,在正方形中都表示为边长
public:
void getxy(float X, float Y);
virtual void getArea();//虚函数
};
void Shape::getxy(float X, float Y) { x = X; y = Y; }
void Shape::getArea() { cout << round(x * y) << " "; }
class Point
{
protected:
float line, row;
float cline, crow;
//在矩形中表示该矩形左上角的坐标
public:
void getplace(float Line, float Row)
{//读取坐标 并且输出距离
cout << round(sqrt(line * line + row * row))<<" ";
}
void replace(float Cline,float Crow)
{
cout << round(sqrt((line + cline) * (line + cline) + (row + crow) * (row + crow))) << endl;;
}
};
//派生Rectangle
class Rectangle : public Shape ,public Point
{
public:
void getlw(float l, float w);//读取长度和宽度
void getlwp(float Line,float Row) { line = Line; row = Row; }
void getclw(float Cline,float Crow){ cline = Cline; crow = Crow;}
};
void Rectangle::getlw(float l, float w) { x = l; y = w; }
float a;
float b;
void fun1(Shape* p1)//定义函数参数为指向基类对象的指针
{
p1->getArea();
}
void fun2(Point* p2)
{
p2->getplace(a,b);
}
void fun3(Point* p3)
{
p3->replace(a,b);
}
int main()
{
Rectangle myjx;
float x, y, line, row, cline, crow;
while (cin >> x >> y >> line >> row >> cline >> crow)
{
myjx.getxy(x, y);
fun1(&myjx);
myjx.getlwp(line, row);
fun2(&myjx);
myjx.getclw(cline, crow);
fun3(&myjx);
}
return 0;
}