中国大学mooc程序设计与算法语言(c )试题及答案-2024欧洲杯竞猜官方平台

大学本科习题 8168
第1章 绪论

第1章 绪论 测验

1、下列程序段的输出是()。 short int i=65536; cout<    a、65536
    b、0
    c、-1
    d、有语法错,无输出结果。

2、下面的说法正确的是()。
    a、cin对象设置的域宽只对与其相邻的下一个输入有效。
    b、cin对象设置的域宽对所有输入有效。
    c、流插入符>>能够读取含空格的字符串。
    d、调用cin的getline函数不能读取含空格的字符串。

3、c 语言是从 两种语言发展来的。

4、cin对象指定输入域宽的两种方法分别是 。

第1章 绪论 作业

1、c 语言程序通常由哪几部分构成?

第2章 c 的数据类型

第2章 c 的数据类型 测验

1、以下对c 中变量使用的说法,正确的是()。
    a、变量名可以随意命名
    b、变量必须先定义再使用
    c、变量可以不区分数据类型
    d、变量未初始化时,其值为零

2、以下常量表示中不正确的是()。
    a、0
    b、‘\55’
    c、0x2a3
    d、103

3、下列选项中属于字符串常量的是()。
    a、'hello'
    b、“ab0x123\0cd”
    c、hello
    d、‘a’

4、说明enum money {fen, jiao, yuan=100, tenyuan};中每个枚举变量所对应的实际值为()。
    a、0, 1, 100, 101
    b、1, 2, 100, 101
    c、“fen”, “jiao”, “yuan”或100, “tenyuan”或101
    d、“fen”或1, “jiao”或2, “yuan”或100, “tenyuan”或101

5、若x, y, z的初值均为1,则执行表达式w= x|| y&& z后,x, y, z的值分别为()。
    a、x=1, y=1, z=2
    b、x=2, y=2, z=2
    c、x=1, y=2, z=1
    d、x=2, y=1, z=1

6、设a是整型变量,初值是6,执行完表达式a =a-=a*a后,a的值为()。
    a、36
    b、-60
    c、60
    d、0

7、在c 中,要求运算数必须是整型的运算符是()。
    a、%
    b、/
    c、<
    d、!

8、关系式x>=y>=z的c 语言表达式是()。
    a、(x>=y)&&(y>=z)
    b、(x>=y)||(y>=z)
    c、(x>=y>=z)
    d、(x>=y)&(y>=z)

9、设a、b、c都是int型变量,a=3, b=4, c=5,下列表达式中,值为0的表达式是()。
    a、‘a’&&’b’
    b、a<=b
    c、a||b c&&b-c
    d、!((a
10、下列语句中符合c 语法的语句是()。
    a、a=7 b c=a 7;
    b、a=7 b =a 7;
    c、a=7 b, b , a 7
    d、a=7 b, c=a 7;

11、下面程序的运行结果是()。 #include using namespace std; void main() { int x=040; cout<<(x=x<<1)<    a、100
    b、160
    c、120
    d、64

12、常变量必须在定义时赋初值,且在程序的运行中值不可变。

13、设x=3, y=5, 表达式x=y==3运算后的值为 。

14、表示10
15、下列程序的运行结果是 。 #include using namespace std; void main( ) { int n1, n2; n1=123, n2=234; cout<< n1 & n2<
16、下列程序的运行结果是 。 #include using namespace std; void main() { int num=39, mask; num >>= 3; mask = ~ ( ~0 << 3); cout<<"result="<
17、下列程序的运行结果是 。 #include using namespace std; void main() { unsigned a=3,b; b=~a|a<<2 1; cout<
18、设a, b为整型量,且a=7, b=8,则表达式a=a|b<<2&&~b的值为 。

19、设二进制数a是00101101,若想通过异或运算a^b使a的高4位取反,低4位不变,则二进制数b应是 。

第2章 c 的数据类型 作业

1、请编程计算下列表达式的值。 设有变量说明:int a=3, b=4, c=5; 1) a b>c && b==c 2) a || b c && b>c 3) !a || !c || b 4) a*b && c a 5) a*=a*=b 6) c=b/=a 7) c=a =b =a

2、请编程计算下列表达式,并指出运算后x、y、a、b和c的值。 设有变量说明:int a=15, b=18, c=21; 1) x=ab && c 3) x=a b>c && c 4) y=a || b || c

第3章 c 语句

3.1 算法的基本概念和表示方法随堂测验

1、对于用c 语言实现的算法,以下叙述中正确的是 ( )。
    a、必须要有输入和输出操作
    b、可以没有输出但必须要有输入
    c、可以没有输入但必须要有输出
    d、可以既没有输入也没有输出

2、三种基本结构分别是 、 和 。

3.2 选择结构程序设计(if-else)随堂测验

1、要使以下程序的输出结果为10,则a和b应满足的条件是( )。 #include using namespace std; void main() { int s, t, a, b; cin >> a >> b; s = t = 5; if(a > 0) s = 2; if(a > b) t = s t; else if(a == b) t = 5; else t = 2 * s; cout << t << endl; }
    a、a>0并且a    b、a<0并且a    c、a>0并且a>b
    d、a<0并且a>b

2、执行以下程序段后,a,b,c的值分别是( )。 int a, b = 20, c, x = 9, y = 8; a = (--x == y)? --x : y ; if(x < 9) b = x ; c=y;
    a、7, 8, 8
    b、7, 7, 8
    c、7, 8, 9
    d、8, 9, 9

3.2 选择结构程序设计(if-else)随堂测验

1、当从键盘输入10 20时,以下程序段的输出结果是 。 (区分==和=) #include using namespace std; void main() { int num1, num2; cout<<"please input num1 and num2:\n"; cin>>num1>>num2; if(num1 = num2) cout<<"num1=num2"<
2、当输入1 0 0时,以下程序段的输出结果是 。 (易错的关系表达式) #include using namespace std; void main() { int a, b, c; cout<<"please input a, b and c:\n"; cin>>a>>b>>c; if(a<=b<=c) { cout<<"min=a="<
3、以下程序运行后的输出结果是 。 (条件表达式的多样性) #include using namespace std; void main() { int a = 3, b = 4, c = 5, t = 99; if(b) if(a) cout<
4、以下程序运行后的输出结果是 。 #include using namespace std; void main() { int a=5, b=8 , c=4 , d=3 , m=1, n=0, p; if( (m = a > b) && (n = c > d)) p = m n; else p = m – n; cout<<"m="<3.3 选择结构程序设计(switch)随堂测验

1、若a和b均是整型变量,以下正确的switch语句是( )。
    a、switch(a/b) {case 0:case1.5:y=a b;break; case 2:case 3:y=a-b;}
    b、switch(a*a b*b); { case0:y=a b;break; case1:y=b-a;break; }
    c、switch a {case 0:x=a b; case 1:y=a-b;break;}
    d、switch(a b) {case 0:x=a b;break; case 1:y=a-b;break;}

3.3 选择结构程序设计(switch)随堂测验

1、当从键盘输入'c'时,以下程序段的输出结果是 。 cin>>n; switch(n) { default: cout<<"error\n";break; case 'a': case 'a':case 'b':case 'b':cout<<"good\n";break; case 'c': case 'c':cout<<"pass\n"; case 'd': case 'd':cout<<"warn\n"; }

2、以下程序的输出结果是 。 #include using namespace std; void main( ) { int i=4; switch(i%4) { case 0: case 1: cout<<'d' i<
3、以下程序的运行结果是 。 #include using namespace std; void main() { int x=1,y=0,a=0,b=0; switch(x) { case 1: switch(y) { case 0: a ; case 1: b ; } case 2: a ;b ; break; case 3: a ;b ; } cout<<"a="<
3.4 循环结构程序设计(while语句)随堂测验

1、有以下程序段: int k = 0; while(k = 1) k ; 则while循环执行的次数是()。
    a、无限次
    b、有语法错,不能执行
    c、一次也不执行
    d、执行1次

3.4 循环结构程序设计(while语句)随堂测验

1、以下程序的输出结果是 。 #include using namespace std; void main() { int num = 2; while(num-- ) ; cout<
2、以下程序的功能是:从键盘上输入若干个学生的成绩,统计并输出最高成绩和最低成绩,当输入负数时结束输入,请填空。(答案中请不要带空格,答案之间用3个空格键间隔) #include using namespace std; void main() { float x,max,min; cin>>x; max=x; min=x; while( ) { if ( ) max=x; if( ) min=x; cin>>x; } cout<<"\nmax="<< max <<"\nmin="<< min<<"\n"; }

3、以下程序的输出结果是 。 #include using namespace std; void main() { int x=5,y=9,a=0; while (x !=y--) a =1; cout<<"x="<
3.5 循环结构程序设计(do-while语句)随堂测验

1、有以下程序段: #include using namespace std; void main() { int k = 0; do { k--; cout<= 0); } 则do-while循环执行的次数是()。
    a、无限次
    b、有语法错,不能执行
    c、一次也不执行
    d、执行1次

3.5 循环结构程序设计(do-while语句)随堂测验

1、以下程序的输出结果是 。 #include using namespace std; void main() { int x = 4; do { x -= 3; cout<
3.6 循环结构程序设计(for语句)随堂测验

1、以下程序的执行结果是( )。 #include using namespace std; void main() { int i, sum=0; for(i=1;i<=5;sum ) sum =i; cout<    a、6
    b、5
    c、无限循环
    d、0

3.6 循环结构程序设计(for语句)随堂测验

1、以下程序的输出结果是 。 #include #include using namespace std; void main() { int i; for (i=1;i>=0;) cout<
2、下述程序计算fibonacci数列的前20个数,且每行输出5个数,请填空。(答案中请不要带空格,答案之间用3个空格键间隔) #include #include using namespace std; void main() { int f,f1=1,f2=1; int i; cout<
3、下述程序计算从键盘输入的两个数的最大公约数,请填空。(答案中请不要带空格,答案之间用3个空格键间隔) #include #include using namespace std; void main() { int x, y, r, gcd; cout<<"enter two number: \n "; cin>> x>>y; r= ; while ( ) { x=y; y=r; r= ; } cout<<"the result is "<
3.7 break与continue语句随堂测验

1、在循环结构的循环体中执行break语句,其作用是( )。
    a、结束本次循环,进行下次循环
    b、继续执行break语句之后的循环体中各语句
    c、跳出该循环体,提前结束循环
    d、终止程序运行

2、以下程序的运行结果是( )。 #include using namespace std; void main() { int i=1; while(i) { cout<<"*"; i ; if(i<3) break; } cout<<"\n"; }
    a、*
    b、***
    c、**
    d、****

3、以下程序的运行结果是( )。 #include using namespace std; void main() { int i, sum=0; for(i=1;i<10;i ) { if(i%5==0) continue; sum =i; break; } cout<    a、1
    b、40
    c、无限循环
    d、无输出结果

3.7 break与continue语句随堂测验

1、以下程序的运行结果是 。 #include using namespace std; void main() { int a = 0, b = 1; for ( ; a<5 ; a , b ) { if (( a b ) % 5 == 0) continue; b = a; } cout<<"a="<
2、当从键盘输入2453时,以下程序的运行结果是 。 #include using namespace std; void main() { char c; cin.get(c); while(c !='\n') { switch(c - '2') { case 0: case 1: cout<<(char)(c 1); break; case 2: cout<<(char)(c 2); break; case 3: cout<<(char)(c 3); default: cout<<(char)(c 4); break; } cin.get(c); }; }

第3章 c 语句 测验

1、以下关于switch 语句和break 语句中,_______是正确的。
    a、在switch语句中,可以根据需要使用或不使用break语句
    b、switch语句中必须用break 语句
    c、break语句只能用于switch 语句
    d、break语句是switch 语句必须的一部分

2、三元条件运算符ex1?ex2:ex3,相当于下面_______语句。
    a、if(ex2) ex1;else ex3;
    b、if(ex1) ex2;else ex3;
    c、if(ex1) ex3;else ex2;
    d、if(ex3) ex2;else ex1;

3、以下程序运行后的输出结果为_______。 #include void main() { int i=-1, j=1; if(( i<0)&&!(j--<=0)) cout<    a、-1 1
    b、1 0
    c、0 1
    d、0 0

4、若有程序段如下: a=b=c=0;x=35; if(!a) x; else if(b); if (c) x = 3; else x = 4; 执行后,变量x 的值是_______________。
    a、35
    b、4
    c、34
    d、3

5、运行下列程序段后a的值是_______________。 int a = 10; switch(a) { case 9: a ; case 10: a ; case 11: a ; default: a ; }
    a、10
    b、11
    c、12
    d、13

第3章 c 语句 作业

1、回文整数是指正读和反读相同的整数,编写一个程序,输入一个整数,判断它是否是回文整数。例如12321就是回文。

2、编写一个程序,写出100-1000所有的水仙花数。水仙花数是一个三位数,其各位数字的立方和等于该数本身。例如153= 1*1*1 5*5*5 3*3*3。

第3章补充 结构体与链表

6.1 结构体的定义随堂测验

1、为了建立如图所示存储结果,data为数据区,next为指向结点的指针域,请填空: data next struct link { char data; ; }node;

(补充)3.2 结构体的应用随堂测验

1、以下程序的运行结果是()。 #include using namespace std; void main( ) { struct cmplx { int x; int y; } cnum[2]={1, 3, 2, 7}; cout<<(cnum[0].y/ cnum[0].x* cnum[1].x)<    a、0
    b、1
    c、3
    d、6

(补充)3.3 用typedef定义类型随堂测验

1、下列说法中,不正确的是()。
    a、typedef 只能用于为已知数据类型名定义新的类型名。
    b、typedef 应用于软件移植。
    c、typedef并没有增加新的数据类型。
    d、typedef和define等价。

(补充)3.4 链表的建立随堂测验

1、以下函数creat用来建立一个带头结点的单向链表,新产生的结点总是插在链表的末尾。单向链表的头指针作为函数值返回。请填空。 #include using namespace std; struct list { char data; list *next; }; list *creat( ) { list *h,*p,*q; char ch; h= (1) ; p=q=h; cin>>ch; while (ch!=’?’) { p= (2) ; p->data=ch; q->next=p; q=p; cin>>ch; } p->next=null; (3) ; }

(补充)3.6 链表的插入及有序链表的建立随堂测验

1、若已建立以下链表结构,指针p,s分别指向图中所示的结点,则不能将s所指的结点插入到链表末尾的语句组是:
    a、s->next=null; p=p->next; p->next=s;
    b、p=p->next; s->next=p->next; p->next=s;
    c、p=p->next; s->next=p; p->next=s;
    d、p=(*p).next; (*s).net=(*p).next; (*p).next=s;

2、有定义: struct node { int num; node *next; } *head, *p; 假定head是一链表首指针,则欲将p指向的结点插入到该链表首部,应做的操作是 。

第4章 函数

4.7 函数模板随堂测验

1、下列程序运行结果是 。 template t f(t *a, t *b, int n) { t s=(t)0; for(int i=0;i
2、下列程序运行结果是 。 template t fun ( t* a , t* b , int n) { t s= ( t)0; for ( int i=0;i
4.9 编译预处理随堂测验

1、编译预处理包括()。
    a、构造工程文件
    b、语句注释
    c、宏定义、文件包含和条件编译
    d、编译源程序

2、预处理命令不具有如下特点:
    a、均以“#”开头
    b、必在程序开头
    c、后面不加分号
    d、在真正编译前处理

3、设有以下宏定义 #define mod(x, y) x%y 则执行语句:int z, a=5, b=10; z=mod(b 3, a); cout<    a、5
    b、3
    c、13
    d、14

4、设有以下宏定义和语句: #define p(x, y) x/y #define pp(a, b) a*b int c=p(2 3, 2 3) pp(2 3, 2 3); 则变量c的值是()。
    a、26
    b、17
    c、17.5
    d、31

5、下面程序的运行结果是()。 #include using namespace std; #define sub(x, y) (x)*y void main() { int a=3, b=4; cout<    a、12
    b、15
    c、16
    d、20

6、假设有宏定义: #define num 15 #define dnum num num 则表达式dnum/2 num*2的值为()。
    a、45
    b、67
    c、52
    d、90

第4章 函数 测验

1、在c 语言的函数体中,下面说法正确的是()。
    a、可以定义和调用其他函数
    b、可以调用但不能定义其他函数
    c、不可调用但可以定义其他函数
    d、不可调用及定义其他函数

2、以下说法中,正确的是()
    a、c 语言程序总是从第一个定义的函数开始执行
    b、在c 语言程序中,要调用的函数必须在main()函数中定义
    c、c 语言程序总是从main()函数开始执行
    d、c 语言程序中的main()函数必须放在程序的开始部分

3、以下关于函数参数的说法,不正确的是()。
    a、函数调用时,先将实参的值按照位置传递给对应的形参。
    b、实参与形参的个数及顺序不必一一对应。
    c、实参与形参的名字可以相同。
    d、c 支持两种参数传递:传值和传引用。

4、以下关于引用的说法,正确的是()。
    a、引用其实是定义了一个新的变量。
    b、通过引用做参数,可以修改调用函数中变量的值。
    c、如果函数具有多个引用参数,则只需在第一个引用变量前加符号&。
    d、如果函数f的形参是引用,主调函数在调用f时,实参可以是一个值。

5、以下关于函数的返回值,不正确的说法是()。
    a、一个函数可以有多个参数,多个返回值。
    b、一个函数通过return语句最多只能返回一个值。
    c、如果一个函数的返回值类型不是void,那么该函数必须包含return语句。
    d、如果一个函数有返回值,则必须在函数头中指定返回值类型。

6、以下程序的运行结果是()。 #include using namespace std; int swap(int x, int y, int z) { int t; t=x; x=y; y=t; z=x*y; x=x*x; y=y*y; return z; } void main( ) { int x=50, y=20, z=0; x=swap(x, y, z); cout<<"x="<第4章 函数 作业

1、求出5~100之间的所有素数,要求每行输出5个素数。判断一个整数是否为素数用一个函数int prime(int x)来实现。

2、通过重载实现求两个数中大数的函数max(x, y),编写一个程序,实现分别求两个实数和两个整数中的大数。

第5章 类与对象

第5章 类与对象 测验

1、以下有关对象的叙述中,不正确的是()。
    a、产生对象时必定要调用构造函数
    b、撤销对象是必定要调用析构函数
    c、对象被保护,其私有成员不能任意访问
    d、对象可以没有构造函数或析构函数

2、以下关于构造函数和析构函数的叙述中正确的是()。
    a、析构函数和构造函数都可以重载
    b、构造函数可以重载,析构函数不能重载
    c、析构函数可以重载,构造函数不能重载
    d、构造函数和析构函数都不能重载

3、对下面的程序段下面的说法正确的是()。 class a { int x, y; public: a(int a, int b) { x=a; y=b;} void show() { cout<    a、编译时报错,程序无法运行
    b、编译无错,运行正常,输出3,5
    c、编译无错,运行时报错
    d、编译时报警告错,但运行正常,输出3,5

4、下列关于类的构造函数和析构函数的说法中,不正确的是()。
    a、类的析构函数可以重载
    b、类的构造函数可以重载
    c、定义一个类可以不显式定义构造函数
    d、定义一个类可以不显式定义析构函数

5、下列程序的运行结果是 。 class stack{ char * sp ; public : stack( ){ sp = new char[100] ; strcpy(sp , "i love china") ; cout << "在构造函数中! \n" ; } ~stack( ){ cout << sp << endl ; delete [ ]sp ; cout << "在析构函数中! \n" ; } } ; void main( ) { stack s ; }

6、下列程序运行结果是 。 #include using namespace std; class sac{ int n; public: sac(): n(4) { cout<
7、下列程序运行结果是 。 class people{ int x , y ; public : people( ){ cout << "default constructor \n"; x=y=0 ; cout << " one \n" ; } people( int i ){ x=i ; y=0 ; cout << "constructor \n"; cout << " two \n" ; } ~people( ) { cout << "destructor \n" ; } void print( ) { cout << x << setw(5) << y << endl ; } } ; void main( ) { people *ptr ; ptr=new people[2] ; ptr[0]=people( ) ; ptr[1]=people(3) ; for( int i=0 ; i<2 ; i ) ptr[i].print( ) ; delete [ ]ptr ; }

8、下列程序运行结果是 。 #include #include class invitem { char *desc; int units; public: invitem(int size = 51) { desc = new char[size]; strcpy(desc, "c"); units = 0; } invitem(char *d, int u=0) { desc = new char [strlen(d) 1]; strcpy(desc, d); units = u; } ~invitem( ) { delete [ ]desc; } char *getdesc( ) { return desc; } int getunits( ) { return units; } }; void main(void) { invitem inventory[3] = { invitem("a", 10),invitem("b") }; for(int index = 0; index < 3; index ) { cout << inventory[index].getdesc( ); cout << inventory[index].getunits( ) <
9、下列程序的运行结果是 。 class test{ int num; public: test(int n=6){ num=n; } int getnumber( ) { return num; } ~test( ){ cout<<"in destructor!"<
10、下列程序的运行结果是 。 #include class item{ char name[20]; int count; public: item(char *n="space",int c=0){ strcpy(name,n); count=c; cout<<"in constructor! "<
第5章 类与对象 作业

1、定义一个复数类complex ,数据成员包括实部和虚部。成员函数包括:(1)设置实数值;(2)设置虚部值。(3)取实部值;(4)取虚部值。(5)输出复数。在主函数中定义一个复数类对象,然后对所有成员函数进行测试。

第6章 共享与数据保护

第6章 共享与数据保护 测验

1、下列关于静态数据成员的描述中,错误的是()。
    a、说明静态数据成员时,前面要加修饰符static
    b、静态数据成员要在类外进行初始化
    c、引用静态数据成员时,要在静态数据成员名前加<类名>和作用域运算符
    d、静态数据成员不是所属类的所有对象共有的

2、关于成员函数的描述中,错误的是()。
    a、成员函数一定是内联函数
    b、成员函数可以重载
    c、成员函数可以设置参数的缺省值
    d、成员函数可以是静态的

3、下面关于友元函数的说法中,正确的是()。
    a、允许在类外访问类中除私有成员以外的任何成员
    b、允许在类外访问类中的任何成员
    c、友元函数也是该类的成员函数
    d、友元函数的定义必须被放在该类的公有部分

4、下面关于友元函数的描述中,错误的是()。
    a、友元函数不是成员函数
    b、友元函数加强了类的封装性
    c、在友元函数中可以访问所属类的私有成员
    d、友元函数的作用是提高程序的运行效率

5、复数类定义如下: class complex { private: float real;//实部 float img; //虚部 public: complex (float x=0, float y=0){real=x, img=y;} complex (complex &c){real=c.real; img=c.img;} }; 若 complex c1(3, 5); //a complex c2; //b complex c3(c1); //c c2=c1; //d 则下列说法正确的是()。
    a、a行调用了拷贝构造函数
    b、b行调用了拷贝构造函数
    c、c行调用了拷贝构造函数
    d、d行调用了拷贝构造函数

6、下列程序运行结果是 。 #include class grade { public: static int num; grade () { num ;} }; int grade::num=7; void main() { cout<<" grade::num="<< grade::num <
7、下列程序运行结果是 。 #include class e{ int x; static int y; public: e(int a) {x=a; y =x;} void show() { cout<
8、下列程序运行结果是 。 #include class test { public: test() { cnt ; } static int count() { return cnt;} private: static int cnt; }; int test::cnt = 0; void main() { cout << test::count() <<' '; test t1, t2; cout << t1.count() <<' '; }

9、下列程序运行结果是 。 class test { public: test( ) { n =2; } ~test( ) { n-=3; } static int getnum( ) { return n; } private: static int n; }; int test::n = 1; void main( ) { test* p = new test; delete p; cout << "n=" << test::getnum( ) << endl; }

10、下列程序运行结果是 。 class ctest { private: static int count; public: ctest(){ count;} ~ctest(){cout<<--count<<"object existn";} static int getcount(){return count;} }; int ctest::count=0; void main() { cout<getcount()<<"object exist\n"; delete ptest2; cout<
11、采用赋值运算符“=”可以将一个对象赋值给另外一个对象,或者采用一个对象初始化另外一个对象。在缺省情况下,这两个操作执行的是 。

12、下列程序运行结果是 。 class point{ double x,y; public: point(double xx=0, double yy=0) { x=xx; y=yy; cout<<"构造函数("<
13、下列程序运行结果是 。 class student { int score ; static int count ; public : student ( int n=0) { score =n ; count ; } student (student &p) { score =p. score ; count ;} ~student ( ) { cout<<"the number of the students: "<<--count<< endl; } void showscore( ) {cout<
第6章 共享与数据保护 作业

1、1. 设计一个人员类person,有姓名:char name[20],年龄:int age两个数据成员,还有一个静态数据成员int counter以描述人员总数。 1) 设计构造函数实现人员的姓名和年龄设置及人员总数加1; 2) 设计一个静态成员函数showcounter(),显示人员总数,并设计其它必要的非静态成员函数; 3) 定义函数showname()、showage()显示人员姓名和年龄; 编写主函数演示上述功能。

2、已知类string的定义为: class string { private: char *data; // 用于保存字符串 public: string( char *str = null); // 构造函数 string( string &other); // 拷贝构造函数 ~ string( ); // 析构函数 }; 请在类外完成string的上述3个函数:构造函数、拷贝构造函数和析构函数的编写。

第7章 数组

第7章 数组 测验

1、下列数组定义中错误的是()。
    a、char s1[‘a’];
    b、char s2[6] = “string”;
    c、static int a[4] = {1};
    d、char p[] = {‘a’, ‘b’, ‘c’}

2、若有定义:int a[4]={1};则下面正确的叙述是()。
    a、只有元素a[0]可得到初值1,其余元素的值不确定。
    b、该语句有错误。
    c、元素a[0]可得到初值1,其余元素的值均为0。
    d、数组a中各元素都可得到初值1。

3、下列程序的运行结果是()。 #include using namespace std; void main() { int n[3]=, i, j, k=2; for( i=0; i    a、2
    b、1
    c、0
    d、3

4、以下程序的输出是()。 #include using namespace std; void main( ) { int a[3][4]={1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23}; int i, j, k=0; for(i=0; i<3; i ) for(j=0; j<2; j ) k=k a[i][j]; cout<    a、60
    b、66
    c、83
    d、144

5、定义变量和数组:int i, j; int a[3][3]={1, 2, 3, 4, 5, 6, 7, 8, 9}; 则下面语句的输出结果是()。 for( i=0; i<3; i ) for( j=i; j<=i; j ) cout<    a、3 5 7
    b、3 6 9
    c、1 5 9
    d、1 4 7

6、关于字符’\0’,不正确的说法是()。
    a、常用来作为字符串的结束标志
    b、在计算机中存储时占一个字节的内存
    c、是空格字符的转义表示形式
    d、作为逻辑值使用时等价于逻辑“假”

7、下述对c 语言字符数组的描述中错误的是()。
    a、字符数组可以存放字符串
    b、字符数组中的字符串可以整体输入和输出
    c、可以在赋值语句中通过赋值运算符“=”对字符数组整体赋值
    d、不可以用关系运算符对字符数组中的字符串进行比较

8、下面程序的运行结果是()。 #include using namespace std; #include void main() { char p1[10] = “abc”, p2[]= “abc”, str[50]= “xyz”; strcpy(str 2, strcat(p1, p2)); cout<    a、xyzabcabc
    b、zabcabc
    c、yzabcabc
    d、xyabcabc

9、下列程序的运行结果是 。 #include using namespace std; void main() { int arr[10], i, k=0; for( i=0; i<10; i ) arr[i]=i; for( i=1; i<4; i ) k =arr[i] i; cout<
10、下列程序的运行结果是 。 #include using namespace std; void main() { int i, j, y=122, a[8]; for( i=0; y; i ) { a[i]=y%8; y=y/8; } for( j=i-1; j>=0; j--) cout<
11、以下程序输出结果是 。 #include using namespace std; void main( ) { int a[4]={5, 9, 19, 32768}; int b[6]={12, 24, 26, 37, 48, 32768}; int c[10], i=0, j=0, k=0; while( i<3 || j<5 ) if( a[i]>b[j]) { c[k]=b[j]; k ; j ; } else { c[k]=a[i]; k ; i ; } for( i=0; i
12、设有定义:int x[4][3]={3, 4, 5, 6, 7, 8, 9, 10, 11,12};则x[3][0]的值为 。

13、以下程序的功能是求二维数组周边元素之和,算法是:用“全体元素之和”减去“内部元素之和”,请完善程序。 #include using namespace std; void main( ) { int a[4][5]={1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5}; int i, j, sum1, sum2; ; for(i=0; i<4; i ) for(j=0; j<5; j ) sum1 =a[i][j]; for( ; ; i ) for( ; ; j ) sum2 =a[i][j]; cout<<"周边元素之和为:"<<(sum1 - sum2)<
14、设有语句:int a[10]; 则a的值是 。

15、下列程序的运行结果是 。 #include using namespace std; float f (float sum, float x[ ], int n) { for( int i=0; i
16、下列程序的运行结果是 。 #include using namespace std; int f (int b[ ], int n) { int i, r=1; for( i=0; i<=n ; i ) r=r*b[i]; return r; } void main() { int x, a [] = { 2, 3, 4, 5, 6 ,7, 8, 9 }; x=f(a, 3); cout<
17、以下程序调用函数,用选择法对数组中的值按降序排序,请完成程序。 #include using namespace std; void sortd( ,int n) { int i, j, p, t; for(i=0; ia[p] ) p=j; if(p!=i) { t=a[i]; a[i]=a[p]; a[p]=t; } } } void main( ) { int a[10]; for( int i=0; i<10; i ) cin>>a[i]; sortd(a, 10); for( i=0; i<10; i ) cout<
18、函数findmax返回数组s中最大元素的下标,数组元素个数由t传入,请完善下列程序。 int findmax (int s[ ], int t) { int k, p; for( p=0, k=p; ps[k]) ; return k; }

19、下列程序的运行结果是 。 #include using namespace std; #include void fun(char str[ ]) { int i, j; for( i=0, j=0; str[i] ; i ) if(isalpha(str[i])) str[j ]=str[i]; str[j] = ‘\0’; } void main() { char ss[80] = “it is!”; fun(ss); cout<
20、设有定义:char s[] = “rep\0ch”; int m=sizeof(s), n=strlen(s);则m和n的值为 。

21、设char s1[10], *s2= “ab\0cded”, 执行strcpy(s1, s2)后,cout<
22、下列程序的运行结果是 。 #include using namespace std; char *fun(char *str, char c) { while ( *str!=’\0’) if(*str==c) return (str); else str ; return (null); } void main() { char s [80] = “warrior”, *p; p=fun(s, ‘r’); if(p) cout<
23、函数char * itoa ( int n, char *s)将整数n变换成对应的十进制数的字符串并存放到s所指向的串空间中。例如,若n为782,则结果将字符串 “782”存放到s指向的串空间,返回结果串的起始地址。 char *itoa(int n, char *s) { int i=0, j, t; while (n) { s[i]= ; n=n/10; i ; } s[i]= ‘\0’; for(j=0; j
第7章 数组 作业

1、编写一个程序,判定一个字符串是否是另一个字符串的子串,若是,则返回子串在主串中的位置,要求不能使用系统函数。

2、编写一个函数,求二维数组的两条对角线元素之和。

第8章 指针

8.3 指针与二维数组随堂测验

1、若有int (*p)[3];以下叙述中正确的是()。
    a、p是一个指针数组
    b、(*p)[3]与*p [3]等价
    c、p是一个指针,它可以指向一个一维数组中任一个元素
    d、p是一个指针,它只能指向一个包含3个int类型元素的一维数组

2、对以下程序,说法正确的是()。 #include using namespace std; void main( ) { int a[4][4]={ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}, sum=0; int (*p)[4]=a; //a p=p 2; for( int i=0; i<2; i ) for(int j=0; j<2; j ) sum =p[i][j]; //b cout<    a、程序输出 14
    b、程序中a行有错
    c、程序输出 46
    d、程序中b行有错

3、以下程序的输出结果是()。 #include using namespace std; int a[3][3]={ {2}, {4}, {6}}; void main( ) { int i, *p=&a[0][0]; for(i=0; i<2; i ) { if(i==0) a[i][i 1]=*p 1; else p; cout<<*p; } }
    a、23
    b、26
    c、33
    d、36

4、以下程序的输出结果是()。 #include using namespace std; void main( ) { int a[3][4]={ 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23}, (*p)[4]=a; int i, j, k=0; for(i=0; i<3; i ) for(j=0; j<2; j ) k=k *(*(p i) j); cout<    a、60
    b、68
    c、99
    d、108

5、以下程序的输出结果是 。 #include using namespace std; void main( ) { int a[ ][4]={ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; cout<<**a<<'\t'; cout<<*(a[1] 2)<<'\t'<<*(*(a 2) 2)<<'\n'; }

8.6 指针数组与指向指针的指针随堂测验

1、以下程序的输出结果是()。 #include using namespace std; void main( ) { int a[5]={2, 4, 6, 8, 10}, *p, **k; p=a; k=&p; cout<<(*(p ))<<'\t'; cout<<(**k)<    a、2 2
    b、2 4
    c、4 4
    d、4 6

2、下面程序的运行结果是 。 #include using namespace std; void main( ) { char *p[]={ “bool”, “opk”, “h”, “sp”}; int i; for (i=3; i>=0; i--, i--) cout<<*p[i]; cout<
3、若下面程序所在的源文件名为abc.cpp,编译后,在dos状态下执行命令行: abc file1 file2,则其运行结果是 。 #include using namespace std; void main(int argc, char *argv[] ) { int i; cout<
4、假设有:char *argv[]={ “hello”, “nanjing”, “jiangsu”}; char **pargv=argv; 则请给出下列语句的输出结果: cout<<*(pargv 1); 结果为 。 cout<
第8章 指针 测验

1、有定义:char s1[20] = "hello", s2[20] = "china"; const char *ptr = s1; 则以下四种操作中,错误的是()。
    a、strcpy(s2, ptr);
    b、ptr = s2;
    c、ptr = ptr 10;
    d、*ptr = *s2;

2、如果以下程序第一行输出结果为0x65fdb0,则第二行输出是()。 #include using namespace std; void main( ) { int a[10]={ 1, 2, 3, 4, 5, 6, 7, 8, 9, 0}, *p=a; cout<    a、0x65fdc8
    b、0x65fdd4
    c、0x65fdb9
    d、0x65fde6

3、下列程序的运行结果是()。 #include using namespace std; void main( ) { int a[]={2, 4, 6, 8, 10}, y=1, x, *p=&a[1]; for( x=0; x<3; x ) y =*(p x); cout<    a、17
    b、18
    c、19
    d、20

4、若有int (*p)[3];以下叙述中正确的是()。
    a、p是一个指针数组
    b、(*p)[3]与*p [3]等价
    c、p是一个指针,它可以指向一个一维数组中任一个元素
    d、p是一个指针,它只能指向一个包含3个int类型元素的一维数组

5、对以下程序,说法正确的是()。 #include using namespace std; void main( ) { int a[4][4]={ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}, sum=0; int (*p)[4]=a; //a p=p 2; for( int i=0; i<2; i ) for(int j=0; j<2; j ) sum =p[i][j]; //b cout<    a、程序输出 14
    b、程序中a行有错
    c、程序输出 46
    d、程序中b行有错

6、以下程序的输出结果是()。 #include using namespace std; int a[3][3]={ {2}, {4}, {6}}; void main( ) { int i, *p=&a[0][0]; for(i=0; i<2; i ) { if(i==0) a[i][i 1]=*p 1; else p; cout<<*p; } }
    a、23
    b、26
    c、33
    d、36

7、以下程序的输出结果是()。 #include using namespace std; void main( ) { int a[3][4]={ 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23}, (*p)[4]=a; int i, j, k=0; for(i=0; i<3; i ) for(j=0; j<2; j ) k=k *(*(p i) j); cout<    a、60
    b、68
    c、99
    d、108

8、下列函数的功能是()。 int fun1(char *x) { char *y=x; while(*y ); return (y-x-1); }
    a、求字符串的长度
    b、比较两个字符串的大小
    c、将字符串复制到字符串y
    d、将字符串x直接接到字符串y的后面

9、设有语句:void f(int a[10], int &x); int y[10], *py=y, n; 则对函数f的正确调用语句是()。
    a、f(py[10], n);
    b、f(py, n);
    c、f(*py, &n);
    d、f(py, &n);

10、以下程序输出是()。 #include using namespace std; void prtv(int *x) { cout<<( *x)<    a、23
    b、24
    c、25
    d、26

11、以下程序输出是() #include using namespace std; #include void fun(char *w, int m) { char s, *p1, *p2; p1=w; p2=w m-1; while( p1    a、ihgfedc
    b、chbbhci
    c、chbbgbh
    d、chhfchi

12、设有以下语句: int add(int a, int b); int fun(int (*p)(int, int), int &a, int &b); int x, y, (*f)(int, int)=add; 则对函数fun的正确调用形式是()。
    a、fun(f, x, y)
    b、fun(f, &x, &y)
    c、fun((*f)(x, y), x, y)
    d、fun(add, &x, &y)

13、以下程序的输出结果是()。 #include using namespace std; void fun(float *p1, float *p2, float *s) { s = new float; *s=*p1 *(p2 ); } void main( ) { float a[2]={1.1, 2.2}, b[2]={10.0, 20.0}, *s=a; fun(a, b, s); cout<<(*s)<    a、11.1
    b、12.1
    c、21.1
    d、1.1

14、运算符“&”有三种含义,分别是 、 和 。

15、若有int a[10], *p, i=5; p=a i; 则p的内容为 , *p的内容为 。

16、如果从键盘输入字符串 “how do you do”,则下面程序的运行结果是 。 #include using namespace std; void main( ) { char str1[]= “how do you do”, str2[10], *p1=str1, *p2=str2; cin>>p2; cout<
17、以下程序的输出是 。 #include using namespace std; void swap(int *p1; int *p2) { int *t; t=p1; p1=p2; p2=t; } void main( ) { int a=3, b=5, *p1=&a, *p2=&b; swap(p1, p2); cout<<*p1<<*p2<
18、以下程序输出结果是 。 #include using namespace std; char * fun(char *str, char c) { while(*str!='\0') if(*str==c) return str; else str ; return null; } void main( ) { char s[ ]="warrior"; char *p; p=fun(s, 'r'); if(p) cout<
第8章 指针 作业

1、在主函数中定义一个含有12个指针的指针数组,令它的数组元素分别指向12个由月份组成的字符串常量,如第0个元素指向”january”。在主函数中,若输入月份整数值,则从上述指针数组中找到并输出相应月份的字符串值。

第9章 继承与派生

第9章 继承与派生 测验

1、设类b是基类a的派生类,并有语句a a1, *pa=&a1; b b1, *pb=&b1; 则正确的语句是()。
    a、pb=pa;
    b、b1=a1;
    c、a1=b1;
    d、*pb=*pa;

2、派生类对象可直接访问基类中的();在派生类的成员函数中,不可以直接访问的是()。
    a、公有继承的公有成员
    b、公有继承的私有成员
    c、公有继承的保护成员
    d、私有继承的公有成员

3、在c 中,三种派生方式的说明符号为 ,若不加说明,则默认的派生方式为 。

4、下列程序运行结果是 。 class a{ public: a(){cout<<"1";} ~a(){cout<<"2";} }; class b:public a { public: b(){cout<<"3";} ~b(){cout<<"4";} }; void main() { b b; }

5、下列程序运行结果是 。 class a { public: a(){cout<<"a";} ~a(){cout<<"~a";} }; class b:public a { a *p; public: b(){ cout<<"b"; p=new a(); } ~b(){ cout<<"~b"; delete p; } }; void main() { b obj; }

6、下列程序运行结果是 。 #include class base{ char c; public: base(char n) { c=n; cout<
7、下列程序运行结果是 。 class a { public: a(char *nm){cout <
第9章 继承与派生 作业

1、定义猫科动物animal类,由其派生出猫类(cat)和豹类(leopard),二者都包含虚函数 sound( ),要求根据派生类对象的不同调用各自重载后的成员函数。

第10章 多态性与虚函数

10.11 类模版随堂测验

1、下列程序运行结果是 。 template class ff { tt a1,a2,a3; public : ff(tt b1,tt b2,tt b3) { a1=b1; a2=b2; a3=b3; } tt sum() { return a1 a2 a3; } }; void main() { ff x(2,4,6),y(5,7,9); cout <
2、下列程序运行结果是 。 # include template class ff { tt x,y; public : ff(tt a,tt b) { x=a; y=b;; } tt sub() { return x-y; } }; void main() { ff f(6,4); cout <
第10章 多态性与虚函数 测验

1、下面有关运算符重载的说法中,正确的是()。
    a、非静态成员函数重载运算符时带有this指针
    b、友元函数重载运算符时带有this指针
    c、成员函数与友元函数重载运算符时都不带有this指针
    d、用成员函数或友元函数重载同一运算符时,两者的参数类型与参数个数相同

2、成员函数中重载运算符“ ”,实现a b运算,则()。
    a、a必须为对象,b可为整数或实数
    b、a和b必须为对象
    c、b必须为对象,a可为整数或实数
    d、a和b均为整数或实数

3、cin是istream_withassign类的对象,>>是用友元函数实现的重载运算符,若有int x; cin>>x; 则编译器将 cin>>x解释成对运算符重载函数的调用,形式是()。
    a、cin.operator>>(cin, x)
    b、operator>>(cin, x)
    c、cin.operator>>(x)
    d、operator>>(x)

4、下列关于类型转换运算符重载的说法中,不正确的是()。
    a、类型转换运算符重载函数无返回值类型
    b、类型转换运算符重载函数有返回值类型
    c、类型转换运算符重载函数不能有参数
    d、类型转换运算符重载函数只能用成员函数实现,不能用友元函数实现

5、下列关于运算符重载的说法中,正确的是()。
    a、运算符重载可以改变操作数的个数
    b、运算符重载可以改变优先级
    c、运算符重载可以改变结合性
    d、运算符重载不可以改变语法结构

6、c 中下列哪个运算符不允许被重载()。
    a、%=
    b、&&
    c、new
    d、*

7、以下有关函数重载的说法正确的是()。
    a、重载函数的函数名可以不同,但其实现的功能必须相同。
    b、完成不同功能的函数可以具有相同的函数名,而且其参数的个数和类型也必须相同。
    c、完成不同功能的函数可以具有相同的函数名,但必须具有不同的返回值类型。
    d、完成不同功能的函数可以具有相同的函数名,但必须具有不同的参数个数或不同的参数类型。

8、下列程序运行结果是 。 class test{ long x; static int num; public: test (long m=0) {x=m;} test operator (); test operator (int); void show() { cout<<"the num is: "<
11、下列程序运行结果是 。 #include class complex { double real, img; public: complex(double r=0, double i=0) { real=r; img=i; } operator double() { return real; } }; void main() { complex c(3, 2); double x; x=c; cout<<”x=”<
12、下列程序运行结果是 。 #include class a { public: void fun(){cout<< “a::fun”<fun(); b.fun(); }

13、下列程序运行结果是 。 #include class a { public: virtual void fun(){cout<< “a::fun”<fun(); b.fun(); }

14、若定义了一个类,该类只能用作基类,而不能定义该类的对象,这种类被称为 。

15、下列程序运行结果是 。 class a1 {public: a1(int i) {cout<<" a1的构造函数 "<
第10章 多态性与虚函数 作业

1、定义一个日期类date,数据成员包括年、月、日,构造函数实现年、月、日的初始化,setdate(int y,int m,int d)和printdate()函数分别用于设置日期和显示日期;再定义一个时间类time,数据成员包括时、分、秒,构造函数实现时、分、秒的初始化,settime(int h,int m,int s)和printtime()函数分别用于设置时间和显示时间,在此基础上再定义一个日期时间类timedate,充分利用已有的两个类,并编写主函数完成基类和派生类的测试工作。

第12章 流类体系与文件操作

12.7 随机访问文件随堂测验

1、假设文本文件中已经存有“ilovechina”九个字符,则下列程序的运行结果是 。 void main(void) { fstream file("letters.txt",ios::in); char ch; if (!file) exit(0); file.seekg (1l, ios::beg); file.get(ch); cout << ch << endl; file.seekg (-4l, ios::end); file.get(ch); cout << ch << endl; file.seekg (2l, ios::cur); file.get(ch); cout << ch << endl; file.close( ); }

2、假设文本文件letters.txt中已经存有“1234567890”十个字符,则下列程序的运行结果是 。 #include #include void main(void) { fstream file("nums.txt",ios::in); char ch; if (!file) exit(0); file.seekg (1l, ios::beg); file.get(ch); cout << ch << endl; file.seekg (-5l, ios::end); file.get(ch); cout << ch << endl; file.seekg (-2l, ios::cur); file.get(ch); cout << ch << endl; file.close( ); }

3、文本文件letters.txt中已经存有“abcdefg”七个字符,则下列程序的运行结果是 。 #include #include void main(void) { fstream file("letters.txt",ios::in); char ch; if (!file) exit(0); file.seekg (2l, ios::beg); file.get(ch); cout << ch ; file.seekg (-3l, ios::end); file.get(ch); cout << ch ; file.seekg (1l, ios::cur); file.get(ch); cout << ch << endl; file.close( ); }

第12章 流类体系与文件操作 测验

1、在c 的文件流中,打开文件的方法有两种,一种是使用成员函数open(),另一种是使用 。

2、假设文本文件中已经存有“ilovechina”九个字符,则下列程序的运行结果是 。 void main(void) { fstream file("letters.txt",ios::in); char ch; if (!file) exit(0); file.seekg (1l, ios::beg); file.get(ch); cout << ch << endl; file.seekg (-4l, ios::end); file.get(ch); cout << ch << endl; file.seekg (2l, ios::cur); file.get(ch); cout << ch << endl; file.close( ); }

3、假设文本文件letters.txt中已经存有“1234567890”十个字符,则下列程序的运行结果是 。 #include #include void main(void) { fstream file("nums.txt",ios::in); char ch; if (!file) exit(0); file.seekg (1l, ios::beg); file.get(ch); cout << ch << endl; file.seekg (-5l, ios::end); file.get(ch); cout << ch << endl; file.seekg (-2l, ios::cur); file.get(ch); cout << ch << endl; file.close( ); }

4、文本文件letters.txt中已经存有“abcdefg”七个字符,则下列程序的运行结果是 。 #include #include void main(void) { fstream file("letters.txt",ios::in); char ch; if (!file) exit(0); file.seekg (2l, ios::beg); file.get(ch); cout << ch ; file.seekg (-3l, ios::end); file.get(ch); cout << ch ; file.seekg (1l, ios::cur); file.get(ch); cout << ch << endl; file.close( ); }

第12章 流类体系与文件操作 作业

1、人工预先创建一个文本文件data.txt,其内容为若干实数,数据之间以空白字符分隔。编程从该文件中读入这些实数,统计实数个数并求出这些实数的平均值,在程序中创建并产生一个文本文件result.txt,内容为 data.txt 中的全体实数,每行5个数,最后一行输出实数个数以及平均值。

期末考试

单选题和填空题

1、用c 语言编写的源程序要成为目标程序必须要经过( )。
    a、解释
    b、汇编
    c、编辑
    d、编译

2、在下列选项中,正确的字符常量为( )。
    a、"a"
    b、'name'
    c、a
    d、'\101'

3、c 语言中,运算符"="和"=="的功能分别是( )。
    a、关系运算和赋值运算
    b、赋值运算和关系运算
    c、都是关系运算
    d、都是赋值运算

4、为了避免在嵌套的条件语句if-else中产生二义性,c 语言规定,else子句总是与( )。
    a、其之前最近的if配对
    b、其之后最近的if配对
    c、同一行上的if配对
    d、缩排位置相同的if配对

5、关于break和continue语句,下列叙述正确的是( )。
    a、在循环体中可以用break语句结束本次循环
    b、在循环体中可以用continue语句结束本次循环
    c、break语句仅能使用在switch结构中
    d、可以使用continue语句跳出switch结构

6、下列有关函数重载的叙述中,错误的是______________。
    a、函数重载就是用相同的函数名定义多个函数。
    b、重载函数的参数列表必须不同。
    c、重载函数的返回值类型必须不同。
    d、重载函数的参数可以带有默认参数。

7、在vc中,若定义一个函数的返回类型为void,则以下叙述正确的是( )。
    a、函数返回值需要强类型转换
    b、函数不执行任何操作
    c、函数本身没有返回值
    d、函数不能修改实际参数的值

8、下列情况中,不会调用拷贝构造函数的是___________。
    a、用一个对象去初始化同一类的另一个新对象时
    b、将类的一个对象赋值给该类的另一个对象时
    c、函数的形参是类的对象,调用函数进行形参和实参结合时
    d、函数的返回值是类的对象,函数执行返回调用时

9、在类定义的外部,可以被访问的成员有( )。
    a、所有类成员
    b、private或protected的类成员
    c、public的类成员
    d、public或private的类成员

10、静态成员函数没有____________。
    a、返回值
    b、this指针
    c、指针参数
    d、返回类型

11、若用数组名作为调用函数的实参,则传递给形参的是( )。
    a、数组存储首地址
    b、数组的第一个元素值
    c、数组中全部元素的值
    d、数组元素的个数

12、关于动态存储分配,下列说法正确的是_______________。
    a、new和delete是c 语言中专门用于动态内存分配和释放的函数
    b、态分配的内存空间也可以被初始化
    c、当系统内存不够时,会自动回收不再使用的内存单元,因此程序中不必用delete释放内存空间
    d、当动态分配内存失败时,系统会立刻崩溃,因此一定要慎用new

13、建立一个有成员对象的派生类对象时,各构造函数体的执行次序为________________。
    a、派生类、成员对象类、基类
    b、成员对象类、基类、派生类
    c、基类、成员对象类、派生类
    d、基类、派生类、成员对象类

14、下列关于运算符重载的叙述中,正确的是___________。
    a、通过运算符重载,可以定义新的运算符。
    b、有的运算符只能作为成员函数重载。
    c、若重载运算符 ,则相应的运算符重载函数名是 。
    d、重载一个二元运算符是,必须声明两个形参。

15、语句ofstream f("salary.dat",ios_base::app);的功能是建立流对象f,并试图打开文件salary.dat与f关联,而且_______。
    a、若文件存在,将其置为空文件;若文件不存在,打开失败。
    b、若文件存在,将文件指针定位于文件尾;若文件不存在,建立一个新文件。
    c、若文件存在,将文件指针定位于文件首;若文件不存在,打开失败。
    d、若文件存在,打来失败;若文件不存在,建立一个新文件。

16、阅读下列程序,写出运行结果: #include using namespace std; void func( int, int, int * ); int main() { int x, y, z; func( 5, 6, &x ); func( 7, x, &y ); func( x, y, &z ); cout << x << "," << y << ", "<< z << endl; } void func( int a, int b, int *c ) { b = a; *c = b - a; } 正确答案: 6, 6, 6 39. 简答题 ( 1.0 分 ) 阅读下列程序,写出运行结果:#include using namespace std; void func( int, int, int & ); int main() { int x=0, y=1, z=2; func( 1, 2, x ); func( x y, y, y ); func( z, x y, z ); cout << x << "," << y << ", "<< z << endl; } void func( int a, int b, int &c ) { b = a; c = b - a; }

17、对象在逻辑上是相对独立的,每个对象都拥有自己的数据和函数。但是,在物理上,对象的数据成员是__________的,而类的成员函数却是共有的。

18、析构函数在对象的________时被自动调用。

19、如果不使用多态机制,那么通过基类的指针虽然可以指向派生类对象,但是只能访问从基类继承的成员。下面程序没有使用多态机制,其输出结果是_________________。 #include using namespace std; class base { public: void print(){cout<<"b";} }; class derived:public base { public: void print(){cout<<"d";} }; int main() { derived *pd=new derived(); base *pb=pd; pb->print(); pd->print(); delete pd; return 0; }

20、c 语言中的多态性分为编译时 的多态性和__________的多态性两种。

最新
192
2881
2236
1286
2785
1543
1918
2838
988
993
精选
中国大学mooc有机化学最新考试答案 730
1245
中国大学mooc断层解剖学最新考试答案 1852
1098
中国大学mooc有机化学最新考试答案 2269
1634
中国大学mooc能源与人类文明发展(2020小学期)最新考试答案 1376
1260
中国大学mooc听着音乐唱着歌,轻松快乐学地理最新考试答案 1025
2977
随机推荐
2477
367
514
904
713
2405
1946
2167
633
902
网站地图