下面定义一个基类Shape,在此基础上又定义了各个派生类,按照程序给出的注释要求填空

#include
<iostream.h>

class
Shape{

( )//访问控制权限为保护类型

double x,y;

public:

Shape(double
i=0, double j=0) {

x=i;

y=j;

}

⑥ //将GetArea声明为纯虚函数

};

class
Rectangle: public Shape{//定义矩形类

public:

Rectangle(double a,double b):Shape(a,b)//派生类的构造函数。

{ }

double GetArea( ){



}

};

class
Square: public Rectangle{//定义正方形类

public:

⑧ //定义正方形的构造函数,注意x和y的大小

{ }

};

⑨ //定义圆类Circle,从形状类公用继承

public:

Circle(double r):Shape(r,0)

{ }

double GetArea( ){

return 3.14*x*x;

}

};

void
main( ){

Rectangle r(20,15);

Square s(15);

⑩ //创建一个圆对象c,其半径为10

cout<<"矩形的面积为: "<<r.GetArea( )<<endl;

cout<<"正方形的面积为: "<<s.GetArea( )<<endl;

cout<<"圆形的面积为: "<<c.GetArea( )<<endl;

第1个回答  推荐于2017-09-11
⑥ void GetArea()=0;

⑦ return a*b;

⑧ Square(double x)::Shape(a,b){ a=x;b=x;}
⑨ class Circle: public shape
⑩ Circle c(10);追问

那上面括号内的呢

追答

protected:

相似回答