您的当前位置:首页课堂练习参考答案(苏大版1-13章)

课堂练习参考答案(苏大版1-13章)

来源:小侦探旅游网
第2章 数据类型、运算符和表达式

一、选择题 题号 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;ifor (i=0;ifor (j=i+1; jif (a[i]==a[j]) { for(k=j;kn--; continue;

//方法一

//for(k=j+1;k} }

cout<<\"删除重复元素后的数组为:\\n\"; for(i=0;icout<}

// 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最小元素:\"<//对调最大值和最小

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 #include int fun(char str[]) {

int count=0,i=0,j=strlen(str);

while(i='A'&& str[i]<='Z'||str[i]>='a'&&str[i]<='z')&&iif(ii++;

count++;

while((str[i]>='A'&& str[i]<='Z'||str[i]>='a'&&str[i]<='z')&&ireturn count;

}

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 第一空: p1p->next==head

8 、 101 M 第一行: 江科大 第二行: C

第三空: s

第一空: n%10 第二空: p1next 第三空: p->next=p2 第四空: h 三、程序设计题

// 1 删除母串中的所有子串 #include #include

int withstr(char *s1,char *sub) {

while(*sub&&*s1++==*sub++); return !(*sub); }

char *delsub(char *s1,char *sub)

{ } { }

// 2 以首元素为据,调整元素位置 #include void fun(int *p,int n) { }

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=\"<cout<<\"现str=\"<}

else p2--;

void print(int *p,int n) {

for(int i=0;ivoid main(void) {

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 struct node{

int data; node *next;

};

void print(node * head) {

while(head) { } cout<<'\\n';

cout<data<<'\'; head=head->next;

}

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 class JC{

int n; int j;

10 public: void set(int num)

{

n=num; }

void fun(); void print()

{

cout<void JC::fun() { }

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 #include class String{ char s1[100]; char s2[100]; char *s;

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 #include class String{ char a[100],b[100];

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 () { }

cout<<\"a=\"<void String::fun() {

char t[100]; strcpy(t,a+n-1); strcpy(a+n-1,b); strcat(a,t);

}

void main(void) { }

char t[]=\"123456789\"; String test(t,\"abc\

cout<<\"原字符串为:\\n\"; test.show();

cout<<\"插入后的字符串为:\\n\"; test.fun(); test.show();

// 2 求二维数组各列元素的平均值 #include class Array{ int a[4][5]; float b[5]; public:

Array(int t[][5],int n) { }

void average();

void show() { cout<<\"二维数组为:\\n\";

for(int i=0;ifor(int j=0;j<5;j++) a[i][j]=t[i][j];

for(int i=0;i<4;i++) {

for(int j=0;j<5;j++) cout<}

cout<<\"各列平均值为:\\n\"; for(i=0;i<5;i++) cout<}

};

void Array::average() {

for(int i=0;i<5;i++) { }

b[i]=0;

for(int j=0;j<4;j++) b[i]+=a[j][i]; b[i]/=4;

}

void main(void) { int t[4][5]={{11,11,11,11,11},{21,21,21,21,21},{31,31,31,31,31},{41,41,41,41,41}};

Array arr(t,4); arr.average();

arr.show(); }

// 3 求两个集合的交集 #include #include class Set{

int s1[10],n1,s2[10],n2; int n,*r;

Set(int t1[],int m1, int t2[],int m2) {

n1=m1;

for(int i=0;ifor(i=0;ipublic:

s2[i]=t2[i];

}

int fun(int,int [],int); void intersection(); void show() { }

cout<<\"集合1:\\n\";

for(int i=0;icout<cout<cout<<\"集合2:\\n\"; for(i=0;iif((i+1)%5==0)cout<<'\\n'; cout<}

cout<cout<<\"交集:\"<if((i+1)%5==0)cout<<'\\n'; cout<cout<~Set(){delete []r;} };

int Set::fun(int num,int t[],int n) { for(int i=0;iif(num==t[i])return 1; return 0;

}

void Set::intersection() {

n=0;

for(int i=0;ifor(i=0;iif(fun(s1[i],s2,n2))r[j++]=s1[i]; }

void main(void)

{ }

第11章 继承和派生

一、选择题

题号 答案 1 A 2 B 3 C 4 D 5 D 6 B 7 C

int t1[]={3,4,6,7,8,12,15,16},t2[]={2,4,5,6,12,14,16,18,20}; Set set(t1,8,t2,9); set.intersection(); set.show();

二、填空题 1 、 第一行: 构造函数 B 第二行: 构造函数 A 第三行: 构造函数 C 2、 3 、

第12章 类的其他特性

一、选择题

题号 答案 二、填空题 1 、 3、 5 、 6、 7 、 8 、 9 、 10、

第13章 运算符重载

一、选择题

题号 答案 二、填空题 1 、 2 、

第一空: Array(){} 第三空: j<3 第一空: A operator=(A t)

第二空: Array Array::operator ^(Array arr) 第四空: *this 第二空: *this

1 A 2 D 3 D 4 B 5 B 6 B 7 D 第一空: 表态 第二空: 动态

2、 抽象 1 A 2 C 3 B 4 A 5 A 6 B 7 C 第四行: 析构函数 ~C 第五行: 析构函数 ~A 第六行: 析构函数 ~B

第一行: B() 第二行: A() 第三行: C() 第四行: ~C() 第五行: ~A() 第六行: ~B() 第一空: A(x),B(y) 第二空: c1.A::geta() 第三空: c1.geta () 或 c1.C::geta()

静态 4 、 第一空: 静态 第二空: 非静态 第一空: 类名::静态成员名 第二空: 对象名.静态成员名 友元 第一行: sin(30)=0.5 第二行: sin(0)=0 第三行: cos(120)=-0.5 第一行: x=100 第二行: y=200 第三行: z=300 第四行: x=100 第五行: y=200 第六行: z=300

第一行: Obama编号1001,月薪8000元 第二行: Bush编号3003,月薪4000元 第一行: class C 第二行: class B 第三行: class B

3 、

第三空: A operator++(int) 第四空: t

第一空: strcpy(s,p) 第二空: STR & STR::operator=(STR &str) 第三空: STR & operator+=(STR &str1,STR &str2)

因篇幅问题不能全部显示,请点此查看更多更全内容