● 试题五(共15分)
阅读以下说明和Java程序,填写程序中的空(1)~(6),将解答写入答题纸的对应栏内。
【说明】
以下Java代码实现一个简单绘图工具,绘制不同形状以及不同颜色的图形。部分接口、类及其关系如图5-1所示。
【Java代码】
interface Draw Circle{//绘制圆形
public (1) ;
}
class Red Circle implements Red Circle{//绘制红色圆形
public void draw Circle(int radius,int x,int y){
System.out.print In("Drawing Circle[red,radius:"+radius+",X:"+x+",y:"+y+"]");
}
}
class Green Circle implements Draw Circle{//绘制绿色圆圆形
public void draw Circle(int radius,int x,int y){
System.out.print In("Drawing Circle[green,radius:"+radius+",X:"+x+",y:"+y+"]");
}
}
abstract class Shape{//形状
protected (2) ;
public Shape(Draw Circle draw Circle){
this.draw Circle= draw Circle;
}
public abstract void draw__(5)__;
}
class Circle extends Shape{//圆形
private int x,y,radius;
public Circle(int x,int y,int radius,Draw Circle draw Circle){
(3) ;
this.x=x;
this.y=y;
this.radius=radius;
}
public void draw( ){
draw Circle. (4) ;
}
}
public class Draw Circle Main{
public static void main(String[]args){
Shape red Circle=new Circle(100,100,10, (5) );//绘制红色圆形
Shape green Circle=new Circle(2000,200,10, (6));//绘制绿色圆形
red Circle.draw__(6)__;
green Circle.draw__(7)__;
}
}
●
试题六(共15分)
阅读下列说明和C++代码,填写程序中的空(1)~(6),将解答写入答题纸的对应栏内。
【说明】
以下C++代码实现一个简单绘图工具,绘制不同形状以及不同颜色的图形。部分类及其关系如图6-1所示。
【C++代码】
#include <iostream>
#include <string>
using name space std;
class Draw Circle{//绘制圆形,抽象类
public:
(1);//定义参数为 int radius,int x,int y
virtual~Draw Circle__(6)__{ }
};
class Red Circle: public Draw Circle{ //绘制红色圆形
public.
void draw Circle(int radius,int x,int y){
cout<<"Drawing Circle[red,radius:"<<radius;
cout<<",X:"<<X<<",y:"<<y<<"]"<<end1;
}
};
class Green Circle:public Draw Circle{//绘制绿色圆形
public:
void draw Circle(int radius,int x,int y){
cout <<"Drawing Circle[green,radius:"<<radius;
cout<<",X:"<<X<<",y:"<<y<<"]"<<end1;
}
};
class Shape{ //形状,抽象类
protected:
(2) ;
public:
Shape(Draw Circle*draw Circle){
this->draw Circle=draw Circle;
}
virtual~shape__(7)__{}
public:
virtual void draw__(8)__=0;
};
class Circle: public Shape{//圆形
private:
int x,y,radius;
public:
Circle(int x,int y,int radius,Draw Circle*draw Circle) (3) {
this->x=x;
this->y=y;
this->radius=radius;
}
Public:
void draw__(9)__{
draw Circle -> (4) ;
}
};
int main__(10)__
{
Shape*red Circle=new Circle(100,100,10, (5) ); //绘制红色圆形
Shape*green Circle=new Circle(100,100,10, (6) ); //绘制绿色圆形
red Circle ->draw__(11)__;
green Circle ->draw__(12)__;
return 0;
}
各省软考办 | ||||||||||