阅读下列说明和C++代码,填写程序中的空(1)~(6),将解答写入答题纸的对应栏内。【说明】以下C++代码实现一个简单绘图工具,绘制不同形状以及不同颜色的图形。部分类及其关系如图6-1所示。 【C++代码】#include<iostream>#include<string>usingnamespacestd;classDrawCircle{//绘制圆形,抽象类public:(1);//定义参数为intradius,intx,intyvirtual~DrawCircle(){}};classRedCircle:publicDrawCircle{//绘制红色圆形public:voiddrawCircle(intradius,intx,inty){cout<<"DrawingCircle[red,radius:"<<radius;cout<<",x:"<<x<<",y:"<<y<<"]"<<end1;}};classGreenCircle:publicDrawCircle{//绘制绿色圆形public:voiddrawCircle(intradius,intx,inty){cout<<"DrawingCircle[green,radius:"<<radius;cout<<",x:"<<x<<",y:"<<y<<"]"<<end1;}};classShape{//形状,抽象类protected:(2);public:Shape(DrawCircle*drawCircle){this->drawCircle=drawCircle;}virtual~shape(){}public:virtualvoiddraw()=0;};classCircle:publicShape{//圆形private:intx,y,radius;public:Circle(intx,inty,intradius,DrawCircle*drawCircle)(3){this->x=x;this->y=y;this->radius=radius;}public:voiddraw(){drawCircle->(4);}};intmain(){Shape*redCircle=newCircle(100,100,10,(5));//绘制红色圆形Shape*greenCircle=newCircle(100,100,10,(6));//绘制绿色圆形redCircle->draw();greenCircle->draw();return0;}
(1)void drawCircle (int radius,int x,int y)(2)DrawCircle*drawCircle(3)drawcircle(4)drawCircle(radius,x,y)(5)new redCircle()(6)new greenCircle() 【解析】 第一空是填接口里面的方法,在接口的实现里面找,可以发现应该填void drawCircle (int radius,int x,int y)。第二空可以根据后面this drawCircle=drawCircle判断,这里应该有一个drawCircle属性,因此应该填)DrawCircle drawCircle。第三空这里填drawcircle,用-> drawcircle来引用父类的成员。第四空调用drawCircle(radius,x,y)方法。第五、六空分别创建一个红色圆形对象和一个绿色圆形对象作为Circle里面的实参。