二级C++-99
(总分100,考试时间90分钟)
一、选择题
1. 已知函数fun的原型为
int fun(int,int,int);
下列重载函数原型中错误的是______。
A. char fun(int,int);
B. double fun(int,int,double);
C. int fun(int,char*);
D. float fun(int,int,int);
2. 下列关于函数重载的叙述中,错误的是______。
A. 重载函数的参数个数可以不同 B. 重载函数的参数类型可以不同
C. 重载函数的返回值类型必须不同 D. 重载函数的参数个数或参数类型必须有所不同
3. 下列有关内联函数的叙述中,正确的是______。
A. 内联函数在调用时发生控制转移
B. 内联函数必须通过关键字inline来定义
C. 内联函数是通过编译器来实现的
D. 内联函数函数体的最后一条语句必须是return语句
4. 为了取代C中带参数的宏,在C++中使用______。
A. 重载函数 B. 内联函数
C. 递归函数 D. 友元函数
5. 为了提高函数调用的实际运行速度,可以将较简单的函数定义为______。
A. 内联函数 B. 重载函数
C. 递归函数 D. 函数模板
6. 计算斐波那契数列第n项的函数定义如下:
int fib(int n){
if(n==0) return 1;
else if(n==1) return 2;
else return fib(n-1)+fib(n-2);
}
若执行函数调用表达式fib(2),函数fib被调用的次数是______。
A. 1 B. 2
C. 3 D. 4
7. 有如下类声明:
class Foo{ int bar;};
则Foo类的成员bar是______。
A. 公有数据成员 B. 公有成员函数
C. 私有数据成员 D. 私有成员函数
8. 有如下类定义:
class Foo
{
public:
Foo(int v):value(v){} //①
~Foo(){} //②
private:
Foo(){} //③
int value=0; //④
};
其中存在语法错误的行是______。
A. ① B. ②
C. ③ D. ④
9. 有如下类定义:
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;
constint c;
};
int Test::b=0;
在标注号码的行中,能被正确编译的是______。
A. ① B. ②
C. ③ D. ④
10. 有如下类声明:
class SAMPLE
{
int n;
public:
SAMPLE(int i=0):n(i){}
void setValue(int n0);
cstring转为int };
下列关于getValue成员函数的实现中,正确的是______。
A. SAMPLE::setValue(int.n0){n=n0;}
B. void SAMPLE::setValue(int n0){n=n0;}
C. void setValue(int n0){n=n0;}
D. (int n0){n=n0;}
11. 以下关键字不能用来声明类的访问权限的是______。
A. public B. static
C. protected D. private
12. 下列关于类定义的说法中,正确的是______。
A. 类定义中包括数据成员和函数成员的声明 B. 类成员的缺省访问权限是保护的
C. 数据成员必须被声明为私有的 D. 成员函数只能在类体外进行定义
13. 如果派生类以protected方式继承基类,则原基类的protected成员和public成员在派生类中的访问属性分别是______。
A. public和public
B. public和protected
C. protected和public
D. protected和protected
14. 下列有关类成员的叙述中,正确的是______。
A. 友元函数是类的成员函数 B. 类成员的默认访问权限是私有的
C. 类成员函数必须声明为公有的 D. 类的静态数据成员不能是常成员
15. 下列运算符函数中,肯定不属于类Value的成员函数的是______。
A. Value operator+(Value);
B. Value operator-(Value,Value);
C. Value operator*(int);
D. Value operator/(Value);
16. 有如下程序:
#include<iostream>
#include<cstring>
using namespace std;
class XCD{
char* a;
int b;
public:
XCD(char* aa,int bb){
a=new char[strlen(aa)+1];
strcpy(a,aa);
b=bb;
}
char* Geta(){return a;}
int Getb(){return b;}
};
intmain(){
char*p1="abcd",*p2="weirong";
int d1=6,d2=8;
XCD x(p1,d1),y(p2,d2);
cout<<strlen(x.Geta())+y.Getb()<<endl;
return 0;
}
运行时的输出结果是______。
A. 12 B. 16
C. 14 D. 11
17. 有如下两个类定义:
class AA{};
class BB{
AA v1,*v2;
BB v3;
int*v4;
};
其中有一个成员变量的定义是错误的,这个变量是______。
A. v1 B. v2
C. v3 D. v4
18. 有如下程序:
#include<iostream>
using namespace std;
class Point{
int x,y;
public:
Point(int x1=0,int y1=0):x(x1),y(y1){}
int get(){return x+y;)
};
class Circle{
Point cente;
int radius;
public:
Circle(int cx,int cy,int r):center(cx,cy),radius(r){}
int get(){()+radius;}
};
int main(){
Circle c(3,4,5);
cout<<c.get()<<endl;
return 0;
}
运行时的输出结果是______。
A. 5 B. 7
C. 9 D. 12
19. 若AA为一个类,a为该类的私有整型数据成员,getA()为该类的一个非静态公有成员函数,功能是返回a的值。如果x为该类的一个对象,要在类外访问x对象中a的值,正确的访问格式为______。
A. AA.getA() B. x.getA()
C. x.a D. AA::a
20. 有如下类定义:
class MyClass{
int b;char a;double c;
public:
MyClass():c(0.0),b(0),a(","){}
};
创建这个类的对象时,数据成员的初始化顺序是______。
A. a,b,c B. c,b,a
C. b,a,c D. c,a,b
21. 下列关于类和对象的叙述中,错误的是______。
A. 一个类只能有一个对象 B. 对象是类的具体实例
C. 类是对某一类对象的抽象 D. 类和对象的关系是一种数据类型与变量的关系
22. 若有如下类声明
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论