11.cout是I0流库预定义的
A 类 B 对象 C 包含文件 D 常量
12.继承机制的作用是
A 信息隐藏 B 数据封装 C 定义新类 D 数据抽象
13.类的定义如下,试问类B的对象占据内存多少宇节空间?
class A {int b; protected: int a; public: A(int n){a=n;};};
class B: public A {int c;};
A 2 B 3 C 4 D 6
14.一段程序的定义如下,在函数f()中将动态对象的成员n的值改为34的语句应该为
class A {
int n;
public: setn(int nl) {n=nl;}
A(int x) {n = x; } }
int f() {A * ptr = new A(45);... }
A A(34); B ptr.setn(34); C ptr->setn(34); D setn(34);
15.类的析构函数的作用是
A 一般成员函数 B 类的初始化 C 对象的初始化 D 删除对象创建的所有对象
16.类的析构函数是在什么时间被自动调用的?
A 类创建时 B 创建对象时 C 删除对象时 D不自动调用
17.下面哪个是正确的递归函数,它保证对所有的参数能够结束?
A int f(int n) {if(n<l) return 1; else return n*f(n+l); }
B int f(int n) {if(n>l) return 1; else return n*f(n-l); }
C int f(int n) {if(abs(n)<l) return 1; else return n*f(n/2); }
D int f(int n) {if(n>l) return 1; else return n*f(n*2); }
18.求解问题的一般方法有
A 结构化方法 B 求精算法和精美算法 C 模块方法 D 过程化方法
19.-1在计算杭内的存储形式是
A 0xFFFF B 1111111111111110 C 1000 0000 0000 0001 D 0000 0000 0000 0001
20.下列常量中,哪个的类型为float类型?
A 2.F B .2L C 0.2E100 D 0.0
三、名词解释题(每小题z分,共10分)
21.变量
22.内部变量
23.赋值运算的类型兼容性
24.拷贝构造函数
25.实例化
四、改错题(每小题1分,共10分)
26.要求下面循环体中的语句x+=3执行30次,请改正程序。
for(j=0; j<90; j++) if(j/3=0) x+=3;
27.下面的函数求一个无负号数的2倍值,请该正错误。
unsigned times(unsigned n) {return n?;}
28.指出程序段中的错误: for(k=l,k<n,k++); (f=f+(f*15)%k; 45+f; cou<<f;}
29.以下语句是合法的C++语言语句吗?不合法的又错在哪里?
if (x > 0) then x =x + 1; else x - x - 1;
30.改正函数原型 static int calc_middle(x, y, z);
31.下列的类声明程序片段是否有语法错误,如有请该正 :
class FIGURE {
PUBLIC:
figure();
FIGURE();
~FIGURE (int have_drawed);
};
32.设有如下的程序片段,是否有错误,如有错误请该正
class PRINTER (
unsigned char flag;
int print_page() (...);
public:
PR INTER (unsigned char fig) {...};
int print_file () {...};
};
int main() {
PRINTER LQ_1600K(0x3F8, '/0');
LQ-1600K.print-page 0;
}
33. 请指出程序片段的语法错误。
int * age_ptr;
int m = 3;
*age_ptr = &m;
34.请指出程序片段的语法错误。
int* salary_ptr;
float* work_hours_ptr;
salary_ptr = work_hours_ptr;
35.指出下面程序中的错误。
#include <iostream.h>
#include <string.h>
class PERSON {
public:
PERSON(char *name) { int len;
len = strlen (name);
PERSON::name = new char[len+1];
strcpy(PERSON:: name, name);
}
~PERSON () { delete name; }
char* get_name () { return name; )
protected:
char *name;
};
class STUDENT: PERSON {
public:
void STUDENT (char *st_name, int score): score (score)
{ int len;
len = strlen(st_name);
name = new char[len+l];
strcpy(name, st_name);
}
int get_score () { return score; )
protected:
int score = 100;
{;
int main () {
STUDENT soft("Zhao". 80);
cout <<"Student:" << soft.get_name ();
cout <<"Score: " <<soft.score <<"./n";
return 0;
}
五、简答题(每小题3分,共15分)
36.试说明实体与程序之间的关系。
37. C++是如何实现数据封装和信息隐藏的?
38. 举例说明如何动态创建对象和删除对象?
39. 什么是父类型?什么是子类型?
40. 什么是函数重载?
六、程序理解题(每小题4分,共20分)
41. 给出下面程序的输出。
#include <iostream.h>
int main() {
const int max_number = 10;
int index;
int find_one, find_two;
int array [max_number] ={20, 12, 32, 13, 19, 41, 10, 61, 23. 57};
find_one = array [1];
find_two = array [2];
for (index = 0; index < max_number; index =index + 1) {
if (array[index] < find_one) find_one = array [index];
if (array[index] > find_two) find_two = array [index];
}
cout << "/n0k, find_one =" <<find_one <<", find_two =" <<find_two;
return 1;
}
42.请给出下面程序的输出结果。
#include <iostream.h>
const unsigned long MEGA_BYTE = (unsigned long)1024 *1024;
class COMPUTER {
public:
COMPUTER (unsigned long m_size, unsigned long h_size, int CD_speed)
{
memory_size = m_size;
hard_disk_size = h_size;
CD_ROM_speed = CD_speed;
if (memory_size > (unsigned long)16 * MEGA_BYTE) {
cout << "/nYou should install Windows 95!";
} else {
cout << "/nYou can only install Windows 3.1!";
}
if (hard_disk_size > (unsigned long)800 * MEGA_BYTE) {
cout << "/nYou can install Visual C++ 4.0!";
} else {
cout << "/nYou can only install Borland C++ 4.5!";
}
if (CD_ROM_speed > 4) cout << "/nYou can see Video CD!";
else cout << "/nYou can only listen Audio CD!";
}
~COMPUTER () { cout << "/nYou should make good use of your computer!"; }
