输入格式
Rectangle的长和宽、Circle的半径、Square的边长
输出格式
Rectangle、Circle和Square对应的面积。四舍五入到整数
输入样例
3 7 6 4
2.1 3.5 10.3 4.5
输出样例
21 113 16
7 333 20
示例:
#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) ;
void getArea();
};
void Shape::getxy(float X, float Y){ x = X; y = Y; }
void Shape::getArea() { cout <<round( x * y) << endl; }
//派生Rectangle
class Rectangle : public Shape
{
public:
void getlw(float l, float w);//读取长度和宽度
};
void Rectangle::getlw(float l, float w) { x = l; y = w;}
//派生Circle
class Circle: public Shape
{
public:
void getr(float r);//读取半径
void getArea();
};
void Circle::getr(float r) { x = r; y = r; }
void Circle::getArea() { cout<<round (pi* x * y) << endl; }//圆的面积输出
class Square : public Rectangle
{
public:
void getb(float b);//读取边长
};
void Square::getb(float b) { x = b; y = b; }
int main()
{
Rectangle myjx;
Circle myyx;
Square myzfx;
float x, y, r, b;
while (cin >> x >> y >> r >> b)
{
myjx.getxy(x, y);
myjx.getArea();
myyx.getr(r);
myyx.getArea();
myzfx.getb(b);
myzfx.getArea();
}
return 0;
}