资源描述
C++程序设计试卷
一, 填空题(每空1分,共15分)
1. 被调函数在执行结束时,这个函数中定义的_______类型的变量不被释放。
2. 设
struct student
{
int no;
char name[12];
float score[3];
} sl,* p = &sl;
用指针法给sl的成员no赋值1234的语句是_________________。
3. C语言程序中对文本文件的存取是以________________为单位进行的。
4. 设char string[] =″This_is_a_book!″;则数组的长度应是________________。
5. 设int a[2][3] = {{2},{3}};则数组元素_________________的值为3。
6. 向对象程序的三大特征是:_______、_____与________。
7. 设int a=5,则执行a++的结果是_______,此时a的值是______。
8. 派生类的3种继承方式分别是___________、_______和_______。
9. 绑定是指一个计算机程序自身彼此关联的过程。按照绑定所进行的阶段不同,可分为_____________和__________。
一、 单项选择题(每题2分,共20分)
1. 设char str[100];int i = 5;则引用数组元素的错误形式是 【 】
A. str[i + 10] B. (str + i)
C. (str + i - 1) D. ((str + + ) + i)
2. 设int x[] = {1,2,3,4,5,6},* p = x;则值为3的表达式是 【 】
A. p + = 2, * + + p B. p + = 2, * p + +
C. p + = 3, * p D. p + = 2, + + * p
3. 在函数内,定义变量时存储类型符可省略的是 【 】
A. auto B. static
C. extern D. register
4. 设有定义语句
struct
{int a;float b;} d[3]={{1,4},{2,5},{6,7}};
则printf(″﹪3.1f \ n″,d[2]. a * d[2]. b/d[1]. b);的输出是 【 】
A. 2.5 B. 2.0 C. 8.0 D. 8.4
5. 设有定义语句:enum t1 {a1, a2 = 7, a3, a4 = 15}time;
则枚举常量a2和a3的值分别为 【 】
A. 1和2 B. 2和3 C. 7和2 D. 7和8
6. 为了避免嵌套的if-else语句的二义性,C++语言规定else总是与【 】组成配对关系。
A. 缩排位置相同的if B. 在它之前未配对的if
C. 在它之前未配对的最近的if D. 同一行上的if
7. sizeof(float)是一个 【 】表达式。
A. 整型 B. 双精度实型
C. 浮点型 D. 函数调用
8.在C++中函数没有返回值时,函数的类型应定义为【 】
A.void B.float C.int D. 无
9.以下构造函数定义形式正确的是【 】
A. int student(char*, int );
B. void student(char*,int )
C. void* student(char*,int)
D. student(char*, *int) ;
10.关于delete运算符,下列描述中,【 】是错误的。
A. 必须用于new返回的指针
B. 适用于空指针
C. 对一个指针可以使用多次delete运行符
D. 在指针名前只用一对括号,而不管所删除数组的维数
二、 读程序填空题(15分)
1. 以下对数组a简单选择排序的程序,
2. 请在______处补充相应的语句,使程序完整。
#include <iostream.h>
void sort(int array[],int n)
{ int i,j,k,t;
for(i=0;i<n-1;i++)
{ k=i;
for(j=i+1;j<n;j++)
if(array[j]<array[k]) k=j;
if(k!=i)
{ t=array[i];
array[i]=array[k];
____①____;
}
}
}
main()
{ int a[10],i;
for(i=0;i<10;i++)
cin>>a[i];
sort(__②____, ___③___);
for(i=0;i<10;i++)
cout<<a[i];
cout<<endl;
}
2. 以下是实现交换两个数的程序,请在______处补充相应的语句,使程序完整。
#include <iostream.h>
void swap(___④______)
{ int *t;
t=*r;
*r=*s;
*s=t;
}
main()
{ int a=1,b=2,*p,*q;
p=&a;
q=&b;
swap(__⑤____);
cout<<*p<<*q<<endl;
}
3. 以下程序的功能是输入一字符串(换行为结束标志)统计其中数字(0,1,…,9不单独统计)、空白和其它字符出现的次数。请在______处补充相应的语句,使程序完整。
# include <iostream.h>
main()
{
char c;
int ⑥ ;
while((c = getchar())! =′\ n′)
{
if(____⑦_____) digit + + ;
else if(c = =′′‖c = =′\ t′) ++ blank;
else ____⑧____;
}
cout<<”digit =”<< digit<<”blank =”<<blank<<””other =”<<other<<endl;
}
四、阅读程序写输出结果(每题5分,共20分)
1. 分析下面程序运行的结果。
#include <iostream.h>
using namespace std;
int main()
{
int i,j,m,n;
i=8;
j=10;
m=++i+j++;
n=(++i)+(++j)+m;
cout<<i<<’t’<<j <<’\t’<<m<<’\t’<<n<<endl;
return 0;
}
运行时输出:_____________________________。
2. #include <string.h>
#include <iostream.h>
void main()
{ char destination[25];
char blank[] = " ", c[]= "C++", turbo[] = "Turbo";
strcpy(destination, turbo);
strcat(destination, blank);
strcat(destination, c);
cout<<destination<<endl;
}
运行时输出:___________________________。
3. #include <iostream.h>
main()
{ void increment(void);
increment();
increment();
increment();
}
void increment(void)
{ static int x=0;
x++;
cout<<x<<endl;
}
运行时输出为:
4. #include <iostream.h>
class base
{
public:
~base()
{
cout<<”destructing base”<<endl;
}
};
class der:public base
{
public:
char *ch;
public:
void der(int i) { ch = new char[i]; }
virtual ~der()
{
delete []ch;
cout<<”destructing der” <<endl;
}
};
void main()
{
base *b= new der(20);
delete b;
}
运行时输出为:
五、 编写程序(每题10分,共30分)
1.编写一个程序,输入3个整数a,b,c,输出其中最大的数。
2.编写一个程序,计算s= 15! 的值。
3.实现一个用于计算体积的长方体类,要求该类:
(1) 数据成员包括:长(length)、宽(width)与高(height)
(2) 提供输入长、宽与高的成员函数;
(3) 提供计算体积的成员函数;
第 6 页 共 6 页
展开阅读全文