2020年全国计算机等级考试二级c++上机题库(3)

0
收藏   分享
  • 卷面总分:100分
  • 试卷类型:模拟考试
  • 测试费用:免费
  • 答案解析:是
  • 练习次数:343次
  • 作答时间:120分钟
试卷简介

2020年全国计算机等级考试二级c++上机题库(3),是针对计算机二级考试中C++的模拟试题。

  • 单选题
  • 操作题
试卷预览
1

使用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;

 }

1

与所使用的计算机无关的是数据的

  • A.物理结构
  • B.逻辑结构
  • C.存储结构
  • D.逻辑和物理结构
5

下列重载函数中,正确的是(  )。

  • A.void fun(int a,float b);void fun(int c,float d)
  • B.void fun(int a,float b);void fun(float a,int b)
  • C.float fun(int a,float b);int fun(int b,float a)
  • D.int fun(int a,int b);float fun(int a,int b)
5

若在表达式y/x中,“/”是作为成员函数重载的运算符,则该表达式还可以表示为

  • A.x.operator/(y)
  • B.operator/(x,y)
  • C.y.operator/(x)
  • D.operator/(y,x)
5

语句int*P=&k;定义了指针P,与这个语句等效的语句序列是(   )。

  • A.int* p;P=&k;
  • B.int * P;P=k;
  • C.int * p;* P=&k;
  • D.int * p;* P=k;
5

下列对字符数组进行初始化中,(  )是正确的。

  • A.char s1[]="abcd";
  • B.char s2[3]="xyz";
  • C.char s3[][]={"a","x", "y");
  • D.char s4 [2][3]={"xyz", "rnnp"};