网友您好, 请在下方输入框内输入要搜索的题目:

题目内容 (请给出正确答案)

39、下面是类Shape的定义:class Shape {public: virtual void Draw()=0; }; 下列关于Shape类的描述中,正确的是()。

A.类Shape是虚基类

B.类Shape是抽象类

C.类Shape中的Draw函数声明有误

D.语句“Shape s;”能够建立Shape的一个对象s


参考答案和解析
B
更多 “39、下面是类Shape的定义:class Shape {public: virtual void Draw()=0; }; 下列关于Shape类的描述中,正确的是()。A.类Shape是虚基类B.类Shape是抽象类C.类Shape中的Draw函数声明有误D.语句“Shape s;”能够建立Shape的一个对象s” 相关考题
考题 ( 12 ) “ 图形 ” 类 Shape 中定义了纯虚函数 CalArea() ,“ 三角形 ” 类 Triangle 继承了类Shape ,请 将Triangle 类中的 CalArea 函数补充完整。class Shape{public:virtual int CalArea()=0;}class Triangle: public Shape{public:Triangle{int s, int h}: side(s),height(h) {}【 12 】 { return side*height/2 ; }private:int side;int height;};

考题 ( 32 )下面是类 Shape 的定义:class Shape{public:virtual void Draw()=0;};下列关于 Shape 类的描述中,正确的是A )类 Shape 是虚基类B )类 Shape 是抽象类C )类 Shape 中的 Draw 函数声明有误D )语句 “ Shape s; ” 能够建立 Shape 的一个对象 s

考题 下列关于Test类的定义中,正确的是______。A) class Test implements Runnabte{public void run(){}public void someMethod(){}B) class Test implements Rnuuable{public void run();}C) class Test implements Rnuuable{public void someMethod();}D) class Test implements Rnuuable{public void someMethod();{}}A.B.C.D.

考题 下面是类Shape的定义: class Shape{ public: virtual void Draw()=0; } 下列关于Shape类的描述中,正确的是( )。A.类Shape是虚基类B.类Shape是抽象类C.类Shape中的Draw函数声明有误D.语句“Shape s;”能够建立Shape的一个对象s

考题 阅读以下说明和C++代码,填入(n)处。[说明]以下C++代码使用虚函数实现了同一基类shape派生出来的Class rectangle、Class triangle、Class circle实现了计算矩形、圆形面积的计算。仔细阅读以下代码,将(n)处语句补充完整。[代码5-1]include<iostream.h>define PI 3.14159class shape {//基类protected:(1);public:(2);(3);};[代码5-2]class rectangle: public shape {public:rectangle (int x2,int y2,int r2): (4) {};double area ( ) {return x*y; };};class circle: public shape {public:circle (int x3,int y3,int r3):(5){};double area ( ) {return r*r*PI; };};[代码5-3]void main ( ){rectangle r (10,20,0);circle c (0,0,30);shape (6);cout<<"长方形面积="<<s1->area ( ) <<endl;cout<<"圆形面积="<<s2->area ( ) <<endl;}[运行结果]长方形面积=200圆形面积=2827.43

考题 若有如下类定义:class Shape {public:virtual void Draw()=0;};则下列关于Shape类的叙述中,正确的是( )。 A. 类Shape是虚基类B.类Shape是抽象类C.类Shape中的Draw函数声明有误D.“Shape s;”能建立Shape的对象s

考题 如下程序声明了一个二维图形类TwoDShape,从其派生出矩形类Rec。 include include 如下程序声明了一个二维图形类TwoDShape,从其派生出矩形类Rec。include<iostream>include<string>using namespaee std,class TwoDShape{// 二维图形类char name[20];public:TwoDShape (char * n="unknown") {strcpy(name, n);}Char * getName(){return name;}【 】=0;};class Rec: public TwoDShape{double width, heightpublic:Rec(double w-=0. 0,double h=0. 0):TwoDShape("rectangle"){ width=w; height=h; }double getWidth() {return width;}double getHeight() {return height;}double area() {return width * height;}};int main() {TwoDShape * shape;Shape=new Rec(2.1,3.0);cout<<"object is"<<shape->getName()<<"\n";cout<<"Area is"<<shape->area()<<"\n";return 0}请将程序补充完整,使程序在运行时输出:abject is triangleArea is 6.3

考题 阅读以下说明和C++代码,[说明]现要编写一个画矩形的程序,目前有两个画图程序:DP1和DP2,DP1用函数draw_a_line(x1,y1,x2,y2)画一条直线,DP2则用drawline(x1,x2,y1,y2)画一条直线。当实例化矩形时,确定使用DP1还是DP2。为了适应变化,包括“不同类型的形状”和“不同类型的画图程序”,将抽象部分与实现部分分离,使它们可以独立地变化。这里,“抽象部分”对应“形状”,“实现部分”对应“画图”,与一般的接口(抽象方法)与具体实现不同。这种应用称为Bridge(桥接)模式。图6-1显示了各个类间的关系。[图6-1]这样,系统始终只处理3个对象:Shape对象、Drawingg对象、DP1或DP2对象。以下是C++语言实现,能够正确编译通过。[C++代码]class DP1{public:static void draw_a_line(double x1,double y1,double x2,double y2){//省略具体实现}};class DP2{public:static void drawline(double x1,double x2,double y1,double y2){//省略具体实现}};class Drawing{public:(1) void drawLine(double x1,double y1,double x2,double y2)=0;};class V1Drawing:public Drawing{public:void drawLine(double x1,double y1,double x2,double y2){DP1::draw_a_line(x1,y1,x2,y2);}};class V2Drawing:public Drawing{public:void drawLine(double x1,double y1,double x2,double y2){(2)}};class Shape{privatc:(3) dp;public:Shape(Drawing*dp);virtual void draw()=0;void drawLine(double x1,double y1,double x2,double y2);};Shape::Shape(Drawing*dp){_dp=dp;}void Shape::drawLine(double x1,double y1,double x2,double y2){ //画一条直线(4);}class Rectangle:public Shape{privatc:double_x1,_y1,_x2,_y2;public:Rectangle(Drawing *dp,double x1,double y1,double x2,double y2);void draw();};Rectangle::Rectangle(Drawing*dp,double x1,double y1,double x2,double y2): (5){_x1=x1;_y1=yl;_x2=x2;_y2=y2;}void Rectangle::draw(){//省略具体实现}(1)

考题 阅读以下说明和C++代码,将应填入(n)处的字句写上。[说明]现有一个显示系统,要显示的图形有线Line、矩形Square,抽象出一个Shape类(接口),有方法显不display()。需要新增图形Circle,又已知有类XXCircle实现了所需要实现的功能:显示displayIt()。为了继承自shape以提供统一接口,又不希望从头开发代码,希望使用XXCircle。这样将XXcircle作为Circle的一个属性,即Circle的对象包含一个XXCircle对象。当一个Circle对象被实例化时,它必须实例化一个相应的XXCircle对象: Circle对象收到的做任何事的请求都将转发给这个XXCircle对象。通过这种称为Adapter模式,Circle对象就可以通过“让XXCircle做实际工作”来表现自己的行为了。图6-1显示了各个类间的关系。以下是C++语言实现,能够正确编译通过。[图6-1][C++代码]class Shape{public:(1) void display()=0;};class Line:public Shape{//省略具体实现};class Square:public Shape{//省略具体实现};class XXCircle{public:void displayIt(){//省略具体实现}//省略其余方法和属性};class Circle:public Shape{private:XXCircle *pxc;public:Circle();void display();};Circle::Circle(){pxc=(2);}void Circle::display(){pxc->(3);}class Factory{public:(4) getshapeInstance(int type){//生成特定类实例switch(type){case 1:return new Square;case 2:return new Line;case 3 :return new Circle;default:return NULL;}}};void main(int argc,char*argv[]){if(argc !=2){cout<<"error parameters!"<<endl;return;}int type=atoi(argv[1]);Factory factory;Shape*s=factory. (5);if(s==NULL){cout<<"Error get the instance!"<<endl;return;}s->display();delete s;return;}(1)

考题 下面是类Shape的定义: classShape{ public: virtualvoidDraw( )=0; } 下列关于Shape类的描述中,正确的是( )。A.类Shape是虚基类B.类Shape是抽象类C.类Shape中的Draw函数声明有误D.语句“ShapeS;”能够建立Shape的一个对象S

考题 阅读以下说明和c++代码,将应填入(n)处的字句写在对应栏内。【说明】现要编写一个画矩形的程序,目前有两个画图程序:DP1和DP2,DP1用函数draw_a_line(x1, y1,x2,y2)画一条直线,DF2则用drawline(x1,x2,y1,y2)画一条直线。当实例画矩形时,确定使用DP1还是DP2。为了适应变化,包括“不同类型的形状”和“不同类型的画图程序”,将抽象部分与实现部分分离,使它们可以独立地变化。这里,“抽象部分”对应“形状”,“实现 部分”对应“画图”,与一般的接口(抽象方法)与具体实现不同。这种应用称为Bridge(桥接)模式。图9-7显示了各个类间的关系。这样,系统始终只处理3个对象:Shape对象、Drawing对象、DP1或DP2对象。以下是 C++语言实现,能够正确编译通过。【C++代码】class DP1{public:static void draw_a_line(double x1, double y1,double x2, double y2){//省略具体实现});class DP2{public:static void drawline(double x1, double x2,double y1, double y2){//省略具体实现}};class Drawing{public:(1) void drawLine(double x1,double y1,double x2,double y2)=0;};class V1Drawing:public Drawing{public:void drawLine(double x1, double y1,double x2, double y2){DP1::draw_a_line(x1,y1,x2,y2);}};class V2Drawing:public Drawing{public:void drawLine(double x1, double y1, double x2, double y2){(2);}};class Shape{private:(3) _dp;public:Shape(Drawing *dp);virtual void draw()=0;void drawLine(double x1, double y1, double x2, double y2);};Shape::Shape(Drawing *dp){_dp = dp;}void Shape::drawLine(double x1, double y1, double x2, double y2){ //画一条直线(4);}class Rectangle: public Shape{private:double _x1,_y1,_x2,_y2;public:Rectangle(Drawing *dp, double x1, double y1,double x2, double y2);void draw();};Rectangle::Rectangle(Drawing *dp, double x1, double y1, double x2, double y2):(5){_x1=x1;_y1=y1;_x2=x2;_y2=y2;}void Rectangle::draw(){//省略具体实现}

考题 编译以下代码,将出现什么情况?()abstract class Shape{ abstract void draw();}Class Square extends Shape{ }A. Square类和Shape类都可以成功编译B. Square类无法编译,但Shape类可以编译C. 类无法编译,但Square类可以编译D. Square类和Shape类都无法编译

考题 试题六(共15分)阅读以下说明、图和Java代码,填补Java代码中的空缺(1)~(6),将解答写在答题纸的对应栏内。【说明】已知对某几何图形绘制工具进行类建模的结果如图6.1所示,其中Shape为抽象(abstract)类,表示通用图形,Box(矩形)、Ellipse(椭圆)和Line(线条)继承(extends)了Shape类,其中,Circle表示圆(即特殊的椭圆)。下面的Java代码用于实现图 6-1所给出的设计思路,将其空缺处填充完整并编译运行,输出结果为:EllipseCircleEllipseCE【Java代码】(1) class Shape{public Shape(String name){this.name= name;}(2) void paint();String getName(){retum this.name;}final String name;};//Box 和Line类似下面 Ellipse,其代码略class Ellipse (3) {public Ellipse(String name){super(name);System.out.println("Ellipse");}Void paintO{∥绘制现状示意代码System.out.println(getName0);}};class Circle (4) {public Circle(String name){super(name);System.out.println("Circle");}};class Diagram{private Shape shapes[]= new Shape[2];public void drawAShape(Shape shape){shape.paint();}void erase A Shape(Shape shape){∥删除形状,代码略}void drawShapes(){shapes*0+= new Circle("C”);shapes[l]= new Ellipse("E");for (int i=O; i2;++i) {drawAShap(shapes[i]);//绘制形状}}void close(){for (int i=0;i2; ++1) { []关闭图,删除所绘制图形(5) ;}}public static void main(String[] args){Diagram diagram= (6) ;diagram.drawShapes();diagram.close();}}

考题 从下列2道试题(试题五至试题六)中任选 1道解答。如果解答的试题数超过1道,则题号小的1道解答有效。试题五(共15分)阅读以下说明、图和C++代码,填补C++代码中的空缺(1)~(5),将解答写在答题纸的对应栏内。【说明】已知对某几何图形绘制工具进行类建模的结果如图5.1所示,其中Shape为抽象类(应至少包含一个纯虚拟( virtual)函数),表示通用图形,Box表示矩形,Ellipse表示椭圆,Circle表示圆(即特殊的椭圆),Line表示线条。下面的C++代码用于实现图5-1所给出的设计思路,将其空缺处填充完整并编译运行,输出结果为:EllipseCircleEllipseCE【C++代码】include stringinclude iostreamusing namespace std;class Shape{public:Shape(const string name){m_name= name;}~Shape(){}(1) void paint() = 0;stringgetName()const {retumm name;}Private:string m_name;};//Box和 Line类的定义与 Ellipse类似,其代码略classEllipse (2) {public:Ellipse(const string name) : Shape(name){ cout"Ellipse" endl; }Voidpaint() { coutgetName()endl;}};classCircle (3) {public:Circle(const string name) : Ellipse(name){ cout"Circl"endl; }};class Diagram {public:void drawAShap(Shape* shape){ shape-paint(); }void drawShapes() {shapes[0] = new Circle("C");shapes[l] = new Ellipse("E");for (int i=O;i2; ++1) {drawAShap(shapes[i]);}}void close (){ /*删除形状,代码略 */ }private:Shape* shapes[2];};int main( ){Diagram* diagram = (4)diagram-drawShapes();diagram-close ();(5) diagram;}

考题 阅读下列说明和C++代码,填写程序中的空(1)~(6),将解答写入答题纸的对应栏内。 【说明】以下C++代码实现一个简单绘图工具,绘制不同形状以及不同颜色的图形。部分类及其关系如图6-1所示。 【C++代码】#include #include using namespace std;class DrawCircle { //绘制圆形,抽象类 public: (1) ;//定义参数为 int radius, int x, int y virtual~DrawCircle() { }}; class RedCircle:public DrawCircle { //绘制红色圆形 public: void drawCircle(int radius, int x, int y) { cout drawCircle = drawCircle; } virtual~shape() { } public: virtual void draw() = 0;}; class Circle:public Shape { //圆形 private: int x,y,radius; public: Circle(int x,int y,int radius,DrawCircle *drawCircle) (3) { this->x = x; this->y = y; this->radius = radius; } public: void draw() { drawCircle -> (4) ; }}; int main(){ Shape *redCircle=new Circle(100,100,10, (5) );//绘制红色圆形 Shape *greenCircle=new Circle(100,100,10, (6) );//绘制绿色圆形 redCircle ->draw(); greenCircle ->draw(); return 0;}

考题 阅读以下说明和Java程序,填写程序中的空(1)~(6),将解答写入答题纸的对应栏内。 【说明】 以下Java代码实现一个简单绘图工具,绘制不同形状以及不同颜色的图形。部分接口、类及其关系如图5-1所示。 【Java代码】 interface?DrawCircle?{? //绘制圆形 public(1) ;}class?RedCircle?implements?DrawCircle?{? ?//绘制红色圆形???????public?void?drawCircle(int?radius,intx,?int?y)??{????????????System.out.println("Drawing?Circle[red,radius:"?+?radius?+",x:"?+?x?+?",y:"?+y+?"]");???????}}class?GreenCircle?implements?DrawCircle?{????//绘制绿色圆形??????public?void?drawCircle(int?radius,?int?x,int?y)?{???????????System.out.println("Drawing?Circle[green,radius:"?+radius+",x:?"?+x+?",y:?"?+y+?"]");??????}}abstract?class?Shape?{????//形状? protected? ? (2)???;? ? public?Shape(DrawCircle?drawCircle)?{? ?this.drawCircle=?drawCircle;? ? ? public?abstract?void?draw();}class?Circle?extends?Shape?{? //圆形? ?private?int?x,y,radius;? public?Circle(int?x,int?y,intradius,DrawCircle?drawCircle)?{? ?(3)???;? this.x?=?x;? ? ? this.y?=?y;? ?this.radius?=radius;? }? ? ?public?void?draw()?{? ? drawCircle.? ?(4)? ?;? ? ? }}public?class?DrawCircleMain?{? public?static?void?main(String[]?args)?{? Shape?redCircle=new?Circle(?100,100,10,? (5) );//绘制红色圆形? Shape?greenCircle=new?Circle(200,200,10,(6) );//绘制绿色圆形? ?redCircle.draw(); greenCircle.draw();? ?}}

考题 在Java语言中,如果你有下面的类定义:  Abstract class Shape{ Abstract void draw(); }  class Square extendeds Shape{} 如果你试图编译上面的代码会发生()。 A、一切成功编译B、Shape可以编译,Square不能编译C、Square可以编译,Shape不能编译D、Shape,Square都不能编译

考题 Which three demonstrate an “is a” relationship?() A、 public class X { }  public class Y extends X { }B、 public interface Shape { }  public interface Rectangle extends Shape{ }C、 public interface Color { }  public class Shape { private Color color; }D、 public interface Species { }  public class Animal { private Species species; }E、 public class Person { } public class Employee {  public Employee(Person person) { }F、 interface Component { }  class Container implements Component { private Component[] children; }

考题 Which the two demonstrate an “is a” relationship?()A、 public interface Person {}  Public class Employee extends Person {}B、 public interface Shape {}  public interface Rectangle extends Shape {}C、 public interface Color {}  public class Shape { private Color color; }D、 public class Species {}  public class Animal { private Species species; }E、 interface Component {} Class Container implements Component {private Component [] children;

考题 Which two demonstrate an “is a” relationship?()   A、 public interface Person { }  public class Employee extends Person { }B、 public interface Shape { }  public class Employee extends Shape { }C、 public interface Color { }  public class Employee extends Color { }D、 public class Species { }  public class Animal (private Species species;)E、 interface Component { }  Class Container implements Component ( Private Component[ ]children;  )

考题 public abstract class Shape {  private int x;  private int y;  public abstract void draw();  public void setAnchor(int x, int y) {  this.x = x;  this.y = y;  }  }  Which two classes use the Shape class correctly?()A、 public class Circle implements Shape { private int radius; }B、 public abstract class Circle extends Shape { private int radius; }C、 public class Circle extends Shape { private int radius; public void draw(); }D、 public abstract class Circle implements Shape { private int radius; public void draw(); }E、 public class Circle extends Shape { private int radius;public void draw() {/* code here */} }F、 public abstract class Circle implements Shape { private int radius;public void draw() { / code here */ } }

考题 单选题在Java语言中,如果你有下面的类定义:   abstract class Shape {  abstract void draw();    }    Class Square extends Shape {}  如果你试图编译上面的代码会发生()。A 一切成功编译B Shape可以编译,Square不能编译C Square可以编译,Shape不能编译D Shape,Square都不能编译

考题 多选题Which three demonstrate an “is a” relationship?()Apublic class X { }  public class Y extends X { }Bpublic interface Shape { }  public interface Rectangle extends Shape{ }Cpublic interface Color { }  public class Shape { private Color color; }Dpublic interface Species { }  public class Animal { private Species species; }Epublic class Person { } public class Employee {  public Employee(Person person) { }Finterface Component { }  class Container implements Component { private Component[] children; }

考题 多选题public abstract class Shape {  private int x;  private int y;  public abstract void draw();  public void setAnchor(int x, int y) {  this.x = x;  this.y = y;  }  }  Which two classes use the Shape class correctly?()Apublic class Circle implements Shape { private int radius; }Bpublic abstract class Circle extends Shape { private int radius; }Cpublic class Circle extends Shape { private int radius; public void draw(); }Dpublic abstract class Circle implements Shape { private int radius; public void draw(); }Epublic class Circle extends Shape { private int radius;public void draw() {/* code here */} }Fpublic abstract class Circle implements Shape { private int radius;public void draw() { / code here */ } }

考题 多选题Which two demonstrate an “is a” relationship?()Apublic interface Person { }  public class Employee extends Person { }Bpublic interface Shape { }  public class Employee extends Shape { }Cpublic interface Color { }  public class Employee extends Color { }Dpublic class Species { }  public class Animal (private Species species;)Einterface Component { }  Class Container implements Component ( Private Component[ ]children;  )

考题 单选题public abstract class Shape {  int x;  int y;  public abstract void draw();  public void setAnchor(int x, int y) {  this.x = x;  this.y = y;  }  }  and a class Circle that extends and fully implements the Shape class. Which is correct?()A  Shape s = new Shape(); s.setAnchor(10,10); s.draw();B  Circle c = new Shape(); c.setAnchor(10,10); c.draw();C  Shape s = new Circle(); s.setAnchor(10,10); s.draw();D  Shape s = new Circle(); s-setAnchor(10,10); s-draw();E  Circle c = new Circle(); c.Shape.setAnchor(10,10); c.Shape.draw();

考题 多选题Which the two demonstrate an “is a” relationship?()Apublic interface Person {}  Public class Employee extends Person {}Bpublic interface Shape {}  public interface Rectangle extends Shape {}Cpublic interface Color {}  public class Shape { private Color color; }Dpublic class Species {}  public class Animal { private Species species; }Einterface Component {} Class Container implements Component {private Component [] children;

考题 单选题下列程序的运行结果是(  )。class Shape{ public Shape(){ System.out.print("Shape"); }}class Circle extends Shape{ public Circle(){ System.out.print("Circle"); }}public class Test{ public static void main(String[]args){ Shape d=new Circle(); }}A ShapeB CircleC ShapeCircleD 程序有错误