面向对象的程序设计语言——C++第二版-习题参考答案
- 格式:doc
- 大小:49.00 KB
- 文档页数:18
C++面向对象程序设计习题解答与上机指导(第2版)习题参考答案源代码使用源程序的几点注意事项(1) 由于源程序在复制、编辑、解压缩等过程中可能引起部分符号(主要是标点符号,如分号、冒号、逗号、引号)的字体、半全角等发生变化,在编译时可能被检出语法错误,只要使用“替换”功能,纠正后即能顺利运行。
(2) 有的C++系统(如Visual C++6.0)没有完全实现C++标准,它所提供的不带后缀的.h 的头文件不支持友元运算符重载函数,在Visual C++6.0中编译会出错,这时可采用带后缀的.h头文件。
将程序中的#include<iostream>using namespace std;修改成#include<iostream.h>即可顺利运行。
第2章 C++基础【2.2】下面是一个C程序,改写它,使它采用C++风格的I/O语句。
#include<stdio.h>int main(){ int a,b,d,min;printf("Enter two numbers:");scanf("%d%d",&a,&b);min=a>b? b:a;for (d=2; d<min; d++)if (((a%d)==0)&&((b%d)==0)) break;if (d==min){ printf("No common denominators\n");return 0;}printf("The lowest common denominator is %d\n",d);return 0;}【解】#include<iostream>using namespace std;int main(){ int a,b,d,min;cout<<"Enter two numbers:";cin>>a;cin>>b;min=a>b? b:a;for (d=2; d<min; d++)if (((a%d)==0)&&((b%d)==0)) break;if (d==min){ cout<<"No common denominators\n";return 0;}cout<<"The lowest common denominator is "<<endl<<d;return 0;}【2.24】写出下列程序的运行结果。
c程序设计语言第二版答案【篇一:c语言程序设计现代方法(第二版)习题答案】answers to selected exercises2. [was #2] (a) the program contains one directive (#include) and four statements (three calls of printf and one return).(b)parkinsons law:work expands so as to fill the timeavailable for its completion.3. [was #4]#include stdio.hint main(void){int height = 8, length = 12, width = 10, volume;volume = height * length * width;printf(dimensions: %dx%dx%d\n, length, width, height);printf(volume (cubic inches): %d\n, volume);printf(dimensional weight (pounds): %d\n, (volume + 165) / 166);return 0;}4. [was #6] heres one possible program:#include stdio.hint main(void){int i, j, k;float x, y, z;printf(value of i: %d\n, i);printf(value of j: %d\n, j);printf(value of k: %d\n, k);printf(value of x: %g\n, x);printf(value of y: %g\n, y);printf(value of z: %g\n, z);return 0;}when compiled using gcc and then executed, this program produced the following output:value of i: 5618848value of j: 0value of k: 6844404value of x: 3.98979e-34value of y: 9.59105e-39value of z: 9.59105e-39the values printed depend on many factors, so the chance that youll get exactly these numbers is small.5. [was #10] (a) is not legal because 100_bottles begins with a digit.8. [was #12] there are 14 tokens: a, =, (, 3, *, q, -, p, *, p, ), /, 3, and ;.answers to selected programming projects4. [was #8; modified]#include stdio.hint main(void){float original_amount, amount_with_tax;printf(enter an amount: );scanf(%f, original_amount);amount_with_tax = original_amount * 1.05f;printf(with tax added: $%.2f\n, amount_with_tax);return 0;}the amount_with_tax variable is unnecessary. if we remove it, the program is slightly shorter:#include stdio.hint main(void){float original_amount;printf(enter an amount: );scanf(%f, original_amount);printf(with tax added: $%.2f\n, original_amount * 1.05f);return 0;}chapter 3answers to selected exercises2. [was #2](a) printf(%-8.1e, x);(b) printf(%10.6e, x);(c) printf(%-8.3f, x);(d) printf(%6.0f, x);5. [was #8] the values of x, i, and y will be 12.3, 45, and .6, respectively. answers to selected programming projects1. [was #4; modified]#include stdio.hint main(void){int month, day, year;printf(enter a date (mm/dd/yyyy): );scanf(%d/%d/%d, month, day, year);printf(you entered the date %d%.2d%.2d\n, year, month, day); return 0;}3. [was #6; modified]#include stdio.hint main(void){int prefix, group, publisher, item, check_digit;printf(enter isbn: );scanf(%d-%d-%d-%d-%d, prefix, group, publisher, item,check_digit);printf(gs1 prefix: %d\n, prefix);printf(group identifier: %d\n, group);printf(publisher code: %d\n, publisher);printf(item number: %d\n, item);printf(check digit: %d\n, check_digit);/* the five printf calls can be combined as follows:printf(gs1 prefix: %d\ngroup identifier: %d\npublishercode: %d\nitem number: %d\ncheck digit: %d\n,prefix, group, publisher, item, check_digit);*/return 0;}chapter 4answers to selected exercises2. [was #2] not in c89. suppose that i is 9 and j is 7. the value of (-i)/j could be either –1 or –2, depending on the implementation. on the other hand, the value of -(i/j) is always –1, regardless of the implementation. in c99, on the other hand, the value of (-i)/j must be equal to the value of -(i/j).9. [was #6](a) 63 8(b) 3 2 1(c) 2 -1 3(d) 0 0 013. [was #8] the expression ++i is equivalent to (i += 1). the value of both expressions is i after the increment has been performed. answers to selected programming projects2. [was#4]#include stdio.hint main(void){int n;printf(enter a three-digit number: );scanf(%d, n);printf(the reversal is: %d%d%d\n, n % 10, (n / 10) % 10, n / 100); return 0;}chapter 5answers to selected exercises2. [was #2](a) 1(b) 1(c) 1(d) 14. [was #4] (i j) - (i j)6. [was #12] yes, the statement is legal. when n is equal to 5, it does nothing, since 5 is not equal to –9.10. [was #16] the output isonetwosince there are no break statements after the cases.answers to selected programming projects2. [was #6]【篇二:c语言与程序设计-第2章课后习题参考答案】txt>关键字(是)注释空白符八进制常量(是)三字符序列字符串常量(是)括号(是)2.2 c编译器可将下列每一个源字符串分解为哪些记号?(不必考虑记号组合是否合法)(1) x+++y x, ++, +, y(2) -0xabl -, 0xabl(3) 2.89e+12l 2.89e+12l(4) string+\foo\ string+ \foo\(5) x**2 x, *, *, 2(6) x??/ x??/(7) a?ba, ?, b(8) x--+=y x, --, +=, y(9) intx=+10 intx, =, +, 10(10) stringfoo string, foo(这道题当时改的时候有几个小题改得有错误,注意!)2.3 下列哪些不是标识符,为什么?标识符由字母、数字和下划线组成,但首字符必须是字母或下划线。
c语言第二版课后习题答案C语言第二版课后习题答案C语言是一门广泛应用于计算机科学和软件开发领域的编程语言。
作为一门基础性的编程语言,掌握C语言对于学习其他高级编程语言以及深入理解计算机原理和操作系统等方面都具有重要意义。
而《C语言第二版》是一本经典的C 语言教材,对于初学者来说是一本非常好的入门教材。
在学习C语言过程中,课后习题是巩固知识、提高编程能力的重要环节。
下面,我将为大家提供一些C语言第二版课后习题的答案。
1. 编写一个C程序,实现两个整数相加并输出结果。
```c#include <stdio.h>int main() {int num1, num2, sum;printf("请输入两个整数:");scanf("%d %d", &num1, &num2);sum = num1 + num2;printf("两个整数的和为:%d\n", sum);return 0;}```2. 编写一个C程序,判断一个数是否为偶数。
```c#include <stdio.h>int main() {int num;printf("请输入一个整数:");scanf("%d", &num);if (num % 2 == 0) {printf("该数为偶数\n");} else {printf("该数为奇数\n");}return 0;}```3. 编写一个C程序,计算一个数的阶乘。
```c#include <stdio.h>int main() {int num, i;long long factorial = 1;printf("请输入一个整数:");scanf("%d", &num);if (num < 0) {printf("负数没有阶乘\n");return 0;}for (i = 1; i <= num; i++) {factorial *= i;}printf("%d的阶乘为:%lld\n", num, factorial);return 0;}```4. 编写一个C程序,判断一个数是否为素数。
c 程序设计第二版课后习题答案C程序设计第二版课后习题答案C程序设计是计算机科学与技术专业中一门重要的课程,它涉及到了计算机程序设计的基本概念、语法和技巧。
而《C程序设计第二版》是一本经典的教材,它通过丰富的例子和习题,帮助学生巩固和扩展他们的编程知识。
在学习这门课程时,课后习题是非常重要的一部分。
通过解答习题,我们可以更好地理解和掌握所学的知识,并且提高我们的编程能力。
然而,有时候我们可能会遇到一些困难,无法找到正确的答案。
因此,本文将为大家提供一些C程序设计第二版课后习题的答案,希望能对大家的学习有所帮助。
1. 第一章习题第一章主要介绍了C语言的基本概念和语法。
在习题中,我们需要编写一些简单的程序来练习基本的输入输出操作。
以下是一些可能的答案:```c#include <stdio.h>int main() {int num;printf("请输入一个整数:");scanf("%d", &num);printf("您输入的整数是:%d\n", num);return 0;}```2. 第二章习题第二章主要介绍了C语言的数据类型和运算符。
在习题中,我们需要编写一些程序来练习不同数据类型的使用和运算符的操作。
以下是一些可能的答案:```c#include <stdio.h>int main() {int a = 10;float b = 3.14;char c = 'A';printf("a + b = %f\n", a + b);printf("a * b = %f\n", a * b);printf("a / b = %f\n", a / b);printf("c + 1 = %c\n", c + 1);return 0;}```3. 第三章习题第三章主要介绍了C语言的控制结构,包括条件语句和循环语句。
《C语言程序设计(Visual C++6.0环境)》习题答案习题六一、思考题1、编写程序,将10个整形数2、4、6,…18,20赋给一个数组,然后使用指针输出显示该数组各元素的值。
#include “stdio.h”main(){int i,*p;int a[10]={2,4,6,8,10,12,14,16,18,20};p=a;for(i=0;i<10;i++)printf(“%3d”,*(p+i));}2、编写程序,将两个字符串连接起来。
#include<stdio.h>#define N 120main(){ char s1[N+N],s2[N],*p,*q;printf("输入2个字符串\n");scanf("%s%s",s1,s2);for(p=s1;* p!='\0'; p++);for(q=s2;*p++=*q++;);printf("两字符串连接后:%s\n",s1);}3、输入5个字符串,按英文字典排序从小到大顺序输出。
#include "stdio.h"#include "string.h"void sort(char *name[],int count){char *temp;int i,j,min;for(i=0;i<count-1;i++){min=i;for(j=i+1;j<count;j++)if(strcmp(name[min],name[j])>0)min=j;if(min!=i){temp=name[i];name[i]=name[min];name[min]=temp;}}}main(){char *name[5]={"BASIC","FORTRON","PASAL","C","FOXBASE"};int i=0;sort(name,5);for(;i<5;i++)printf("%s\n",name[i]);}4、编一程序,输入月份号,输出该月的英文月名。
C 程序设计教程第二版习题答案C 程序设计教程第二版习题答案C 程序设计是一门广泛应用于计算机科学和工程领域的编程语言,它具有高效、灵活和可移植等优点。
对于初学者来说,掌握C 程序设计的基本知识是非常重要的。
而《C 程序设计教程》是一本经典的教材,为学习者提供了一系列的习题来巩固所学知识。
本文将为大家提供《C 程序设计教程第二版》习题的答案,帮助大家更好地理解和掌握C 程序设计。
第一章:C 程序设计入门1.1 习题答案:1. 编写一个C程序,输出"Hello, World!"。
```c#include <stdio.h>int main() {printf("Hello, World!");return 0;}```1.2 习题答案:1. 编写一个C程序,输入两个整数,然后输出它们的和。
```c#include <stdio.h>int main() {int num1, num2, sum;printf("请输入两个整数:");scanf("%d %d", &num1, &num2);sum = num1 + num2;printf("两个整数的和为:%d", sum);return 0;}```第二章:C 程序设计基本要素2.1 习题答案:1. 编写一个C程序,输入一个字符,然后输出它的ASCII码。
```c#include <stdio.h>int main() {char ch;printf("请输入一个字符:");scanf("%c", &ch);printf("该字符的ASCII码为:%d", ch);return 0;}```2.2 习题答案:1. 编写一个C程序,输入一个整数,然后输出它的绝对值。
计算机程序设计基础C语言程序设计(第二版)习题解答习题一1.(1)00000000 00101101 (2)1000000000101101 (3)1111111111010011(4)65491 (5)0177723 (6)0xFFD32.11001000 0310 0xC83.(1) 00000000 00000000 00000000 10110010(2) 11111111 11111111 11111111 01001110(3)37777777516 (4)FFFFFF6D4.1100001101010000 0141520 0xC350习题二一、选择题DDCD BADA二、填空题1.字母或下划线 32个字符2. 字符串常量转义字符3. 65 974. 25. 06. 97. 2 4 4 8 18. 2 49. 24 10 60 0 0 010. sqrt((sin(3.14/3)+1)*(sin(3.14/6)+1)/cos(x)) 11. fabs(1-pow(x,3.6))12. (exp(x)+exp(-x))/2 13. 2.5 14. 3.5习题三一、单选题A C DB C二、填空题1.将x的值取出,加3后存回。
2. #include <stdio.h>3. 9,54.4.4三、编程题1.#include <stdio.h>#include <math.h>#define PI 3.1415926void main(){float a,b,c,s,jiaodu;printf(“shuru 2 bian yu jiajiao:”);scanf(“%f,%f,%f”,&a,&b,&jioadu);c=sqrt(a*a+b*b-2*a*b*cos(jiaodu*PI/180);s= a*b*sin(jiaodu*PI/180)/2;2. #include <stdio.h>void main(){float a;int b,c,d;printf(“shuru RMB(yuan):”);scanf(“%f”,&a);d=(int)(a*100)/5; c=(int)(a*100)%5/2;一、填空题1. 0 1 非0 02. 03. z>80 &&(x==100&&y>80||y==100&&x>80)二、按照输出格式写出以下程序的运行结果 21. a=1,b=0,c=02. a=8,b=8,c=103. y=0.5000004. 3三、编程题1. #include "stdio.h"main(){ char c;c=getchar();if (c= ='a' || c= ='A') printf("America");else if (c= ='b' || c= ='B') printf("Britain");else if (c= ='c' || c= ='C') printf("China");else printf("France");}2. #include <stdio.h>void main(){char c;c=getchar();switch (c){ case ‘a’:case ‘A’: printf(“America\n”);break;case ‘b’:case ‘B’: printf(“Britain\n”);break;case ‘c’:case ‘C’: printf(“China\n”);break;default: printf(“France\n”);}}一、 单选题C A C B B B二、 填空题1. 52. 63. 0 20三、 判断题四、 按照输出格式写出以下程序的运行结果1. ▫▫1▫▫2▫▫42. ▫▫7,▫▫8,▫423. 94. 38,6,3,5 五、 编程题4. #include <stdio.h>void main() { int rd,wr,bl,k=0; for(rd=0;rd<=3;rd++) { for(wr=0;wr<=3;wr++) { bl=8-rd-wr;if( bl>6) continue;k+=1;printf(“red=%d,write=%d,black=%d\n ”,rd,wr,bl); }}printf(“count=%d\n ”,k)k;}1. main() { int i; long fact,s; for (i=2;i<=10;i++) {fact=fact*(-1)*I;s=s+fact;} printf(“s=%ld ”,s);}一、 单选题ACAB ABCB二、 填空题1. float b[10]; 0 92. int a[10]={5,12,8,20,15}; 5 8 0 0 0 20 0 a[5]=10; scanf(“%d ”,&a[6]);for(i=0,i<10,i++) printf(“%d ”,a[i]);3. 0 44. 0 6三、 简答题int b[ ]={1,5,8,2,3}只有5个元素。
C++面向对象程序设计习题解答与上机指导(第二版)源程序c++面向对象程序设计习题解答与上机指导(第2版)练习参考答案源代码使用源程序的几点注意事项(1)由于在复制、编辑和解压源程序的过程中,某些符号(主要是标点符号,如分号、冒号、逗号和引号)的字体和半全角度可能会发生变化,因此在编译过程中可能会检测到语法错误。
只要使用“替换”功能,校正后可以平稳运行。
(2)有的c++系统(如visualc++6.0)没有完全实现c++标准,它所提供的不带后缀的.h的头文件不支持友元运算符重载函数,在visualc++6.0中编译会出错,这时可采用带后缀的.h头文件。
将程序中的#包括名称空间标准;改成#include即可顺利运行。
第2章C++基础【2.2】下面是一个c程序,改写它,使它采用c++风格的i/o语句。
#includeintmain(){inta,b,d,min;printf(\scanf(\min=a>b?b:a;对于(d=2;dif((a%d)==0)和((b%d)==0))中断;如果(d==min){printf (\return0;}Printf(\return0;}[solution]#includesingnamespacestd;intmain(){inta,B,D,min;cout<>A;CIN>>B;1min=A>B?B:A;for(D=2;dif((A%D)==0)和((B%D)==0))break;if(D==min){cout<cout<[2.24]写下下列程序的操作结果。
#运行结果:101请按任意键继续。
[2.25]写下以下程序的操作结果#包括NamespaceStd;voidf(int&m,intn){inttemp;temp=m;m=n;n=temp;}Intmain(){inta=5,B=10;f(a,B);cout<result:1010请继续[2.26]分析以下程序的输出结果。
C程序设计教程第二版习题答案第1章:C语言概述1. 简述C语言的特点。
- C语言是一种结构化编程语言,具有高效、灵活、功能强大等特点。
它支持多种编程范式,包括过程式、面向对象和泛型编程。
2. C语言的发展历史。
- C语言由丹尼斯·里奇在20世纪70年代初期开发,最初用于UNIX操作系统的编写。
随着UNIX的流行,C语言也逐渐普及。
第2章:C语言基础1. 变量声明的规则。
- 变量声明必须指定数据类型,变量名必须以字母或下划线开头,可以包含字母、数字和下划线,但数字不能作为变量名的首位。
2. 常量的使用。
- 常量是在程序执行过程中不能被修改的值,可以用#define预处理指令定义,或者直接使用字面量。
第3章:控制语句1. if语句的使用。
- if语句用于根据条件执行不同的代码块。
基本语法为:`if (条件) { 执行代码 }`。
2. switch语句的使用。
- switch语句用于根据变量的值执行不同的代码块。
基本语法为:`switch (变量) { case 值1: 执行代码1; break; ... }`。
第4章:循环语句1. for循环的使用。
- for循环用于重复执行一段代码直到满足特定条件。
基本语法为:`for (初始化; 条件; 增量/减量) { 执行代码 }`。
2. while循环的使用。
- while循环在条件为真时重复执行代码块。
基本语法为:`while (条件) { 执行代码 }`。
第5章:函数1. 函数的定义和调用。
- 函数是一段具有特定功能的代码块,可以被重复调用。
定义函数的基本语法为:`返回类型函数名(参数列表) { 函数体 }`。
调用函数时使用:`函数名(参数)`。
2. 函数的参数传递。
- 参数传递可以是值传递或引用传递。
值传递时,函数内部对参数的修改不会影响到外部变量的值;引用传递则相反。
第6章:数组1. 一维数组的声明和使用。
- 一维数组的声明语法为:`类型数组名[大小]`。
习题参考答案 第1章 C++语言概述 1.填空题 (1)函数说明,函数体 (2)声明区,主程序区,函数定义区 (3)多态性 (4)namespace,using (5)std (6)cin,>> (7)// (8)对数据的操作
2.判断题 (1)对 (2)错 (3)错 (4)错 (5)错
3.改错题 (1)没有函数体,应改为 void main() {}; (2)语句没有分号,应改为 using namespace myspace; (3)cout和操作符<功能,应改为 cout<<" Input your name:"; (4)应改为 #include
4.简答题 (略) 5.编程题 (略)
第2章 基本数据类型、运算符与表达式 1. 选择题 (1)B (2)D (3)B (4)D (5)B
2.简答题 (1)(a)、(c)(e)、(f)、(g)、(h)、(i) (2)(a)、(g)、(i)、(j) (3) (a)5.5 (b)0 (c)20 (d)0,0 (e)1 (f)1,2 (g)3 (h)-40 (i)2 (j)3 (k)s1>='0'&&s1<='9' (l)N!=0
3.读程序写结果 (1)0,15 (2)(1、1、1),(-1、-1、-1) (3) (a)a*a+2*a*b+b*b (b)4.0/3.0*3.1415926*R*R*R (c)5.0/9.0*(F-32) (d)b>=a&&b<=c (4) 36 41 43 (5) x=1
4.编程题 (略)
第3章 C++的控制语句 1.选择题 (1)B (2)A (3)A (4)C (5)A
2.判断题 (1)错 (2)对 (3)对 (4)错 (5)错
3.读程序写结果 (1) 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 (2) 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 1 2 3 4 5 4 3 2 1 (3) j的值为0; i的值为2;
4.编程题 (略)
第4章 函数 1. 填空题 (1)void (2)静态全局变量,static (3)函数重载 (4)inline (5)递归函数 (6)宏定义命令,文件包含命令,条件编译命令
2.判断题 (1)错 (2)错 (3)错 (4)错 (5)错 (6)对 (7)错 (8)错 (9)对 (10)对
3.读程序写结果 (1) x=7,y=4 x=9,y=5 (2) 34.56 101 (3) 16 22 28 (4) 12 15 18 21 24 (5) 2,1,4,1,3,2,1,
4.简答题 (略) 5.编程题 (略) 第5章 构造数据类型 1.选择题 (1)C (2)D (3)A (4)B (5)C
2.判断题 (1)错 (2)对 (3)对 (4)错 (5)错
3.读程序写结果 (1) 153 (2) 42 2 5 6 8 10 (3) 65535,21 (4) 4 19 (5) 6904 (6) 4 3 2 1 0
4.编程题 (略)
第6章 类和对象 1.填空题 (1) 类,对象,类 (2) 数据成员,成员函数 (3) 不能 (4) private,protected,public,private (5) 成员函数 (6) friend (7) 类名,作用域运算符 (8) 对象名.成员名,指针变量名->成员名,(*指针变量名).成员名 (9) 构造,析构,构造,析构 (10) 常量数据,引用数据 (11) 全局,数据类型,所属的类 (12) 常成员,只读 (13) 成员,友元 (14) 类数据成员,类成员函数 (15) this (16) 浅拷贝
2.选择题 (1)C (2)C (3)B (4)C (5)B (6)C (7)D (8)B (9)C (10)D (11)A (12)C (13)D (14)D (15)B
3.改错题 (1)man1.salary=1000.00; 不能在类外访问类的私有成员 (2)float r=0;和float c=0; 类本身是抽象的,不能在类的定义体中给其数据成员赋值 }后缺少分号“;” (3)成员函数void setdata(float x1,float y1,float r);没有实现 (4)构造函数名point()应与类名同名,为Point 没有头文件包含#include
4.读程序写结果题 (1) x=0,y=0 x=100,y=200 (2) x=100,y=200 x=1000,y=2000 t=3.14 (3) Sta::fun2()=10 s.fun2()=11 r.a=20 (4) Constructor1 called! x=0 Constructor2 called! x=100 Destructor called! Destructor called! (5) 57
5.简答题 (略) 6.编程题 (略)
第7章 继承和派生 1.填空题 (1)继承 (2)基类,派生类 (3)private,protected,public,private (4)不可访问,保护,公有 (5)私有 (6)单(一),多(重) (7)赋值兼容规则 (8)静态,动态 (9)抽象类 2.选择题 (1)B (2)A (3)B (4)C (5)B (6)A (7)D (8)B (9)B (10)B (11)D (12)B
3.改错题 (1)本题的错误主要是数据成员的访问权限问题:基类的私有成员在派生类中不可访问,如fb()函数中的a3=30;语句;类的私有和保护成员在类外不能访问,如main函数中的x.a2 =20;.a3=30; ,y.a2=200; ,y.a3=300; ,y.b2=2000;和y.b3=3000;语句。 (2)本题的错误主要是成员函数的访问权限问题:由于派生类Derived是基类Base的保护派生类,所以基类中的私有成员变成派生类的不可访问成员,而基类的保护和公有成员则变成派生类的保护成员。对于类的不可访问和保护成员在类外是不能访问的,故main函数中的语句 obj.funl();,obj.fun2(); 和obj.fun3(); 是错误的。
4.读程序写结果题 (1) d=110 b=190 d=110 d=110 (2) d=110 b=190 d=110 b=90 (3) 基类B1的构造函数被调用 基类B3的构造函数被调用 基类B2的构造函数被调用 派生类D的构造函数被调用 派生类D的析构函数被调用 基类B2的析构函数被调用 基类B3的析构函数被调用 基类B1的析构函数被调用 (4) A B C D D (5) A B D D (6) A A B D D (7) A B C D D (8) 5 25
5.简答题 (略) 6.编程题 (略)
第8章 运算符重载 1.填空题 (1) 函数重载 (2) 重载为类的成员函数,重载为类的友元函数 (3) Operator (4) 1,2 (5) 友元
2.选择题 (1)B (2)D (3)A (4)D (5)B (6)C (7)C (8)C
3.简答题 (略) 4.编程题 (略) 第9章 模板 1.填空题 (1)类模板,函数模板 (2)类,对象 (3)数据类型 (4)fun(5)
2.选择题 (1)C (2)B (3)C (4)B (5)D
3.简答题 (略) 4.编程题 (略)
第10章 文件 1.填空题 (1)FILE,stdio.h (2)stdio.h,fopen,fclose (3)顺序,随机 (4)cin,>>,cout,<<