#include<iostream>
#include<cmath>
const double PI = 3.1415;
using namespace std;
class Shape {
public:
Shape() {
cout << "执行Shape类的构造函数" <<endl;
}
~Shape() {
cout << "执行Shape类的析构函数" << endl;
}
};
class Rectangle :public Shape {
public:
Rectangle(double a=0, double b=0) {
width= a;
length= b;
}
double getArea() {
return width*length;
}
private:
double width,length;
};
class Circle :public Shape {
Circle(float r) {
radius = r;
}
double getArea() {
return radius*radius*PI;
}
private:
float radius;
};
class Square :public Rectangle {
Square(double a) {
Rectangle(a,a);
}
};
void main() {
Rectangle a(5, 6);
cout<<"a的面积为"<<a.getArea()<<endl;
Square b(5);
cout << "b的面积为" <<b.getArea();
getchar();
}