网友您好, 请在下方输入框内输入要搜索的题目:
题目内容
(请给出正确答案)
172、已知Circle类定义如下所示,则下列说法正确的是()。 class Circle { public: double m_x,m_y; double m_radius; void setCenter(double x,double y) { m_x=x; m_y=y; } void setRadius(double radius) { m_radius=radius; } double getArea() { return 3.14 * m_radius * m_radius; } };
A.m_x、m_y和m_radius都是Circle类的成员变量
B.setCenter、setRadius和getArea都是Circle类的成员函数
C.类定义体后面的分号可以省略
D.将double m_radius;改为double m_radius=1;,则表示m_radius成员变量的初值为1
参考答案和解析
m_x、m_y和m_radius都是Circle类的成员变量;setCenter、setRadius和getArea都是Circle类的成员函数
更多 “172、已知Circle类定义如下所示,则下列说法正确的是()。 class Circle { public: double m_x,m_y; double m_radius; void setCenter(double x,double y) { m_x=x; m_y=y; } void setRadius(double radius) { m_radius=radius; } double getArea() { return 3.14 * m_radius * m_radius; } };A.m_x、m_y和m_radius都是Circle类的成员变量B.setCenter、setRadius和getArea都是Circle类的成员函数C.类定义体后面的分号可以省略D.将double m_radius;改为double m_radius=1;,则表示m_radius成员变量的初值为1” 相关考题
考题
阅读下列Java程序和程序说明,将应填入(n)处的字句写在对应栏内。【说明】下面的程序先构造Point类,再顺序构造Ball类。由于在类Ball中不能直接存取类Point中的xCoordinate及yCoordinate属性值,Ball中的toString方法调用Point类中的toString方法输出中心点的值。在MovingBall类的toString方法中,super.toString调用父类Ball的toString方法输出类Ball中声明的属性值。public class Point{private double xCoordinate;private double yCoordinate;public Point 0 }public Point(ouble x, double y){xCoordinate = x;yCoordinate = y;}public String toString(){return "( + Double.toString(Coordinate)+ ","+ Double.toString(Coordinate) + ");}//other methods}public class Ball{(1); //中心点private double radius; //半径private String colour; ///颜色public Ball() { }public Ball(double xValue, double yValue, double r)// 具有中心点及半径的构造方法{center=(2);//调用类Point 中的构造方法radius = r;}public Ball(double xValue, double yValue, double r, String c)// 具有中心点、半径及颜色的构造方法{(3);//调用3个参数的构造方法colour = c;}public String toString(){return "A ball with center" + center, toString() + ", radius"+ Double.toString(radius) + ", colour" + colour;}//other methods}public class MovingBall. (4){private double speed;public MovingBall() { }public MovingBall(double xValue, double yValue, double r, String e, double s){(5);// 调用父类Ball中具有4个参数的构造方法speed = s;}public String toString( ){ return super, toString( ) + ", speed "+ Double.toString(speed); }//other methods}public class Tester{public static void main(String args[]){MovingBall mb = new MovingBall(10,20,40,"green",25);System.out.println(mb);}}
考题
●试题五阅读下列程序说明和C++代码,将应填入(n)处的字句写在答卷的对应栏内。【说明】①在类体中添加函数move(double ax, double ay)的定义,使得点的坐标x和y分别移动ax和ay个单位。②在类定义外完成重载的两个构造函数CPosition()和CPosition(double dx, double dy),其中前者为不带参数的构造函数,使CPosition对象的默认值为x=0,y=0,后者为带参数的构造函数,把数据成员x和y分别初始化为参数dx和dy的值。③完成函数double distance(double bx, double by)的定义,该函数返回*this和点(bx,by)的距离。注意:除在指定的位置添加语句外,请不要改动程序中的其他语句。源程序文件test5.cpp清单如下:#includeiostream.h#include math.hclass CPosition{public:CPosition();CPosition(double dx, double dy);double getx();double gety();(1)double distance(double bx, double by);private:double x;double y;};(2){x=0; y=0;}CPosition::CPosition(double dx, double dy){x=dx; y=dy;}double CPosition::getx(){return x;}double CPosition::gety(){return y;}double CPosition::distance(double bx, double by){(3)}void main(){double a,b;cout "Input x, y position of a point: ";cin a b;CPosition psA(a, b);cout "Input x, y position of another point: ";cin a b;cout "The distance is " psA.distance(a,b) endl;}
考题
( 13 )有如下复数类的声明,请补充完整。class complex{double real; // 实部double imag; // 虚部public:complex(double x , double y){real=x;imag=y;}perator+(complex c){// 重载加法运算符 “ + ”return complex(___________)}};
考题
( 13 )补充完整下面的类定义:const double PI=3 .14;class Circle{ // 圆形物体的抽象基类protected:double r; // 半径public:Circle ( double radius=0 ) : r ( radius ) {}【 13 】 ; // 计算圆形物体表面积的纯虚函数声明};class Cylinder:public Circle { // 圆柱体类double h; // 高度public:Cylindr ( double radius=0, doubli height=0 ) :Circle ( radius ) , h ( height ) {}Virtual double Area () { // 计算圆柱体的表面积return 2*PI*r* ( r+h ) ;}};
考题
( 23 )有如下两个类定义class XX{private:double x1;protected:double x2;public:double x3;};class YY:protected XX{private:double y1;protected:double y2;public:double y3;};在类 YY 中保护成员变量的个数是A ) 1B ) 2C ) 3D ) 4
考题
下面程序的输出结果是【】。include include class point{double x; double y;
下面程序的输出结果是【 】。include <iostream.h>include <math.h>class point{double x;double y;public:point(double a, double b){x=a;y=b;}friend double distance(point a, point b) ;};double distance(point a, point b){return sqrt ((a. x-b.x) * (a. x-b.x)+ (a. y-b. y) * (a. y-b. y) );}void main(){point p1(1,2);point p2(5,2);cout<<distance(p1,p2)<<end1;}
考题
阅读下列程序说明和C++代码,将应填入(n)处。【说明】①在类体中添加函数move(double ax,double ay)的定义,使得点的坐标x和y分别移动 ax和ay个单位。②在类定义外完成重载的两个构造函数CPosition()和CPosition(double dx,double dy),其中前者为不带参数的构造函数,使CPosition对象的默认值为x=0,y=0,后者为带参数的构造函数,把数据成员x和y分别初始化为参数dx和dy的值。③完成函数double distance(double bx,double by)的定义,该函数返回*this和点(bx, by)的距离。注意:除在指定的位置添加语句外,请不要改动程序中的其他语句。源程序文件test5.cpp清单如下:include<iostream.h>include<math.h>class CPosition{public:CPosition();CPosition(double dx,double dy);double getx();double gety();(1)double distance(double bx,double by);private:double x;double y;};(2){x=0;y=0;}CPosition::CPosition(doub,e dx,doub,e dy){x=dx; y=dy;}double CPosition::getx(){return x;}double CPosition::gety(){return y;}double CPosition::distance(double bx,double by){(3)}vold main(){double a,b;cout<<"|nput x,y position of a point:";cin >> a >> b;CPosition psA(a,b);cout<<"Input x,y position of another point:";cin >>a >> b;cout <<"The distance is" <<psA.distance(a,b) <<end1;}
考题
阅读下列C++程序和程序说明,将应填入(n)处的字句写在对应栏内。【说明】Point是平面坐标系上的点类,Line是从Point派生出来的直线类。include <iostream.h>class Point{public:Point (int x, int y) ;Point (Point p) ;~Point();void set (double x, double y) ;void print();private:double X,Y;};Point::Point (int x, int y) //Point 构造函数{X=x; Y=y; }Point::Point ( (1) ) //Point 拷贝构造函数{X=p.X; Y=p.Y;}void Point::set (double x, double y){X=x; Y=y; }void Point::print(){cout<<' ('<<X<<","<<Y<<") "<<endl; }Point::~Point(){cout<<"Point 的析构函数被调用! "<<endl;class Line: public Point{public:Line (int x, int y, int k) ;Line (Line s) ;~Line();void set (double x, double y, double k)void print();private:double K;};(2)//Line 构造函数实现{ K=k;}(3)//Line 拷贝构造函数实现{K=s.K;}void Line::set (double x, double y, double k){ (4);K=k;}void Line::print(){cout<<" 直线经过点";(5);cout<<"斜率为: k="<<K<<endl;}Line: :~Line(){cout<<"Line 析构函数被调用! "<<endl;}void main(){Line 11 (1,1,2) ;11 .print();Linel2 (11) ;12.set (3,2,1) ;12.print();}
考题
阅读以下函数说明和Java代码,将应填入(n)处的字句写在对应栏内。【说明】现要编写一个画矩形的程序,目前有两个画图程序:DP1和DP2,DP1用函数draw_a_line(x1,y1,x2,y2)画一条直线,DP2则用drawline(x1,x2,y1,y2)画一条直线。当实例画矩形时,确定使用DP1还是DP2。为了适应变化,包括“不同类型的形状”和“不同类型的画图程序”,将抽象部分与实现部分分离,使它们可以独立地变化。这里,“抽象部分”对应“形状”,“实现部分”对应“画图”,与一般的接口(抽象方法)与具体实现不同。这种应用称为Bridge(桥接)模式。图9-6显示了各个类间的关系。这样,系统始终只处理3个对象:Shape对象、Drawing对象、DP1或DP2对象。以下是 Java语言实现,能够正确编译通过。【Java代码】//DP1.java文件public class DP1{static public void draw_a line(double x1,double y1,double x2,double y2){//省略具体实现}}//DP2.java文件public class DP2{static public void drawline(double x1,double y1,double x2,double y2){//省略具体实现}}//Drawing.java文件(1) public class Drawing{abstract public void drawLine(double x1, double y1, double x2, double y2);}//V1Drawing.java文件public class V1Drawing extends Drawing{public void drawLine(double x1, double y1, double x2, double y2){DP1.draw_a_line(x1,y1,x2,y2);}}//V2Drawing.java文件public class V2Drawing extends Drawing{public void drawLine(double x1,double y1,double x2, double y2)(//画一条直线(2);}}//Shape.java文件abstract public class Shape{abstract public void draw();private (3) _dp;Shape(Drawing dp){_dp=dp;}protected void drawLine(double x1,double y1,double x2, double y2){(4);}}//Rectangle.java文件public class Rectangle extends Shape{private double_x1,_x2,_y1,_y2;public Rectangle(Drawing dp,double x1,double y1,double x2,double y2){(5);_x1=x1;_x2=x2;_y1=y1;_y2=y2;}public void draw(){//省略具体实现}}
考题
阅读以下函数说明和Java代码,将应填入(n)处的字句写在对应栏内。【说明】下面的程序先构造Point类,再顺序构造Ball类。由于在类Ball中不能直接存取类Point中的xCoordinate及yCoordinate属性值,Ball中的toString方法调用Point类中的toStrinS方法输出中心点的值。在MovingBsll类的toString方法中,super.toString调用父类Ball的toString方法输出类Ball中声明的属性值。【Java代码】//Point.java文件public class Point{private double xCoordinate;private double yCoordinate;public Point(){}public Point(double x,double y){xCoordinate=x;yCoordinate=y;}public String toStrthg(){return"("+Double.toString(xCoordinate)+","+Double.toString(yCoordinate)+")";}//other methods}//Ball.java文件public class Ball{private (1);//中心点private double radius;//半径private String color;//颜色public Ball(){}public Ball(double xValue, double yValue, double r){//具有中心点及其半径的构造方法center=(2);//调用类Point中的构造方法radius=r;}public Ball(double xValue, double yValue, double r, String c){//具有中心点、半径和颜色的构造方法(3);//调用3个参数的构造方法color=c;}public String toString(){return "A ball with center"+center.toString()+",radius "+Double.toString(radius)+",color"+color;}//other methods}class MovingBall (4) {private double speed;public MovingBall(){}public MoyingBall(double xValue, double yValue, double r, String c, double s){(5);//调用父类Ball中具有4个参数的构造方法speed=s;}public String toString(){return super.toString()+",speed"+Double.toString(speed);}//other methods}public class test{public static void main(String args[]){MovingBall mb=new MovingBall(10,20,40,"green",25);System.out.println(mb);}}
考题
分析以下程序执行结果【】。 include int f (int x, int y){return x,y; } double f (d
分析以下程序执行结果【 】。include<iostream.h>int f (int x, int y){return x,y;}double f (double x, double y) {return x,y;}void main() {int a=4, b=6;double c=2.6, d=7.4;cout<<f (a, b) <<","<<f (c, d) <<end1;}
考题
下列函数中对调用它的函数没有起到任何作用的是______ 。A.void fl(double x){--x;}B.double f2(double x){return x-1.5;}C.void f3(double x){--x;}D.double f4(double *x){--*x;return *x;}
考题
下列函数中,对调用它的函数没有起到任何作用的是( )。A.void f1(double x){--x;}B.double f2(double x){return x-1.5;}C.void f3(double x){--x;}D.double f4(double *x){--*x;return*x;}
考题
阅读以下说明和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)
考题
下列程序的执行结果为【 】。include class Point{public:Point(double i, double j)
下列程序的执行结果为【 】。include <iostream. h>class Point{public:Point(double i, double j) { x=i; y=j;}double Area() const { return 0.0;}private:double x, y;};class Rectangle: public Point{public:Rectangle(double i, double j, double k, double 1)double Area() const {return w * h;}private:double w, h;};Rectangle: :Rectangle(double i, double j, double k. double 1): Point(i,j).{w=k, h=1}void fun(Point s){cout<<s. Area()<<end1;}void main( ){Rectangle rec(3.0, 5.2, 15.0. 25.0);fun(rec)}
考题
使用VC6打开考生文件夹下的工程test11_3。此工程包含一个test11_3.cpp,其中定义了类CPosition,但该类的定义都并不完整。请按要求完成下列操作,将类CPosition的定义补充完整。(1)在类定义外完成重载的两个构造函数CPosition()和CPosition(double dx,double dy),其中前者为不带参数的构造函数,使CPosition对象的默认值为x=0,y=0,后者为带参数的构造函数,把数据成员x和y分别初始化为参数dx和dy的值。请在注释“//**1**”之后添加适当的语句。(2)在类体中添加函数move(double ax,double ay)的定义,使得点的坐标x和y分别移动ax和ay个单位,请在注释“// **2**”之后添加适当的语句。(3)完成函数double distance (double bx,double by)的定义,该函数返回*this和点(bx,by)的距离,请在注释“//**3**”之后添加适当的语句。注意:除在指定的位置添加语句外,请不要改动程序中的其他语句。源程序文件test11_3.cpp清单如下:include<iostream.h>include<math.h>class CPosition{public:CPosition();CPosition(double dx,double dy);double getx();double gety();// ** 2 **double distance(double bx,double by);private:double x;double y;};// ** 1 **{x=0;y=0;}CPosition::CPosition(double dx,double dy){x=dx;y=dy;}double CPosition::getx(){return x;}double CPosition::gety(){return y;}double CPosition::distance(double bx,double by){// ** 3 **}void main(){double a,b;cout << "Input x, y position of a point:";cin >> a >> b;CPosition psA(a,b);cout << “Input x,y position of another point:";cin >> a >> b;cout << "The distance is " << psA.distance(a,b) <<endl;}
考题
在下列方法的定义中,正确的是 ( )A.public double x(){..;return false;}B.public static int x(double y){...}C.void x(doubled){...;return d}D.public static x(double a){..}
考题
阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。【说明】以下程序的功能是计算正方体、球体和圆柱体的表面积和体积并输出。程序由4个类组成:类cube、sphere和cylinder分别表示正方体、球体和圆柱体;抽象类 container为抽象类,提供了两个纯虚拟函数surface_area()和volum(),作为通用接口。【C++程序】include<iostream.h>define pi 3.1416class container{protected:double radius;public:container(double radius) {container::radius=radius;}virtual double surface_area()=0;virtual double velum()=0;};class cube:(1){ //定义正方体类public:cube(double radius):container(radius){};double surface_area () {return 6 * radius * radius;}double volum() {return radius * radius * radius;}};class sphere:(2){ //定义球体类public:sphere(double radius): container(radius){};double surface_area() { return (3);}double volum() {return pi * radius * radius * radius * 4/3;}};class cylinder:(4){ //定义圆柱体类double height;public:cylinder(double radius,double height):container(radius){container::height=height;}double surface_are a () { return 2 * pi * radius * (height+radius); }double volum () {return (5);}};void main(){container * p;cube obj1 (5);sphere obj2(5);cylinder obj3(5,5);p=obj1;cout<<“正方体表面积”(<<p->surface_area()<<end1;cont<<“正方体体积”<<p->volume()<<end1;p=obj2;cout<<“球体表面积”<<p->surface_area()<<end1;cout<<“球体体积”<<p->volume()<<end1;p=obj3;cout<<“球体表面积”<<p->surface_area()<<end1;cout<<“球体体积”<<p->volume()<<end1;}
考题
下列程序中,先声明一个圆类circle和一个桌子类table,另外声明一个圆桌类roundtable,它是由 circle和table两个类派生的,要求声明一个圆桌类对象,并输出圆桌的高度,面积和颜色。请填空完成程序include<iostream.h>include<string.h>class circle{double radius;public:circle(double r){radius=r;}double get_area(){return 3.416*radius*radius;}};class table{double height;public:table(double h)<height=h;}double get_height(){return height;}};class roundtable:public table,public circle{char *color;public:roundtable(double h,double r,char c[]): 【 】 {color=new char[strlen(c) +1];【 】;};char*get_color(){return color;}}:void main(){roundtable rt(0.8,1.0,“白色”);cout<<"圆桌的高:"<<rt. get_height()<<end1;cout<<"圆桌面积:"<<rt.get_area()<<end1;cout<<"圆桌颜色:"<<n.get color()<<end1;}
考题
阅读以下说明和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(){//省略具体实现}
考题
以下程序的输出结果是【】。 include int add(int x,int y) { retum X+y; } dOuble ad
以下程序的输出结果是【 】。include<iostream.h>int add(int x,int y){retum X+y;}dOuble add(dOUble x,double y){return x+y;}void main(){int a=4,b=6;double c=2.6,d=7.4;cout<<add(a,b)<<",”<<add(C,d)<<endl;}
考题
使用VC6打开考生文件夹下的工程test18_1,此工程包含一个源程序文件(est18_1.cpp,但该程序运行有问题,请改正程序中的错误,使程序的输出结果如下:Enter x and y:-4 -5xoffset=1yoffset=1angle=45radius=1.41421源程序文件test18_1.cpp 清单如下:include <iostream.h>include <math.h>class point{public:void set(double ix,double iy){x=ix;y=iy;}double xoffset(){return x;}double yoffset(){return y;}double angle ( ){return (180/3.14159)*atan2(y,x);}/**************** found *******************/inline radius ( ){return sqrt(x*x+y*y);}protected:double x;double y;};void main(){point p;double x,y;cout<<"Enter x and y:\n";cin>>x>>y;p.set(x,y);/**************** found *******************/p.x+=5;p.y+=6;/**************** found *******************/cout<<"xoffset="<<p.xoffset()<<end1;cout<<"yoffset="<<p.yoffset()<<end1;cout<<"angle="<<p.angle()<<end1;cout<<"radius="<<p.radius()<<end1;
考题
有如下两个类定义: class XX{ private: double xl; protected: double x2; public: double x3; }; class YY:protected XX{ private: double yl; protected: double y2; public: double y3; 在类YY中保护成员变量的个数是( )。A.1B.2C.3D.4
考题
阅读以下函数说明和Java代码,[说明]现要编写一个画矩形的程序,目前有两个画图程序:DP1和DP2,DP1用函数draw_a_line(x1,y1,x2,y2)画一条直线,DP2则用drawline(x1,x2,y1,y2)画一条直线。当实例化矩形时,确定使用DPI还是DP2。为了适应变化,包括“不同类型的形状”和“不同类型的画图程序”,将抽象部分与实现部分分离,使它们可以独立地变化。这里,“抽象部分”对应“形状”,“实现部分”对应“画图”,与一般的接口(抽象方法)与具体实现不同。这种应用称为Bridge(桥接)模式。图7-1显示了各个类间的关系。[图7-1]这样,系统始终只处理3个对象:Shape对象、Drawing对象、DP1或DP2对象。以下是JAvA语言实现,能够正确编译通过。[Java代码]//DP1.Java文件public class DPI{static public void draw_a_line(double x1,double y1,double x2,double y2){//省略具体实现}}//DP2.java文件public class DP2{static public void drawline(double x1,double y1,double x2,double y2){//省略具体实现}}//Drawing.java文件(1) public class Drawing{abstract public void drawLine(double x1,double y1,double x2,double y2);}//V1Drawing.java文件public class V1Drawing extends Drawing{public void drawLine(double x1,double y1,double x2,double y2){DP1.draw_a_line(x1,y1,x2,y2);}}//V2Drawing.java文件public class V2Drawing extends Drawing{public void drawLine(double x1,double y1,double x2,double y2){//画一条直线(2);}}//Shape.java文件abstract public class Shape{abstract public void draw();private (3) dp;Shape(Drawing dp){_dp=dp;}protected void drawLine(double x1,double y1,double x2,double y2){(4);}}//Rectangle.java文件public class Rectangle extends Shape{private double_x1,_x2,_y1,_y2;public Rectangle(Drawing dp,double x1,double y1,double x2,double y2){(5);_x1=x1;_x2=x2;_y1=y1;_y2=y2;}public void draw(){//省略具体实现}}(1)
考题
使用VC6打开考生文件夹下的工程RevProj14。此工程包含一个源程序文件RevMain14.cpp,但该程序中类的定义有错误。请改正程序中的错误,使它能得到正确结果。注意,不要改动main函数,不得删行或增行,也不得更改程序的结构。源程序文件RevMain14.cpp中的程序清单如下://RevMain14.cppinclude<iostream>include<math>using namespace std;class Point{private:double x;double y;public:Point(){}void Point(double x1,double y1){x=x1;y=y1;}void setvalue(double x,double y){x=x;y=y;}double getx (){return x;}double gety()}return y;}void print(){cout<<"x="<<x<<",y= "<<y<<end1;}~Point(){}};class Line{private:Point p1;Point p2;double width;public:Line(double x1,double y1,double x2,double y2,double d):p1(x1,y1),p2(x2,y2){width=d;}~Line(){}void displength(){double 1;1=sqrt((p1.getx{)-p2.getx())*(p1.getx()-p2-getx())+(p1.gety()-p2.gety())*(p1.gety()-p2.gety()));cout<<"the length of Line is "<<1<<end1;}};int main(){Line *p1;Line 1(5,15,25,35,0.5);p1=1;p1->displength();return 0;}
考题
已知一个函数的定义如下:double fun(int x,double y){⋯⋯}则该函数正确的函数原型声明为()A、double fun(intx,doubley)B、fun(int x,doubley)C、double fun(int,double);D、fun(x,y);
考题
下列方法定义中,方法头不正确的是()。A、public static x(double a)B、public static int x(double y)C、void x(double d)
考题
单选题public class Mycircle { public double radius; public double diameter; public void setRadius(double radius) this.radius = radius; this.diameter= radius * 2; } public double getRadius() { return radius; } Which statement is true?()A
The Mycircle class is fully encapsulated.B
The diameter of a given MyCircle is guaranteed to be twice its radius.C
Lines 6 and 7 should be in a synchronized block to ensure encapsulation.D
The radius of a MyCircle object can be set without affecting its diameter.
热门标签
最新试卷