作者在 2014-05-02 23:25:09 发布以下内容
class Shape
{
public:
Shape() {}
~Shape() {}
virtual float GetArea()=0;
virtual float GetPerim()=0;
};
class Circle:public Shape
{
public:
Circle(float radius):itsRadius(radius) {}
float GetArea()
{
return 3.14*itsRadius*itsRadius;
}
float GetPerim()
{
return 6.28*itsRadius;
}
private:
float itsRadius;
};
class Rectangle :public Shape
{
public:
Rectangel(float len, float width):itsLength(len),itsWidth(width) {};
~Rectangel (){};
virtual float GetArea()
{
return itsLength* itsWidth;
}
float GetPerim()
{
return 2*itsLength+2*itsWidth;
}
virtual float GetLength()
{
return itsLength;
}
virtual float GetWidth()
{
return itsWidth;
}
private:
float itsWidth;
float itsLength;
};