2006年4月全国计算机等级考试二级C++语言程序设计笔试试卷

出处:www.examlink.com 作者:小罗 日期:2007年01月22日 16时08分

  (24)下面是重载为非成员函数的运算符函数原型,其中错误的是

  A)Fractionoperator+(Fraction,Fraction);

  B)Fractionoperator-(Fraction);

  C)Fraction&operator=(Fraction&,Fraction);

  D)Fraction&operator+=(Fraction&,Fraction);

  (25)有如下函数模板:

  template

  Tcast(Uu){returnu;}

  其功能是将U类型数据转换为T类型数据。已知i为int型变量,下列对模板函数cast的调用中正确的是

  A)cast(i);B)cast<>(i);

  C)cast(i);D)cast(i);

  (26)若磁盘上已存在某个文本文件,其全路径文件名为d:\ncre\test。txt,下列语句中不能打开该文件的是

  A)ifstreamfile("d:\ncre\test。txt");

  B)ifstreamfile("d:\ncre\test。txt");

  C)ifstreamfile;file。open("d:\ncre\test。txt");

  D)ifstream*pFile=newifstream("d:\ncre\test。txt");

  (27)有如下类定义:

  classFoo

  {

  public:

  Foo(intv):value(v){}//①

  ~Foo(){}//②

  private:

  Foo(){}//③

  intvalue=0;//④

  };

  其中存在语法错误的行是

  A)①B)②C)③D)④

  (28)有如下类定义:

  classPoint

  {

  intx_,y_;

  public:

  Point():x_(0),y_(0){}

  Point(intx,inty=0):x_(x),y_(y){}

  };

  若执行语句

  Pointa(2),b[3],*c[4];

  则Point类的构造函数被调用的次数是

  A)2次B)3次C)4次D)5次

  (29)有如下类定义:

  classTest

  {

  public:

  Test(){a=0;c=0;}//①

  intf(inta)const{this->a=a;}//②

  staticintg(){returna;}//③

  voidh(intb){Test::b=b;};//④

  private:

  inta;

  staticintb;

  constintc;

  };

  intTest::b=0;

  在标注号码的行中,能被正确编译的是

  A)①B)②C)③D)④

  (30)有如下程序:

  #include

  usingnamespacestd;

  classA

  {

  public:

  A(){cout<<"A";}

  ~A(){cout<<"~A";}

  };

  classB:publicA

  {

  A*p;

  public:

  B(){cout<<"B";p=newA();}

  ~B(){cout<<"~B";deletep;}

  };

  intmain()

  {

  Bobj;

  return0;

  }

  执行这个程序的输出结果是

  A)BAA~A~B~AB)ABA~B~A~A

  C)BAA~B~A~AD)ABA~A~B~A

  

最后更新时间:2008-05-28 11:40:20
文章评论
共有 0 位网友发表了评论
用户名: 新注册) 密码: 匿名评论 [查看所有评论]

评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
您可以用以下几种方式找到此文章

考试全流程