#include
using namespace std;
class ClsShape
{
public:
virtual float area() const {return 0.0;}
virtual float perimeter() const {return 0.0;}
virtual float volume() const = 0;
};
class ClsRect:public ClsShape
{
public:
ClsRect(float l , float w):length(l),width(w){};
float area() const;
float perimeter() const;
protected:
float length;
float width;
};
float ClsRect::area() const
{
return length * width ;
}
float ClsRect::perimeter() const
{
return 2 * (length + width);
}
class ClsCub : public ClsRect
{
public:
ClsCub(float h, float l, float w) : ClsRect(l,w)
{
height = h;
}
float area() const;
float perimeter() const;
float volume() const;
private:
float height;
};
float ClsCub::area() const
{
return 2 * (length * width + width * height + length * height);
}
float ClsCub::perimeter() const
{
return 4 * (length + width + height);
}
float ClsCub::volume() const
{
return length * width * height;
}
int main()
{
//...
return 0;
}