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

2024-11-30 11:36:39
推荐回答(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);}