一、选择题 题号 1 答案 B 二、填空题 13、 15、 17、 19、 21、
第4章 C++流程控制语句
一、选择题 题号 答案 1 C 2 D 3 B 4 C 5 A 6 A 7 D
8 C 9 D 10 A 11 C 12 D 13 B 14 D
2 A 3 B 4 A 5 C
6 D
7 D 14、 16、 18、 20、 8 A 9 B 10 D 11 D 12 A
int(a) 或 (int)a 1 105 和 70 10、8、3 0 4 或4.0 60 5、7、2.9 7、7、15、1 二、填空题 1、 第一空:switch ,第二空:continue 3、 第一空,第二空:退出程序运行
2、 10 4、 第一空:A ,第二空:e 5、 第一行:11 13 17 19 23 , 第二行:29 31 37 6、 第一行:2 , 第二行:0 0 7、 第一行:1 , 第二行:3 8、 9、 10、 11、
第一行:10=1*2*5 , 第一行:i=40 , 第一空:i%5==0, 第一空:i<10,
第二行:20=1*2*2*5
第二行:s=108 第二空:n+m ,第三空:n-m 第二空:i%5==0 ,第三空:x1
12、 第一空:i<=100, 第二空:1.0/i*s ,第三空:s*(-1) 13、 第一空:n或 n!=0, 第二空:n/=10 14、 第一空:n/10%10 或 n%100/10 等,
第二空:a==b||a==c||b==c
第5章 函数和编译预处理
一、选择题 题号 答案 1 、 3 、 5 、 7 、 9 、 10、 11、 12、
1 2 C 3 C 4 B
5 A
6 C 7 D 8 A 9 B 10 D 11 B 12 C 13 C A 二、填空题
inline 14 fun=29 2 、 4 、 6 、 8 、
int 作用域 或 :: 条件编译 f();
0 自动类型 或 auto
第一行:-1 12 14 10 第一行:521 第二行:0234
第二行:7 14 33 20 第一空:return n*f(n-1) 第二空:f(m)/(f(r)*f(m-r)) 第一行:4,4,6 第二行:15,4,12 第三行:10,4,6
第6章 数组
一、选择题 题号 答案 1 2 3 4 5 C 6 B
7 D
8 C 2 、 4 、 6 、 8 、 9 B 8 10 D 11 A 12 D 13 C 14 B D D C C 二、填空题 1 、 cin.getline(str,20) 3 、 5 、 7 、 9 、 10、 第一空: ’\\0’ 第二空: 0 第一行:s=56 第二行:count=7 第二行:1 1 第四行:1 3 3 1
第一空: 4 第二空: 100 第一行: 9 第三行: 6.4 9 7 6 5 4 3 2 第一行: 3 0 2 第二行: 5 7 3
第三行: 4 5 1 第四行: 7 6 9
第三空: b 或 b==1等 第三空: count(str,substr) 第一空: n%10 第二空: a[j]!=a[i-j-1] 11、 第一空: str[i]等 第二空: break 三、程序设计题
// 1 删除一维数组中的重复元素 #include void main(void)//间接选择排序法 { int a[10]={7,3,7,1,9,7,8,3,3,1},i,j,k,n=10; cout<<\"原数组为:\\n\"; for(i=0;i //方法一 //for(k=j+1;k cout<<\"删除重复元素后的数组为:\\n\"; for(i=0;i // 2 交换二维数组中的最大和最小元素 #include void main(void) { int a[3][4],i,j,max,min,rmax,cmax,rmin,cmin,t; for(i=0;i<3;i++) //输入二维数组 for(j=0;j<4;j++) cin>>a[i][j]; for(i=0;i<3;i++){ //输出输入的数组(调换前的数组) for(j=0;j<4;j++) } cout<cout<<'\\n'; max=min=a[0][0]; //把首元素作为最大值和最小值 rmax=cmax=rmin=cmin=0; //记录最大值和最小值的位置 for(i=0;i<3;i++) //查找最大值和最小值及其位置 for(j=0;j<4;j++) { if(a[i][j]>max)max=a[i][j],rmax=i,cmax=j; if(a[i][j] cout<<\"最大元素:\"< cout<<'\\n'; t=a[rmax][cmax],a[rmax][cmax]=a[rmin][cmin],a[rmin][cmin]=t; 值 for(i=0;i<3;i++){ //输出调换后的数组 } for(j=0;j<4;j++) cout<cout<<'\\n'; } // 3 统计英文单词个数 #include int count=0,i=0,j=strlen(str); while(i count++; while((str[i]>='A'&& str[i]<='Z'||str[i]>='a'&&str[i]<='z')&&i } void main(void) { } 第8章 指针和引用 一、选择题 题号 1 答案 B 二、填空题 1 、 3 、 5 、 7 、 9 、 11、 12、 13、 14、 地址 引用 2 C 3 A 4 C 5 B 6 B 7 B 8 A 2 、 4 、 9 A 10 B 11 A 12 A 13 C 14 C char p[200]; cin.getline(p,200);//\" Sandwich was an Englishman. He lived in the 18th century(世纪).\"; int num=fun(p); cout<<\"段落:\\n\"< void (*f)(int,int);等 3 p->next=q等 6 、 pup[2].age 、(p+2)->age 、(*(p+2)).age 0 7 14 21 28 10、 第一行: 13 第二行: 1 第一空: p1 8 、 101 M 第一行: 江科大 第二行: C 第三空: s 第一空: n%10 第二空: p1 // 1 删除母串中的所有子串 #include int withstr(char *s1,char *sub) { while(*sub&&*s1++==*sub++); return !(*sub); } char *delsub(char *s1,char *sub) { } { } // 2 以首元素为据,调整元素位置 #include int *p1=p,*p2=p+n-1; while(p2>p1) { if(*p2<*p1) } { int t=*p2,*p3=p2; while(p3>p1) *p3--=*(p3-1); *p1++=t; char *s=s1; while(*s) { if(withstr(s,sub))strcpy(s,s+strlen(sub)); } return s1; s++; void main(void) char str[]=\"This book is a very good book.\ cout<<\"原str=\"< else p2--; void print(int *p,int n) { for(int i=0;i int a[]={45,0,7,67,89,45,2,6},n; n=sizeof(a)/sizeof(a[0]); cout< } cout<<\"原数组为:\\n\"; print(a,n); fun(a,n); cout<<\"调整后的数组为:\\n\"; print(a,n); // 3 合并链表相邻的结点 #include int data; node *next; }; void print(node * head) { while(head) { } cout<<'\\n'; cout< } node* create(node *head,int n)//把以n为数据的结点置于链首 { } node * p=new node; p->data=n; p->next=head; head=p; return head; node * merge(node * head) { } node *p1=head,*p2=p1->next; while(p2) { p1->data+=p2->data; p1->next=p2->next; p1=p2->next; delete p2; if(p1)p2=p1->next; else p2=0; } return head; void dele(node *head) { } { } 第9章 类和对象 一、选择题 题号 答案 二、填空题 1 、 3 、 5 、 this 2 、 第一空: public 第二空: protected 第一空: private 第二空: public 第二行: 5 第一空: 类名:: 第二空: 对象名. 4 、 public 第三行: 20 30 1 B 2 B 3 C 4 D 5 A 6 C 7 D 8 B 9 D 10 D 11 A 12 C if(head==0) return ; while(head) { node*p=head; } head=head->next; delete p; void main(void) int a[]={1,2,3,4,5,6,7}; node *h=0; for(int i=0;i<7;i++) h=create(h,a[i]); print(h); merge(h); print(h); dele(h); 6 、 第一行: 0 0 三、程序设计题 // 1 定义求n!的类 #include int n; int j; 10 public: void set(int num) { n=num; } void fun(); void print() { cout< void main(void) { JC test; test.set(5); test.fun(); test.print(); j=1; for(int i=2;i<=n;i++) j*=i; } // 2 定义实现字符串拼接的类 #include public: void set(char*p1,char*p2) }; void String::fun() { s=new char[strlen(s1)+strlen(s2)+1]; char *p1=s1,*p=s; { strcpy(s1,p1); strcpy(s2,p2); } void fun(); void print() { cout<<\"s1=\"< //~String(){delete []s;} } { } while(*p1)*p++=*p1++; p1=s2; while(*p1)*p++=*p1++; *p=0; void main(void) char str1[]=\"abcdefgh\String str; str.set(str1,str2); str.fun(); str.print(); 第10章 构造函数和析构函数 一、选择题 题号 答案 1 C 2 C 3 D 4 B 5 C 6 B 7 A 8 B 9 D 二、填空题 1 、 5 2 、 对象 3 、 第一空: 对象名 第二空: 对象所属类的构造函数 4 、 5 、 6 、 7 、 8 、 第一空: 没有参数 第二空: 所有参数都有缺省值 第三空: 1 第一空:拷贝构造函数 第二空:类名 新对象=已建立对象 第三空:类名 新对象(已建立对象) 第一行: x=0,y=0 第二行: x=3,y=5 第三行: x=13,y=15 第一行: B() A() C() 第二行: ~C() ~A() ~B() 第一空: Point::Point(int a,int b) 第三空: l.distance() 第二空: p1.getx()-p2.getx() 第三行: 5 6 9 、 第一行: 1 2 三、程序设计题 #include int n; public: 第二行: 3 4 // 1 将字符串b插入到字符串a的第n个字符处 String(char c[],char d[],int m) { strcpy(a,c); }; strcpy(b,d); n=m; } void fun(); void show () { }