当前位置:高等教育资讯网  >  中国高校课件下载中心  >  大学文库  >  浏览文档

广东海洋大学:《C++程序设计》第七章练习题

资源类别:文库,文档格式:PPT,文档页数:16,文件大小:120KB,团购合买
一、选择题: 1数组声明为inta[3},D不是数组元素。 A)a[0]B)a[1]C)a[2]d)a[3
点击下载完整版文档(PPT)

选择题: 1数组声明为inta3,D不是数组元素。 A)a[0] B)a[l C)a[2] D) a[3l 2下列语句中 能正确输出结果:C++。 A)char s[C++; cout<<s<<endl; B)char s 3=C++;cout<<s<<endl C)char s3=C,+,+, 0; cout<<s<<end; D) char s!3l={C,+",+";cout<≤s≤<endl; 3以下数组定义中,不正确的是B A)intb|3}={0,1,2,3} B)intd3l={1,2},{1,2,3},{1,2,3,4}}; C)int c[100100]={0}; D) int a2 3; C++程序设计课件设计制作:徐龙琴

C++程序设计课件 设计制作:徐龙琴 1 1 数组声明为int a[3], 不是数组元素。 A)a[0] B)a[1] C)a[2] D)a[3] 2 下列语句中, 能正确输出结果:C++。 A) char s[]="C++";cout<<s<<endl; B) char s[3]="C++";cout<<s<<endl; C) char s[3]={'C','+','+','\0'};cout<<s<<endl; D) char s[3]={'C','+','+'};cout<<s<<endl; 3以下数组定义中,不正确的是 A) int b[][3]={0,1,2,3}; B) int d[3][]={{1,2},{1,2,3},{1,2,3,4}}; C) int c[100][100]={0}; D) int a[2][3]; D A 一、选择题: B

4、下列给字符数组进行初始化中,B是正确的。 A)char s423=(xyz,abc; B)char sll C)char s3=(X,y, D)char s2 3=xyz"; 5、以下选项中,不能正确赋值的是DE A)char s40=\n123"; B)char s3 20="Ctest C)char s2(C,'t, ','s, 't; D)char slsl="Ctest E) int a[ ="string C++程序设计课件设计制作:徐龙琴

C++程序设计课件 设计制作:徐龙琴 2 4、下列给字符数组进行初始化中, 是正确的。 A) char s4[2][3]={"xyz","abc"};` B) char s1[]="xyz"; C) char s3[][]={‘x‘,‘y‘,‘z‘}; D) char s2[3]="xyz"; 5、以下选项中,不能正确赋值的是 A) char s4[]="Ctest\n123"; B) char s3[20]="Ctest"; C) char s2[]={‘C‘, ‘t‘, ‘e‘, ‘s‘, ‘t‘}; D) char s1[10];s1="Ctest"; E) int a[] = "string" B D E

6、有以下程序段: int b3]3={0,1,2,0,1,2,0,1,2},t=1; for(I=0;k3;H++) for(j=1;j<=1;j+十) t=t+b[bjI[jl;其t的值是C A) B)9 C)4 D)3 7、当调用函数时,实参是一个数组名,则向函数传送的是B A)数组的长度 B)数组的首地址 C)数组每一个元素的地址 D)数组每个元素中的值 C++程序设计课件设计制作:徐龙琴 3

C++程序设计课件 设计制作:徐龙琴 3 6、有以下程序段: int b[3][3]={0,1,2,0,1,2,0,1,2},I,j,t=1; for(I=0;I<3;I++) for(j=I;j<=I;j++) t=t+b[I][b[j][j]]; 其t的值是 A) 1 B) 9 C) 4 D) 3 7、当调用函数时,实参是一个数组名,则向函数传送的是 A) 数组的长度 B) 数组的首地址 C) 数组每一个元素的地址 D) 数组每个元素中的值 C B

8、inti,x{33l={1,2,3,4,5,6,7,8,9} for(i=0;i<3;i++) printi“%d”,x[训2-i);其输出结果是_C_。 a.159 b.147 357 d.369 9、在C++语言中,数组下标的数据类型允许是C a只能整型常量 b只能整型表达式 c整型常量或整型表达式 d任何类型的表达式 C++程序设计课件设计制作:徐龙琴

C++程序设计课件 设计制作:徐龙琴 4 8、int i,x[3][3] = {1,2,3,4,5,6,7,8,9}; for(i = 0;i < 3;i ++) printf(“%d ”,x[i][2-i]); 其输出结果是____。 a. 1 5 9 b. 1 4 7 c. 3 5 7 d. 3 6 9 9、在C++语言中,数组下标的数据类型允许是____。 a.只能整型常量 b.只能整型表达式 c.整型常量或整型表达式 d.任何类型的表达式 C C

10、下面程序的运行结果是B。 char c|5l={"a',"b',",c',"V0} printf("os", c); a."a“"b bab cab c d以上三个答案均有错误 C++程序设计课件设计制作:徐龙琴

C++程序设计课件 设计制作:徐龙琴 5 10、下面程序的运行结果是____。 char c[5] = {'a','b','\0','c','\0'}; printf("%s",c); a. 'a‘ 'b' b.ab c.ab c d.以上三个答案均有错误 B

二下列程序有无错误 1\ #include #include void maino { int all={1,2,3,4,5}; for(int i=0; i<5; i++) cout<<"a"<<"l="<<a[<<"t'; C++程序设计课件设计制作:徐龙琴

C++程序设计课件 设计制作:徐龙琴 6 二 下列程序有无错误: 1、#include #include void main() { int a[]={1,2,3,4,5}; cout<<a<<endl; } for(int i=0;i<5;i++) cout<<"a["<<i<<"]="<<a[i]<<'\t'; }

2, #include #include void maino ichar oripassword[=1234"; char userpassword 10l; cout>userpassword; if(strcmp(userpassword, oripassword)==0) cout<<"欢迎进入!n se cout<"非法用户!m";} C++程序设计课件设计制作:徐龙琴 7

C++程序设计课件 设计制作:徐龙琴 7 2、#include #include void main() {char oripassword[]="1234"; char userpassword[10]; cout>userpassword; if(userpassword==oripassword) cout<<"欢迎进入!\n"; else cout<<"非法用户!\n";} if(strcmp(userpassword,oripassword)==0)

3 #include double avg(double[l, int); void maino { double math14={78.5,44.3,995,72.6}; double chem6]={88,65.5,79.8,88.4,84.6,92}; cout<< average of math=<<avg(math, 4)<<endl; cout<< average of chem=<<avg(chem, 6)<<endl; double avg( double corell, int n) i int i; double sum=score[O] for(i=l; i<n; i++) sum+=score; return sum/n; 1 C++程序设计课件设计制作:徐龙琴 8

C++程序设计课件 设计制作:徐龙琴 8 3、#include double avg(double,int); void main() { double math[4]={78.5,44.3,99.5,72.6}; double chem[6]={88,65.5,79.8,88.4,84.6,92}; cout<<"average of math="<<avg(math,4)<<endl; cout<<"average of chem="<<avg(chem,6)<<endl;} double avg(double score[],int n) { int i; double sum=score[0]; for(i=1;i<n;i++) sum+=score[i]; return sum/n;} double avg(double[],int);

程序填空题: 1.程序读入20个整数,统计非负数个数,并计算非负数之和。 #include void main(void) i int i, a,s, count; s= count=0 for(i=0;i<20;i++) scanf(ir d &ai ); for(i=0;i<20;i++) i if(a<0) continue s+=aii count ++ 3 printf("s=%dt count=%dn",S, count); )Ax C++程序设计课件设计制作:徐龙琴

C++程序设计课件 设计制作:徐龙琴 9 三 程序填空题: 1.程序读入20个整数,统计非负数个数,并计算非负数之和。 #include void main(void) { int i,a[20],s,count; s = count = 0; for(i = 0;i < 20;i ++) scanf("%d", ); for(i = 0;i < 20;i ++) { if(a[i] < 0) ; s += a[i]; count ++; } printf("s = %d\t count = %d\n",s,count);} &a[i] continue

2.以下程序将数组中的数据按逆序存放。 #include void maino i int a[12],i, j, t; for(i=0; i<12; i++) scanf(%od", &aiD i=0;j=12; while( itali; ai]=alj-1; alj-11=t for(i=0;i<12;i++) printf(%o3d, aiD; printf("In") C++程序设计课件设计制作:徐龙琴 10

C++程序设计课件 设计制作:徐龙琴 10 2. 以下程序将数组中的数据按逆序存放。 #include void main() { int a[12],i,j,t; for(i=0;i<12;i++) scanf("%d",&a[i]); i=0;j=12; while( ) { t=a[i]; ; ; i++; j ;} for(i=0;i<12;i++) printf("%3d",a[i]); printf("\n"); } i<j a[i]=a[j-1] a[j-1]=t --

点击下载完整版文档(PPT)VIP每日下载上限内不扣除下载券和下载次数;
按次数下载不扣除下载券;
24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
共16页,试读已结束,阅读完整版请下载
相关文档

关于我们|帮助中心|下载说明|相关软件|意见反馈|联系我们

Copyright © 2008-现在 cucdc.com 高等教育资讯网 版权所有