一、单项选择题 ( 本大题共 10 小题,每小题 2 分,共 20 分 ) 在每小题列出的四个选项中只有一个选项是符合题目要求的,请将其代码填在题后的括号内。错选或未选均无分。
1. 在 C++ 中,函数原型不能标识 ( )
A. 函数的返回类型 B. 函数参数的个数
C. 函数参数类型 D. 函数的功能
2. 在 C++ 程序中,对象之间的相互通信通过 ( )
A. 继承实现 B. 调用成员函数实现
C. 封装实现 D. 函数重载实现
3. 对于任意一个类,析构函数的个数最多为 ( )
A.0 B.1 C.2 D.3
4. 下面函数模板定义中不正确的是( )
A.template B.template
QF(Qx){ QF(Qx){
return Q+x; return x+x;
} }
C.template D.template
TF(Tx){ TF(Tx){
return x*x; return x>1;
} }
5. 友元关系不能 ( )
A. 继承
B. 是类与类的关系
C. 是一个类的成员函数与另一个类的关系
D. 提高程序的运行效率
6. 语句 ofstream f( ″ SALARY.DAT ″ ,ios::app | ios::binary); 的功能是建立流对象 f ,试图打开文件 SALARY.DAT 并与之连接,并且 ( )
A. 若文件存在,将文件写指针定位于文件尾;若文件不存在,建立一个新文件
B. 若文件存在,将其置为空文件;若文件不存在,打开失败
C. 若文件存在,将文件写指针定位于文件首;若文件不存在,建立一个新文件
D. 若文件存在,打开失败;若文件不存在,建立一个新文件
7. 下面说法正确的是 ( )
A. 内联函数在运行时是将该函数的目标代码插入每个调用该函数的地方
B. 内联函数在编译时是将该函数的目标代码插入每个调用该函数的地方
C. 类的内联函数必须在类体内定义
D. 类的内联函数必须在类体外通过加关键字 inline 定义
8. 可以用 p.a 的形式访问派生类对象 p 的基类成员 a ,其中 a 是 ( )
A. 私有继承的公有成员 B. 公有继承的私有成员
C. 公有继承的保护成员 D. 公有继承的公有成员
9. 在公有派生情况下,有关派生类对象和基类对象的关系,不正确的叙述是 ( )
A. 派生类的对象可以赋给基类的对象
B. 派生类的对象可以初始化基类的引用
C. 派生类的对象可以直接访问基类中的成员
D. 派生类的对象的地址可以赋给指向基类的指针
10. 对于类定义
class A{
public:
virtual void func1( ){ }
void func2( ){ }
};
class B:public A{
public:
void func1( ){cout<< ″ class B func 1 ″
下面正确的叙述是 ( )
A. A::func2( ) 和 B::func1( ) 都是虚函数
B. A::func2( ) 和 B::func1( ) 都不是虚函数
C. B::func1( ) 是虚函数,而 A::func2( ) 不是虚函数
D. B::func1( ) 不是虚函数,而 A::func2( ) 是虚函数
第二部分 非选择题 ( 共 80 分 )
二、填空题 ( 本大题共 10 小题,每小题 2 分,共 20 分 ) 不写解答过程,将正确的答案写在每小题的横线处。错填或不填均无分。
11. 定义类的动态对象数组时,系统只能够自动调用该类的 _________ 构造函数对其进行初始化。
12. 在 C++ 程序设计中,建立继承关系倒挂的树应使用 _________ 继承。
13. 表达式 cout<14. 基类的公有成员在派生类中的访问权限由 _________ 决定。
15.C++ 支持的两种多态性分别是 _________ 多态性和 _________ 多态性。
16.C++ 中语句 const char * const p= ″ hello ″;所定义的指针 p 和它所指的内容都不能被 _________ 。
17. 假定 AB 为一个类,则语句 AB(AB&x) ;为该类 _________ 构造函数的原型说明。
18. 将关键字 const 写在成员函数的 _________ 和 _________ 之间时,所修饰的是 this 指针。
19. 在 C++ 中,访问一个对象的成员所用的运算符是 _________ ,访问一个指针所指向的对象的成员所用的运算符是 _________ 。
20. 派生类从一个或多个以前定义的该类的 _________ 继承数据和函数。
三、改错题 ( 本大题共 5 小题,每小题 2 分,共 10 分 )
21. 指出下面程序段中的错误,并说明出错原因。
class A{
int a,b;
public :
A(int aa,int bb) {a=aa;b=bb;}
};
Ax(2,3),y(4);
22. 指出并改正下面利用类模板的对象定义中的错误。
template
class Tany{
T x,y;
public:
Tany(T a,T b){x=a,y=b;}
T sum( ){return x+y;}
};
Tany (int) obj(10,100);
23. 指出下面程序段中的错误,并说明出错原因。
class one{
private:
int a;
public:
void func(two&);
};
class two{
private:
int b;
friend void one::func(two&);
};
void one::func(two& r)
{
a=r.b;
}
24. 指出下面程序段中的错误,并说明出错原因。
# include
class A{
public: void fun( ){cout<< ″ a.fun ″ <};
class B{
public: void fun( ){cout<< ″ b.fun ″ class C:public A,public B{
private:int b;
public:void gun( ){cout<< ″ c.gun ″ };
25. 指出下面程序段中的错误,并说明出错原因。
class Location {
int X,Y=20;
protected:
int zeroX,zeroY;
int SetZero(int ZeroX,int ZeroY);
private:
int length,height;
public:
float radius;
void init(int initX,int initY);
int GetX( );
int GetY( );
};
四、完成程序题 ( 本大题共 5 小题,每小题 4 分,共 20 分 )
根据题目要求,完成程序填空。
26. 在下面横线处填上适当字句,完成类中成员函数的定义。
class A{
int * a;
public:
A(int aa=0) {
a=_________;// 用 aa 初始化 a 所指向的动态对象
}
~ A(){_________;}// 释放动态存储空间
};
27. 下面是一个函数模板,用于计算两个向量的和。在下面横线处填上适当字句,完成函数模板定义。
# include
template
T* f(T* a,T* b,int n)
{
T* c=_________;
for(int i=0;ic [ i ] =_________;
return c;
}
void main()
{
int a [ 5 ] ={1,2,3,4,5},b [ 5 ] ={10,20,30,40},*p;
p=f(a,b,5);
for(int i=0;i<5;i++)
cout<}
28. 下面是一个用户口令检查程序,在横线处填上适当语句完成程序功能。
# include
# include
_________// 定义由 PASS 指针所指向的口令 wolleh 。
void main()
{
char user [ 10 ] ;// 用于存放输入的口令
cout<< ″ please input your password: ″ <_________// 输入口令
if((strcmp(user,PASS))==0)
cout<< ″ your password is correct ″ cout<< ″ your password is error ″ <}
29. 下面是类 fraction( 分数 ) 的定义,其中重载的运算符 << 以分数形式输出结果,例如将三分之二输出为 2/3 。在横线处填上适当字句。
class fraction{
int den; // 分子
int num; // 分母
friend ostream& operator<<(ostream&,fraction);
…
};
ostream& operator <<(ostream& os,fraction fr){
_________;
return _________;
}
30. 在下面程序横线处填上适当的字句,使其输出结果为 0 , 56 , 56 。
# include
class base{
public:
_________func( ){return 0;}
};
class derived:public base{
public:
int a,b,c;
_________ setValue(int x,int y,int z){a=x;b=y;c=z;}
int func( ){return(a+b)*c;}
};
void main()
{
base b;
derived d;
coutcoutcout<}
五、程序分析题 ( 本大题共 6 小题,每小题 5 分,共 30 分 )
给出下面各程序的输出结果。
31. # include
void main( )
{
int *a;
int *&p=a;
int b=10;
p=&b;
cout<<*a;
}
输出为:
32. # include
template
Tf(T*a,T*b,int n){
Ts=(T)0;
for(int i=0;is+=a [ i ] *b [ i ];
return s;
}
void main()
{
double c [ 5 ] ={1.1,2.2,3.3,4.4,5.5},d [ 5 ] ={10.0,100.0,1000.0};
cout<}
输出为:
33. # include
void main()
{
for(int i=0;i<4;i++)
cout<<0? ′ 0 ′ : ′′ );
}
输出为:
34. 运行下面的程序,写出当输入 25 , 60 时的输出结果。
# include
class goods{
private:
static int totalWeight;
int weight;
public:
goods(int w)
{
weigh=w;
totalWeight+=w;
}
goods(goods& gd)
{
weight=gd.weight;
totalWeight+=weight;
}
~ goods()
{
totalWeight-=weight;
}
int getwg()
{
return weight;
}
static int getTotal()
{
return totalWeight;
}
};
int goods::totalWeight=0;
void main()
{
int w;
cout<< ″ The initial weight of goods: ″ >w; // 输入 25
goods g1(w);
cin>>w; // 输入 60
goods g2(w);
cout<< ″ The total weight of goods: ″ <}
输出为:
35. # include
class A{
public:
A( ){ }
virtual void func( ){cout<< ″ Destructor A ″ <~ A( ) {func();}
};
class B:public A{
public:
B( ){ }
void func(){cout<< ″ Destructor B ″ <~ B( ) {func();}
};
void main( )
{
B b;
A&a=b;
}
输出为:
36. # include
class My Class {
public:
int number;
void set(int i);
};
int number=3;
void MyClass::set (int i)
{
number=i;
}
void main()
{
MyClass my1;
int number=10;
my1.set(5);
coutcoutcout<}
输出为:
第一部分 选择题 ( 共 20 分 )
一、单项选择题 ( 本大题共 10 小题,每小题 2 分,共 20 分 )
1.D 2.B 3.B 4.A 5.A
6.A 7.B 8.D 9.C 10.C
第二部分 非选择题 ( 共 80 分 )
二、填空题 ( 本大题共 10 小题,每小题 2 分,共 20 分 )
11. 无参
12. 单一 ( 或单 )
13.cout<< ′ \n ′ ( 或 cout<< ′ \12 ′ , 或 cout<< ′ \xA ′ , 或其它等价形式 )
14. 访问控制 ( 或其它等价形式 )
15. 编译时的 ( 或静态,或操作重载 )
运行时的 ( 或动态,或虚函数 )
16. 改变 ( 或重新赋值 )
17. 复制初始化 ( 或拷贝 )
18. 函数头 ( 或参数表 ) 函数体
19. 成员选择运算符 ( 或“ . ” ) 成员访问运算符 ( 或“ -> ” )
20. 基类
三、改错题 ( 本大题共 5 小题,每小题 2 分,共 10 分 )
21.Ax(2,3),y(4); 语句出错,因为没有单参数的构造函数 ( 或者 y(4) 少写了一个参数 ) 。
22.Tany(int) obj(10,100); 出错,应为 Tany obj(10,100); 语句。
23.void func(two&); 出错, two 尚未声明 ( 或应在 class one 前加声明语句 class two ; ) 。
24.void hun(){fun();} 出错, C :: fun() 有二义性。
25.int X,Y=20; 出错,不能采用这种方式初始化。
四、完成程序题 ( 本大题共 5 小题,每小题 4 分,每空 2 分,共 20 分 )
26.new int(aa) delete a
27.new int [ n ] a [ i ] +b [ i ] ( 或等价形式 )
28.const char *PASS= ″ wolleh ″ ;( 或 const char PASS [] = ″ wolleh ″ ;)
cin.getline(user,9);( 或 cin>>user;)
29.os<30.virtual int void
五、程序分析题 ( 本大题共 6 小题,每小题 5 分,共 30 分 )
31.10
32.3531
33. 0
0*0
0***0
0*****0
34.The initial weight of goods:0
25 60 ( 这是输入数据 )
The total weight of goods:85
35.Destructor B
Destructor A
36.5
10
3
上一篇文章: 计算机技术与软件水平考试面向对象程序设计试题(6)
下一篇文章: 没有了
【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口】