等级考试 百分网手机站

2011年9月计算机等级考试二级C++(2)

时间:2018-04-21 等级考试 我要投稿

  (30)有如下程序?

  class Base{

  public:

  int data;

  };

  class Derived1:public Base{};

  class Derived2:protected Base{};

  int main(){

  Derived1 d1;

  Derived2 d2;

  d1. data=0; //①

  d2. data=0; //②

  return 0;

  }

  下列关于程序编译结果的描述中?正确的是( )。

  A) ①②皆无编译错误 B) ①有编译错误?②无编译错误

  C) ①无编译错误?②有编译错误 D) ①②皆有编译错误

  (31)有如下程序?

  #include?iostream?

  using namespace std;

  class Base1{

  public:

  Base1(int

  D) {cout??d;}

  ~Base1(){}

  };

  class Base2{

  public:

  Base2(int D) {cout??d;}

  ~Base2 (){}

  };

  class Derived:public Base1, Base2{

  public:

  Derived(int a, int b, int c, int D) ;

  Base1(B) , Base2(A) , b1(D) , b2(C) {}

  Private:

  int b1; www.docin.comint b2;

  };

  int main(){

  Derived d(1, 2, 3, 4);

  return 0;

  }

  运行时的输出结果是( )。

  A) 1234 B) 2134 C) 12 D) 21

  (32)有如下程序?

  #include?iostream?

  using namespace std;

  class Base{

  public:

  virtual void function1(){cout??'0';}

  void function2(){cout??'1';}

  };

  class Derived:public Base{

  public:

  void function1(){cout??'2';}

  void function2(){cout??'3';}

  };

  int main(){

  Base*P=new Derived();

  p-?function1()?

  p-?function2()?

  return 0;

  };

  运行时的输出结果是( )。

  A) O1 B) 21 C) 03 D) 23

  (33)若为Fraction类重载前增1运算符++?应在类体中将其声明为( )。

  A) Fraction& operator++();

  B) Fraction& operator++(int)?

  C) friend Fraction& operator++();

  D) friend Fraction& operator++(int);

  (34)有如下程序?

  #include?iomanip?

  #include?iostream?

  using namespace std;

  int main(){

  cout??setfill('*')??setw(6)??123??456;

  return 0;

  }

  运行时的输出结果是( )。

  A) ***123***456 B) ***123456*** www.docin.comC) ***123456 D) 123456

  (35)有如下程序?

  #include?iostream?

  using namespace std;

  void function2(int n);

  void function1(int n){

  if(n?=0)retum;

  function2(n-2);

  }

  void function2(int n){

  if(n?

  =0)return;

  function1(n-1);

  }

  int main(){

  function1(5);

  return 0;

  }

  下列关于程序运行情况的描述中?正确的是( )。

  A) function1运行1次?function2运行2次

  B) function1运行2次?function2运行1次

  C) function1运行2次?function2运行3次

  D) function1运行2次?function2运行2次

  二、填空题

  (1)数据结构分为线性结构与非线性结构?带链的栈属于______。

  (2)在长度为n的顺序存储的线性表中插入一个元素?最坏情况下需要移动表中

  ______个元素。

  (3)常见的软件开发方法有结构化方法和面向对象方法。对某应用系统经过需求

  分析建立数据流图(DFD) ?则应采用______方法。

  (4)数据库系统的核心是______。

  (5)在进行关系数据库的逻辑设计时?E-R图中的属性常被转换为关系中的属

  性?联系通常被转换为______。

  (6)若有“intx=15, y=20;”?则执行表达式y-=x++后?表达式x+y的值为

  ______。

  (7)执行语句序列“int k=0; do k++; while(k*k?20);”后?k的值为

  ______。

  (8)下列程序运行时的输出结果是______。

  #include?iostream?

  using namespace std;

  int Xfun(int*a, int n);

  int main()

  int b[6]={-2, 6, 8, -3, 5, 4);

  cout??Xfun(b, 6)??end1;

  return 0;

  } www.docin.comint Xfun(int*a, int n){

  int x=0;

  for(int*p=a; p?a+n; p++)if(*p?0)x+=*p;

  return X;

  }

  (9)下列程序运行时的输出结果是______。

  #include?iostream?

  using namespace std;

  void Xfun(int&, int&);

  int main(){

  int a=3, b=4;

  Xfun(a, B) ;

  cout??a*a+b??end1;

  return 0;

  }

  void Xfun(int& x, int& y){

  int z=x;

  x=y; y=z;

  }

  (10)若Xcs是一个类?该类中具有一个函数体为空的不带参数的构造函数?此

  构造函数的类外定义为______。

  (11)有如下程序?

  #include?iostream?

  using namespace std;

  class Sac{

  int n;

  public:

  Sac():n(4){cout??n;}

  Sac(int k):n(k){cout??n;}

  ~Sac(){cont??n+n;}

  };

  int main(){

  Sac s1,*s2;

  s2=new Sac(3);

  delete s2;

  return 0;

  }
以上是考试频道小编为你收集整理2011年9月计算机等级考试二级笔试C++语言程序设计。