题目详情

阅读下列说明和C++代码,填写程序中的空(1)~(6),将解答写入答题纸的对应栏内。

【说明】

以下C++代码实现一个简单绘图工具,绘制不同形状以及不同颜色的图形。部分类及其关系如图6-1所示。

中级软件设计师,模拟考试,2021年软件设计师模拟题7

【C++代码】

#include?#include?using?namespace?std;class?DrawCircle?{??????//绘制圆形,抽象类? ? ? public: (1);//定义参数为?int?radius,?int?x,?inty? ?virtual~DrawCircle()?{?}};class?RedCircle:public?DrawCircle?{????//绘制红色圆形? ? ? ? public: void?drawCircle(intradius,?int?x,?int?y)?{cout?<<?"Drawing?Circle[red,radius:<<radius;? ? ? ? ? ? ? cout?<<?",x:?"?<<x<<?",y:"<<y<<?"]"?<<?end1;? ?}};class?GreenCircle:public?DrawCircle?{????//绘制绿色圆形? ? ? public:? ?void?drawCircle(int?radius,?int?x,?int?y)?{ cout?<<"Drawing?Circle[green,radius:?"<<?radius;? ? ? ? ? ? ? ? ? ? ? ?cout?<<",x:?"?<<x<<?",y:?"<<y<<?"]"?<<?end1;? }};class?Shape?{????//形状,抽象类? ? ? protected:? (2);? ? ? public:? ?Shape(DrawCircle*drawCircle)?{? this?->?drawCircle?=?drawCircle;? }? ?virtual~shape()?{?}? public:? ?virtual?void?draw()?=?0;};class?Circle:public?Shape?{????//圆形? ? private:? ? ?int?x,y,radius;? ? public:? Circle(int?x,inty,int?radius,DrawCircle?*drawCircle)? (3)? {? this->x?=?x;? ?this->y?=?y;? ? this->radius?=?radius; }? ? ? public:? void?draw(){? drawCircle?-> (4); }};int?main(){Shape?*redCirclenew?Circle(100,100,10,????(5)????);//绘制红色圆形? Shape?*greenCircle=new?Circle(100,100,10, (6)??);//绘制绿色圆形redCircle >draw();? ?greenCircle?->draw();? ?return?0;}

正确答案及解析

正确答案
解析

(6)(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里面的实参。

包含此试题的试卷

你可能感兴趣的试题

单选题

Advancements in ( )have contributed to the growth of the automotive industry through the creation and evolution of self-driving vehicles.

  • A.Artificial Intelligence
  • B.Cloud Computing
  • C.Internet of Things
  • D.Big Data
查看答案
单选题

In project human resource management , ( )is not a source of power for the project manager.

  • A.referent power
  • B.expert power
  • C.reward power
  • D.audit power
查看答案
单选题

At the project establishment stage , the feasibility study mainly includes techinical feasibility analysis , ( ), operation environment feasibility analysis and other aspects of feasibility analysis.

  • A.detail feasibility analysis
  • B.opportunity analysis
  • C.economic feasibility analysis
  • D.risk analysis
查看答案
单选题

( )is a grid that shows the project resources assigned to each work package.

  • A.Stakeholder engagement assessment matrix
  • B.Requirements traceability matrix
  • C.Probability and impact matrix
  • D.Responsibility assignment matrix
查看答案
单选题

Xinhua News Agency reported in January 2022,Chian will further promote the developmet of a digital economy during the 14th Five-Year Plan eriod(2021-2025). The plan also emphasized industrial ( )transformation.

  • A.digital
  • B.networking
  • C.intelligentize
  • D.informatization
查看答案

相关题库更多 +