c++填空,定义一个Shape抽象类,由它派生出Rectanglr和Circle类。。。。。非常感谢
定义一个Shape抽象类,由它派生出Rectanglr和Circle类,二者都有GetArea()函数计算对象的面积,GetPerim()函数计算对象的周长#includ...
定义一个Shape抽象类,由它派生出Rectanglr和Circle类,二者都有GetArea( )函数计算对象的面积,GetPerim( ) 函数计算对象的周长
#include <iostream.h>
class Shape
{
[①定义GetArea 和GetPerim函数 ______]
};
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:
[②定义Rectangle构造函数_____________]
[③定义 GetArea()和 GetPerim()函数_______]
private:
float GetLength(){return itsLength;}
float GetWidth(){return itsWidth;}
private:
float itsWidth;
float itsLength; 展开
#include <iostream.h>
class Shape
{
[①定义GetArea 和GetPerim函数 ______]
};
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:
[②定义Rectangle构造函数_____________]
[③定义 GetArea()和 GetPerim()函数_______]
private:
float GetLength(){return itsLength;}
float GetWidth(){return itsWidth;}
private:
float itsWidth;
float 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);}
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);}
展开全部
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);}
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);}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询