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

 

(21)有如下程序:
#include
using namespace std;
int main()
{
void function(double val);
double val;
function(val);
cout<
return 0;
}
void function(double val)
{
val = 3;
}
编译运行这个程序将出现的情况是
A.编译出错,无法运行
B.输出:3
C.输出:3.0
D.输出一个不确定的数
(22)有如下类定义:
class AA
{
int a;
public:
int getRef() const{return &a;} //①
int getvalue() const{return a;} //②
void set(int n) const{a=n;} //③
friend void show(AA aa) const {cout< //④
};
其中的四个函数定义中正确的是
A.①
B.②
C.③
D.④
(23)有如下程序:
#include +
using namespace std;
#include
using namespace std;
class Base
{
public:
void fun(){cout<<"Base::fun"<
};
class Derived:public Base
{
public:
void fun()
{
cout<<"Derived::fun"<
}
};
int main()
{
Derived d;
d.fun();
return 0;
}
已知其执行后的输出结果为:
Base::fun
Derived::fun
则程序中下划线处应填入的语句是
A.Base.fun();
B.Base::fun()
C.Base->fun()
D.fun();
(24)下面是重载为非成员函数的运算符函数原型,其中错误的是
A.Fraction operator + (Fraction, Fraction);
B.Fraction operator - (Fraction);
C.Fraction& operator = (Fraction&, Fraction);
D.Fraction& operator += (Fraction&, Fraction);
(25)有如下函数模板:
template
T cast(U u){return u;}
其功能是将U类型数据转换为T类型数据。已知i为int型变量,下列对模板函数cast的调用中正确的是
A.cast(i);
B.cast<>(i);
C.cast(i);
D.cast (i);
(26)若磁盘上已存在某个文本文件,其全路径文件名为d:\ncre\test.txt,下列语句中不 能打开该文件的是
A.ifstream file("d:\ncre\test.txt");
B.ifstream file("d:\ncre\test.txt");
C.ifstream file; file.open("d:\ncre\test.txt");
D.ifstream* pFile=new ifstream("d:\ncre\test.txt");
(27)有如下类定义:
class Foo
{
public:
Foo(int v):value(v){} //①
~Foo(){} //②
private:
Foo(){} //③
int value = 0; //④
};
其中存在语法错误的行是
A.①
B.②
C.③
D.④
(28)有如下类定义:
class Point
{
int x_, y_;
public:
Point():x_(0), y_(0){}
Point(int x, int y = 0):x_(x),y_(y){}
};
若执行语句
Point a(2), b[3], *c[4];
则Point类的构造函数被调用的次数是
A.2次
B.3次
C.4次
D.5次
(29)有如下类定义:
class Test
{
public:
Test(){ a = 0; c = 0;} //①
int f(int a)const{this->a = a;} //②
static int g(){return a;} //③
void h(int
B.{Test::b = b;}; //④
private:
int a;
static int b;
const int c;
};
int Test::b = 0;
在标注号码的行中,能被正确编译的是
A.①
B.②
C.③
D.④
(30)有如下程序:
#include
using namespace std;
class A
{
public:
A(){cout<<"A";}
~A(){cout<<"~A";}
};
class B:public A
{
A* p;
public:
B(){cout<<"B"; p = new A();}
~B(){cout<<"~B"; delete p;}
};
int main()
{
B obj;
return 0;
}
执行这个程序的输出结果是
A.BAA~A~B~A
B.ABA~B~A~A
C.BAA~B~A~A
D.ABA~A~B~A

上一页  [1] [2] [3] [4] [5] 下一页

责任编辑:cyth

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