2007年4月全国计算机等级考试二级C++笔试试题及答案(2)
来源:优易学  2010-1-14 16:51:33   【优易学:中国教育考试门户网】   资料下载   IT书店

(21)有如下函数定义:
  void func (int a,int&b) {a++; b++;}
  若执行代码段:
  int x=0 ,y=1
  func(x,y);
  则变量x和y值分别是
  A)0和1  
  B)1和1
  C)0和2
  D)1和2

(22)有如下程序:
  #include
  using namespace std;
  class A{
  public
  static int a;
  void init(){a=1;}
  A(int a=2) {init();a++;}
  };
  int A:;a=0
  A obj;
  Int main()
  {
  cout<  retum0;
  }
  运行时输出的结果是
  A)0
  B)1
  C)2
  D)3

(23)下列有关继承和派生的叙述中,正确的是
  A) 派生类不能访问基类的保护成员
  B)作为虚基类的类不能被实例化
  C)派生类应当向基类的构造函数传递参数
  D)虚函数必须在派生类中重新实现

(24)下列运算符中,不能被重载的是
  A)&&
  B)!=
  C).
  D)++

(25)下列函数模板的定义中,合法的是
  A) template Tabs(T x) {return x <0 – x: x;}
  B)template class Tabs(Tx){retumx<0 -x;x;}
  C)template Tabs(T x){retum x<0 -x;x;}
  D)template T abs(T x){returm x<0 -x;x;}

(26)在语句cin>>data;中,cin是
  A)C++的关键字
  B)类名
  C)对象名
  D)函数名

(27)有如下程序:
  #include
  using namespace std;
  class test {
  private:
  int a;
  public:
  test(){cout<<”constructor”<  test(int a){cout<  test(const test&_test)
  {
  a=_testa;
  cout<<”copy constructor”<  }
  test(){cout<<”destructor”<  };
  int main()
  }
  test A(3)
  return0;
 运行时输出的结果是
  A)3
  B)constructor
  destruclor
  C)copy constructor
  D)3
  dstructor destruclor

(28)若有如下类声明
  class My Class {
  public:
  MyClass() {cout<<1;}
  };
  执行下列语句
  MyClass a,b[2],*P[2];
  以后,程序的输出结果是
  A)11
  B)111
  C)1111
  D11111

(29)有如下程序:
  #include
  using namespace std;
  class point {
  public:
  static int number;
  public:
  point(){number++;
  ~point(){number-;}
  };
  imt point::number=0;
  void main(){
  point*ptr;
  printA,B;
  {
  point*ptr_point=new point{3};
  ptr=ptr_point;
  }
  pointC;
  cout<  delete[]ptr;
  }
  运行时输出的结果是
  A)3
  B)4
  C)6
  D)7

(30)如果不使用多态机制,那么通过基类的指针虽然可以指向派生类对象,但是只能访问从基类继承的成员,有如下程序,没有使用多态机制。
  #include
  using namespace std;
  class Base{
  int a,b;
  public:
  Bace(int x ,int y) { a=x; b=y;}
  Void show(){ cout<  }
  clsaa Derived:public Base {
  int c ,d;
  public:
  Derived(int x,int y,int z,int m):Base(x,y){c=z; d=m;}
  Void show(){ cout<  };
  int main()
  {
  Base B1(50,50),*pb;
  Derived DI(10,20,30,40);
  Pb=&D1;
  Pb->show();
  Return 0;
  }
  运行时输出的结果是
  A)10,20
  B)30,40
  C)20,30
  D)50,50

[1] [2] 下一页

责任编辑:cyth

文章搜索:
 相关文章
热点资讯
资讯快报
热门课程培训