招生考试网
学历类| 阳光高考 研 究 生 自学考试 成人高考 专 升 本 中考会考 外语类| 四 六 级 职称英语 商务英语 公共英语 日语能力
资格类| 公 务 员 报 关 员 银行从业 司法考试 导 游 证 教师资格 财会类| 会 计 证 经 济 师 会计职称 注册会计 税 务 师
工程类| 一级建造 二级建造 造 价 师 造 价 员 咨 询 师 监 理 师 医学类| 卫生资格 执业医师 执业药师 执业护士 国际护士
计算机| 等级考试 软件水平 应用能力 其它类| 书画等级 美国高考 驾 驶 员 书法等级 少儿英语 报 检 员 单 证 员 出国留学
 招生考试网 - 自学考试 - 自考真题 - 正文
2009年10月全国自考C++程序设计试题
来源:fjzsksw.com 2009-12-4 9:47:00 【字体:小 大】

全国2009年10月自学考试
C++程序设计试题
课程代码:04737

一、单项选择题(本大题共20小题,每小题1分,共20分)
在每小题列出的四个备选项中只有一个是符合题目要求的,请将其代码填写在题后的括号内。错选、多选或未选均无分。
1.对C++中主函数描述正确的是( )
A.名称为main,可为多个
B.名称不限,可为多个
C.名称为main,必须有且只能有一个
D.名称不限,必须有且只能有一个

2.调用声明为int result(int a,int b)的函数时,正确的方法是( )
A.result(1,2)
B.result(1)
C.result(0.1,0.3)
D.result(1,2,3)

3.用于包含C++标准库iostream的预处理指令是( )
A.#define<iostream>
B.#include<iostream>
C.#define ‘iostream’
D.#include‘iostream’

4.无类型标识符是指( )
A.void
B.bool
C.short
D.long

5.从本质上看,引用是被引用变量的( )
A.拷贝
B.别名
C.复制
D.克隆

6.下面关于数组的初始化正确的是( )
A.char str[ ]={'a','b','c'};
B.char str[2]={'a','b','c'};
C.char str[1][2]={{'a','b'},{'e','d'}};
D.char str[ ][ ]={'a','b','c'};

7.C++类中定义的成员默认访问属性为( )
A.public
B.private
C.protected
D.friend

8.决定C++语言中函数的返回值类型的是( )
A.return语句中的表达式类型
B.调用该函数时系统随机产生的类型
C.调用该函数时的主调用函数类型
D.在定义该函数时所指定的数据类型

9.函数int & min(int &,int &)返回参数中较小者,设有两整型变量int a=10;int b=15;在执行语句min(a,b)--;之后,a,b值分别为( )
A.9,14
B.9,15
C.10,14
D.10,15

10.声明函数为内联函数时所使用的关键字为( )
A.const
B.inline
C.short
D.signed

11.函数int sum(int a=l,int b=1,int c=3)可与下列哪个函数同时声明( )
A.double sum(int);
B.char sum(int,int);
C.int sum(double);
D.int sum(int,int,int);

12.函数模板template<typename T> void Func(T,T)可具有下列哪种实例化形式( )
A.void Func(float,int)
B.void Func(char,char)
C.void Func(int,double)
D.void Func(bool,float)

13.下列访问成员的方式哪个是正确的( )
A.对象名.对象成员名
B.对象指针名.对象成员名
C.对象名→对象成员名
D.类名→对象成员名

14.对类A,复制构造函数的原型是( )
A.A::A(const A&);
B.A::A(const A *);
C.A::A(const A);
D.A::A( );

15.对class point,如使用point * ptr=new point[2];创建对象数组,则删除此数组使用的语句是( )
A.delete ptr[2];
B.delete[ ] ptr;
C.delete ptr[ ];
D.delete[2] ptr;

16.下列哪个编译指令不属于条件编译指令( )
A.#if
B.#else
C.#endif
D.#error

17.类A中存在静态数据成员x,设a和b是类A的两个对象,在执行a.x=10之后,b.x
的值为( )
A.未初始化
B.等于a.x
C.等于0
D.随机

18.使用string.h库操纵字符串时,将两个字符串连接成一个字符串的函数是( )
A.strlen()
B.strcap()
C.strcat()
D.strcmp()

19.基类中的public成员,通过public派生,其在派生类中的访问权限为( )
A.不可访问
B.private
C.protected
D.public

20.不同对象调用同名函数,但导致完全不同行为的现象称为( )
A.抽象
B.封装
C.继承
D.多态性

二、填空题(本大题共20小题,每小题1分,共20分)
请在每小题的空格中填上正确答案。错填、不填均无分。
21.在C++语言的面向对象设计框架中,_______是程序的基本组成单元。
22.执行代码double pi=3.1415192; cout < < setprecision (3) < < pi;程序的输出结果是_______。
23.C++语言提供的的基本控制结构可以分为3种类型:顺序结构、_______和循环结构。
24.要使用STL库提供的对数组进行降幂排序算法,在源程序中需要包含的头文件是______。
25.在C++标准库中,用_______类来表示复数。
26.将对象作为函数参数,是将实参对象的_______传递给形参对象,这种传递是单向的。
27.C++函数的返回类型可以是除数组与_______以外的任何类型。
28.能提供封装的C++关键字是_______。
29.在C++的类声明中,用public关键字声明的类成员的访问权限是_______。
30.开发一个C++语言程序的步骤通常包括编辑、_______、连接、运行和调试。
31.C++类中的_______函数在对象的生存期结束时被自动调用。
32.友元函数可以存取类的_______、公有成员和保护成员。
33.若类的成员函数用关键字static进行修饰,这样的成员函数称为_______。
34.在C++中,创建派生类对象时,总是先从_______的初始化开始的。
35.类的继承是指派生类继承基类的数据成员和_______。
36.在C++中,利用向量类模板定义一个具有20个double的向量,其元素均被置为0.5,实现此操作的语句是_______。
37.vector类中用于返回向量中的最后一个对象的方法是_________。
38.虚函数类似于重载函数,但与重载函数的实现策略不同,对虚函数声明时应使用_______关键字。
39.在C++中,虽然友元提供了类之间数据进行访问的一种方式,但它破坏了面向对象程序设计的_______特性。
40.执行下列代码
cout < < showpoint < < 123.0;程序的输出结果是_______。
三、改错题(本大题共5小题,每小题4分,共20分)
下面的每个程序都有一处错误,请用下横线标出错误所在行并给出修改意见。
41.#include <iostream>
using namespace std;
int main ( ){
int num; max=10; num =1
while (num < max) num + + ;
cout <<″Num = ″<< num;
return 0;
}
42.#include <iostream>
using namespace std;
class A {
void show ( ) {
cout<<″Hello!″;
}
};
int main ( ) {
A a;a. show ( );
return 0;
}
43.#include <iostream>
using namespace std;
int main ( ) {
const int num = 20;
int scores[num];
for (int i=1;i<=num;i + +){
scores[i]=i;
}
return 0;
}
44.#include <iostream>
using namespace std;
class CMax {
private:
int xx; int yy;
public:
CMax(int x,int y)
{ xx = x;yy = y ; }
void setValue(int x,int y)
{ xx = x;yy = y;}
int max( ){
return xx > yy? xx:yy;
}
};
void main( ){
CMax m( );
m.setValue(20,30);
cout <<″Max=″<<m.max( )<<endl;
}
45.#include <iosiream>
using namespace std;
class A{
public:
char name[255];
private:
char * getName( )
{ return name; }
};
class B:public A{
public:
B(char * n){
strcpy ( name,n);
}
};
void main( ){
B b(″Hello!″);
cout <<″Name:″<<b.getName( );
}

四、完成程序题(本大题共5小题,每小题4分,共20分)
46.将下面程序补充完整,使程序输出结果为:
Begin
Welcome
Show
End
程序如下:
#include <iostream>
using namespace std;
class A{
public:
__________{
cout <<″Begin″<<endl;
}
void show( ){
cout<<″Show″<<endl;
}
___________{
cout<<″End″<<endl;
}
};
A object;
int main( ){
cout <<″Welcome″<<endl;
object.show( );
return 0;
}
47.请将下面程序补充完整,使程序可以正常打印9×9乘法口诀。
#include <iostream>
using namespace std;
class A {
private:
int a;int b;
public:
__________
{ a = x;b = y; }
void set(int x,int y)
{ a = x;b = y; }
void display( ){
cout<<a<<*′<<b<<′=′<<a * b;
}
};
int main( ){
A a(1,1);
for(int i=1;i<=9;i++){
for(int j=1;____;j++){
a.set(j,i);
a.display( );
cout<<″″;
}
cout<<endl;
}
return 0;
}
48.将下面程序补充完整,使程序可以输入学生信息并计算平均成绩。
#include <iostream>
#include <string.h>
using namespace std;
class Student{
private:
char name[255];
int score[10];
public:
Student(char n[ ],int s[ ]){
___________;
for(int i=0;i<10;i++){
score[i]=s[i];
}
}
void Show( ){
int sum=0;
for(int i=0;i<10;i++){
_______________;
}
cout<<″名字:″< < name<<″,平均成绩:″<<sum/10;
}
};
void main( ){
char name[255];
int score[10];
cout<<″姓名:″;cin>>name;
for(int i=0;i<10;i++){
cout<<″成绩″<<i+l<<″:″;
cin>>score[i];
}
Student s(name,score);
s.Show( );
}
49.将下面程序补充完整,使程序可以正常运行,并释放内存。
#include <iostream.h>
_______
class A {
private:
T * data;
int length;
public:
A (int len){
length=len;
data=new T[len];
}
~A( ){
_________
}
T& operator[](int i){
return data[i];
}
};
int main( ){
A<int> obj(2);
obj[0]=1;
obj[1]=2;
cout<<obj[0]<<endl;
cout<<obj[1]<<endl;
return 0;
}
50.将下面程序补充完整,使程序运行结果为:
C1ass A
Class B
程序如下:
#include <iostream.h>
#include <string.h>
class A{
public:
virtual void GetA( ) = 0;
};
class B:public A{
private:
char str[32];
public:
void GetA( ){
cout<<″Class A″<<endl;
}
const char * GetB( ) {_____
}
B(char * s){
strcpy(str,s);
}
};
void main( ){
A * a;
B b(″Class B″);
a=_________;
a-> GetA( );
cout<<b.GetB( )<<endl;
return;
}
五、程序分析题(本大题共2小题,每小题5分,共10分)
51. #include <iostream>
using namespace std;
int main( ){
int i,j;
for(i=l;i<=4;i+=1)
for(j=2;j<=4;j+=j){
if(i+j<5)
cout<<″ + ″;
else
cout<<″ * ″;
}
return 0;
}
52. #include <iostream>
using namespace std;
class A {
int a;
public:
A(int aa=0){a=aa;}
~A( ){cout <<″Destructor A!″<<a<<endl;}
};
class B:public A{
int b;
public:
B(int aa = 0,int bb = 0):A(aa){b = bb;}
~B( ){cout <<″Destructor B!″<< b << endl;}
};
void main( ){
B x(5),y(6,7);
}

六、程序设计题(本大题10分)
53.下面Shape类是一个表示形状的抽象类,Area ( )为求图形面积的函数。请从Shape类派生梯形类(Trapezoid)、圆形类(Circle),三角形类(Triangle),并给出具体的求面积函数。其中,所有派生类计算面积需要用到的参数由构造函数给出,梯形面积计算需要上底、下底和高,三角形面积需要底和高,圆形面积需要半径。
形状的抽象类声明如下:考试大收集整理
class Shape {
public:
virtual double Area( ) = 0;
};

 

网站版权与免责声明
①由于各方面情况的不断调整与变化,本网所提供的相关信息请以权威部门公布的正式信息为准.
②本网转载的文/图等稿件出于非商业性目的,如转载稿涉及版权等问题,请在两周内来电联系.