Double full astern.()
第1题:
编写求两个双精度数之和的函数,选项中正确的是
A.double add(double a,double b)
{double s;
s=a+b;
return s; }
B.double add(double a,b)
{double s;
s=a+b;
return (s);}
C.double add(double a double b)
{double s;
s=a+b;
returns;}
D.double add(a,b)
{double a,b,s;
s=a+b;
return (s);}
第2题:
My ship’s engine responds well to telegraph orders and takes about 80 seconds to reverse from full speed ahead to full speed astern. This sentence ______.
A.indicates the engine’s particulars
B.tells the engine’s function
C.shows the engine’s type
D.refers to the engine’s information
第3题:
以下选项中正确的定义语句是
A)double a;b;
B)double a=b=7;
C)double a=7,b=7;
D)double,a,b;
第4题:
以下选项中正确的定义语句是______。
A.double a;b;
B.double.a=b=7;
C.double a=7,b=7;
D.double,a,b;
第5题:
Double full astern.
A.全速后退。
B.再后退三。
C.半速后退。
D.后退三。
第6题:
●试题五
阅读下列程序说明和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(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;
}
●试题五
【答案】(1)void move(double ax, double ay){x += ax;y += ay;};
(2)CPosition::CPosition()(3)return sqrt(pow(x-bx, 2) + pow(y-by, 2));
【解析】本题主要考查考生对于类的定义和重载构造函数的掌握情况。在(3)中使用了基本的数学函数sqrt(x)求x的开方,pow(x,n)函数是求x的n次方。
第7题:
紧急后退三。
A.Full astern!
B.Double full astern!
C.Emergency full astern!
D.Emergency three astern!
第8题:
若程序中定义了以下函数:double myadd(double a,double b){ return(a+b);}并将其放在调用语句之后,则在调用之前应该对该函数进行说明,以下选项中错误的说明是( )。A.double myadd(double a, b)B.double myadd(double ,double )C.double myadd(double b,double a)D.double myadd(double x,double y)
第9题:
下列程序的执行结果为【 】。
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)
}
第10题:
有以下程序: #include<iostream> #include<math> using namespace std; class point { private: double x; double y; public: point(double a,double B) { x=a; y=b; } friend double distance (point a,point B) ;
A.1
B.5
C.4
D.6