c++填空,定义一个Shape抽象类,由它派生出Rectanglr和Circle类。。。。。非常感谢

2024年11月30日 11:36
有2个网友回答
网友(1):

1. virtual float GetArea() = 0;
virtual float GetPerim() = 0; //两个纯虚函数
2. Rectangle(float width, float length):itsWidth(width), itsLength(length){}
3. float GetArea() {return itsWidth* itsLength;}
float GetPerim() {return 2 * (itsWidth + itsLength);}

网友(2):

1. virtual float GetArea() = 0;
virtual float GetPerim() = 0;

2. Rectangle(float width, float length):itsWidth(width), itsLength(length){}

3. float GetArea() {return itsWidth* itsLength;}
float GetPerim() {return 2 * (itsWidth + itsLength);}