#include<iostream>
#include <iomanip>
using namespace std;
class Shape {
public:
Shape(double r, double rl, double rw, double sl):radius(r),rlength(rl),rwidth(rw),slength(sl) {};、
Shape();
private:
double radius;
double rlength;
double rwidth;
double slength;
};
Shape::Shape(){}
class Rectangle :public Shape {
public:
Rectangle();
~Rectangle() {}
void getArea(double a, double b) {
cout << "The area of the Rectangle is " <<setiosflags(ios::fixed)<<setprecision(2)<<1.00*a * b << endl;
};
};
Rectangle::Rectangle(){}
class Circle :public Shape {
public:
Circle();
~Circle() {}
void getArea(double c) {
cout << "The area of the Circle is "<<setiosflags(ios::fixed) <<setprecision(2)<< 3.14 * c * c <<setprecision(2)<< endl;
};
};
Circle::Circle()
{
}
class Square :public Rectangle {
public:
Square();
~Square() {}
void getArea(double d) {
cout << "The area of the Square is "<<setiosflags(ios::fixed) <<setprecision(2)<< 1.00*d * d <<setprecision(2)<< endl;
};
};
Square::Square(){}
int main() {
double r, rl, rw, sl;
Shape shape(r, rl, rw, sl);
Rectangle rectangle;
Circle circle;
Square square;
Rectangle* q;
Circle* w;
Square* e;
q = &rectangle;
w = &circle;
e = □
cout << "input the radius of circle: ";
cin >> r;
w->getArea(r);
cout << endl;
cout << "input the length and width of rectangle: ";
cin >> rl >> rw;
q->getArea(rl, rw);
cout << endl;
cout << "input the length of square: ";
cin >> sl;
e->getArea(sl);
cout << endl;
return 0;
}
【样例输入】
input the radius of circle: 5
input the length and width of rectangle: 4 6
input the length of square: 5
【样例输出】
The area of the Circle is 78.50
The area of the Rectangle is 24.00
The area of the Square is 25.00