#include
using namespace std;
class Shape
{
public:
Shape(){}
~Shape(){}
virtual float getArea()
{
return -1;
}
virtual float getLen()
{
return -1;
}
};
class Rectangle:public Shape
{
public:
Rectangle(float len,float width):_Len(len),_Width(width){}
~Rectangle()
{
cout<<"调用析构函数"<<endl;
}
virtual float get_Len() { return _Len; }
virtual float get_Width() { return _Width; }
virtual float getArea()
{
return _Len * _Width;
}
virtual float getLen()
{
return 2 * _Len * _Width;
}
private:
float _Len;
float _Width;
};
class Circle:public Shape
{
public:
Circle(float r):_R(r){}
~Circle()
{
cout<<"调用析构函数"<<endl;
}
virtual float get_R(){return _R;}
virtual float getArea()
{
return 3.14 * _R * _R;
}
virtual float getLen()
{
return 3.14 * 2 * _R;
}
private:
float _R;
};
int main()
{
Rectangle rectangle(3,6);
Shape *z = &rectangle;
z->getArea();
z->getLen();
Circle circle(10);
Shape *c = &circle;
c->getArea();
c->getLen();
//system("pause");
return 0;