C++语言程序设计(电大考试必备)小抄参考

上传人:沈*** 文档编号:40899788 上传时间:2021-11-18 格式:DOC 页数:20 大小:205.62KB
返回 下载 相关 举报
C++语言程序设计(电大考试必备)小抄参考_第1页
第1页 / 共20页
C++语言程序设计(电大考试必备)小抄参考_第2页
第2页 / 共20页
C++语言程序设计(电大考试必备)小抄参考_第3页
第3页 / 共20页
点击查看更多>>
资源描述
专业好文档C+语言程序设计课程期末针对性训练训练第一套 一、单选题(每小题2分,共20分) 1在每个C+程序中都必须包含有这样一个函数,该函数的函数名为( A )。 A. main B. MAIN C. name D. function 2设x和y均为bool量,则x & y为真的条件是( D )。 A. 其中一个为假 B. 其中一个为真 C. 它们均为假 D. 它们均为真 3. 逻辑表达式x0 | y=5的相反表达式为( B )。A. x=0 | y!=5 B. x0 | y!=5 D. x0 & y=5 4. 假定p是一个指向float型数据的指针,则p+1所指数据的地址比p所指数据的地址大( C )个字节。 A. 1 B. 2 C. 4 D. 8 5. 枚举类型中的每个枚举常量的值都是一个( A )。 A. 整数 B. 浮点数 C. 字符 D. 逻辑值 6. 循环体至少被执行一次的语句为( C )语句。 A. for循环 B. while循环 C. do循环 D. 任一种循环 7. 在下面的字符数组定义中,( D )语句有语法错误。 A. char a20=”abcdefg”; B. char a=”x+y=55.”; C. char a15=1,2; D. char a10=5; 8. 若用数组名作为函数调用的实参,传递给形参的是( A )。 A. 数组的首地址 B. 数组中第一个元素的值 C. 数组全部元素的值 D. 数组元素的个数 9假定AB为一个类,则执行“AB a(4), b5, *p2;”语句时,自动调用该类构造函数的次数为( A )。 A. 6 B. 7 C. 9 D. 11 10当使用fstream流类定义一个流对象并打开一个磁盘文件时,文件的隐含打开方式为( D )。 A. ios:in B. ios:out C. ios:in | ios:out D. 没有 二、填空题(每小题2分,共20分) 1. 若需要定义一个标识符常量,并且使C+能够进行类型检查,则应在定义语句的开始使用保留字_ const _。 2. 算术表达式对应的C+表达式为_(x*y*y)/(3*a)+4*b-1 _。 3. 逻辑表达式xy & x!=10的相反表达式为_ x=y | x=10_。 4. 每个字符指针变量占用内存_4_个字节。 5. 执行“typedef int DataType;”语句后,在使用int定义整型变量的地方都可以使用标识符_ DataType _来定义整型变量。 6. 对于在所有函数定义之外定义的变量,若没有被初始化则系统隐含对它赋予的初值为_0_。 7假定p所指对象的值为25,p+1所指对象的值为46,则执行“*(p+);”语句后,p所指对象的值为_46_。 8假定一个结构类型的定义为“struct Aint a; double* b; A* c;”,则该类型的大小为_12_字节。 9假定一维数组的定义为“int a8;”,则该数组所含元素的个数为_8_。 10. 若while循环语句的开始为”while(i+=10)”,若i的初值为0,同时在循环体中不会修改i的值,则其循环体将被重复执行_11_次后正常结束。 三、写出下列每个程序运行后的输出结果(每小题6分,共30分) 1. #include void main() int s1=0, s2=1; for(int i=1; i=6; i+) s1+=i; s2*=i; couts1,s2endl; 输出结果:21,720 2. #include void main() int a10=68,79,86,65,46,94,37,78,60,53; int c=0; for(int i=0;i=60) c+; cout”c=”cendl; 输出结果:c=7 3. #include void main() int a34=1,2,7,8,5,6,11,15,9,20,3,4; int m=a00; for(int i=0;i3;i+) for(int j=0;jm) m=aij; coutmendl; 输出结果:20 4. #include void main() int a=10, b=15; couta b ; a*=3; int b=a+20; couta b ; couta bendl; 输出结果:10 15 30 50 30 15 5. #include void main() int a8=6,19,4,12,20,5,18,25; int* p=a; for(p=a; pa+8;p+) if(*p10) cout*p ; coutendl; 输出结果:6 4 5 四、写出下列每个函数的功能(每小题8分,共24分) 1. bool WB(int a, int n, int x) for(int i=0;in;i+) if(ai=x) return true; return false; 函数功能:从数组a中顺序查找值为x的元素,若查找成功则返回真,否则返回假。 2. int LJ(int a, int n) int k=0; for(int i=1;iak) k=i; return ak; 函数功能:求出数组a中n个元素的最大值并返回。 3. 假定结构类型Dnode中的data域为结点值域,next域为结点指针域。 DNode* QB(int n) if(n=0) return NULL; DNode* f=new DNode; cinf-data; DNode* p=f; while(-n) p=p-next=new DNode; cinp-data; p-next=NULL; return f; 函数功能:建立一个具有n个结点的链表,每个结点的值依次由键盘输入,该函数返回其表头指针。 五、按题目要求编写程序(6分) 已知6a30、15b36,求出满足不定方程2a+5b=126的全部整数组解。如(13,20)就是其中的一组解,并按此格式输出每组解。答: #include void main() int a,b; for(a=6;a=30; a+) for(b=15;b=36;b+) if(2*a+5*b=126) cout(a,b)endl; 训练第二套 一、单选题(每小题2分,共20分) 1. 枚举类型中的每个枚举常量的值都是一个( A )值。 A. 整数 B. 浮点数 C. 字符 D. 逻辑 2设x和y均为bool量,则逻辑表达式x | y为假的条件是( C )。 A. 它们均为真 B. 其中一个为真 C. 它们均为假 D. 其中一个为假 3. 声明或定义一个内联函数时,必须在函数开始使用保留字( D )。 A. static B. const C. extern D. inline 4. 在下面的函数声明中,存在着语法错误的是( D )。 A. BC(int a, int); B. BC(int, int); C. BC(int, int=5); D. BC(int x; int y); 5. 假定a为一个整型数组名,则元素a4与( C )的表示等价。 A. a+4 B. *a+4 C. *(a+4) D. *(a+16) 6. 下面循环语句执行结束后输出的i值为( B )的值。 for(int i=0; in/2) coutiendl; break; A. n/2 B. n/2+1 C. n-1 D. n 7. 将两个字符串连接起来组成一个字符串时,选用( C )函数。 A. strlen() B. strcpy() C. strcat() D. strcmp() 8. 预处理命令在程序中都是以( B )字符开头的。 A. * B. # C. & D. 9. 假定有定义“struct BOOKchar title40; float price;”,则不正确的变量定义语句为( D )。 A. BOOK x; ; B. BOOK x=C+ Programming,27.0; C. BOOK *x=new BOOK; D. BOOK x=new BOOK; 10. 假定AB为一个类,px为指向该类动态对象数组的指针,该数组长度为n,则执行“delete px;”语句时,自动调用该类析构函数的次数为( B )。 A. 1 B. n C. n-1 D. n+1 二、填空题(每小题2分,共20分) 1已知AZ的ASCII码为6590,当执行“char ch=14*4+12;coutch;”语句序列后,得到的输出结果为_D_。 2double类型的长度为_8_。 3. 表达式x=x+1表示成增量表达式为_+x _。4. 逻辑表达式ab & b!=15_。 5. 假定一个二维数组的定义为“char* a54;”,则该数组所含元素的个数为_20_,所占存储空间的字节数为_80_。 6当函数中的_局部_变量没有被赋初值时,它的值是不确定的。 7假定一个结构类型的定义为“struct Adouble a,b; A* c;”,则该类型的大小为_20_字节。 8. 假定要访问一个结构指针p所指对象中的数据成员data,则表示方法为_ p-data _。 9假定用户没有给一个名为AB的类定义构造函数,则系统为其隐含定义的构造函数为 AB()_。 10. 当在程序中执行到 break 语句时,就立即结束本层循环类语句或switch语句的执行。 三、写出下列每个程序运行后的输出结果(每小题6分,共30分) 1. #include void main() int s=0; for(int i=1;i=8;i=+2) s+=i*i; couts=sendl; 输出结果:s=84 2. #include void main() int i=1,s=0; while(s20) if(i%2!=0) s+=i; i+; couti,sendl; 输出结果:10,25 3. #include void main() int a8=36,25,48,14,55,20,47,82; int b1, b2; b1=b2=a0; for(int i=1; i8; i+) if(aib2) b2=ai; coutb1,b2endl; 输出结果:14,82 4. #include int LB(int *a, int n) int s=1; for(int i=0;in;i+) s*=*a; a+; return s; void main() int a5=1,2,3,4,5; coutLB(a,5)endl; 输出结果:120 5. #include struct Worker char name15; /姓名 int age; /年龄 float pay; /工资 ; void main() Worker x=wangfong,46,1640; Worker y, *p; y=x; p=&x; couty.name y.age y.payendl; coutname age+5 pay-300endl; 输出结果:wangfong 46 1640 wangfong 51 1340 四、写出下列每个函数的功能(每小题8分,共24分) 1. int WC(int a, int n, int k) int c=0; for(int i=0;i=k) c+; return c; 函数功能:统计出数组a的n个元素中大于等于参数k的值的元素个数并返回。 2. bool SG(int x) /x为大于等于2的整数 int a=int(sqrt(x); /sqrt(x)为求x的平方根 int i=2; while(ia) return true; else return false; 函数功能:判断x是否为一个素数(或质数),若是则返回真,否则返回假。 3. 假定结构类型Worker中的name域表示姓名,age域表示年龄,pay域表示工资。 void QA(Worker a, int n) for(int i=0; iai.nameai.ageai.pay; 函数功能: 从键盘上输入n个Worker结构类型的记录依次保存到一维数组a的对应元素中。 五、按题目要求编写函数(6分) 假定函数声明为“void Print(int a, int n);”,在函数体中按下标从大到小的次序输出数组a中的n个元素的值,并要求每行输出6个元素,当然最后一行可以不足6个。答: void Print(int a, int n) int i,j=0; for(i=n-1; i=0; i-) coutai ; if(+j%6=0) coutendl; coutendl; 训练第三套 一、单选题(每小题2分,共20分) 1. 由C+源程序文件编译而成的目标文件的缺省扩展名为( A )。 A. obj B. lik C. exe D. cpp 2. 程序运行中需要从键盘上输入多于一个数据时,各数据之间应使用( D )符号作为分隔符。 A. 空格或逗号 B. 逗号或回车 C. 逗号或分号 D. 空格或回车 3. 设x是一个bool型的逻辑量,y的值为10,则表达式 x & y的值为( C )。 A. 1 B. 0 C. 与x值相同 D. 与x值相反 4. for语句能够被改写为( D )语句。 A. 复合 B. if C. switch D. while 5. 在下面的do循环语句中,其循环体被执行的次数为( A )。 int i=0; do i+; while(i*i10); A. 4 B. 3 C. 5 D. 2 6. 在下面的一维数组定义中,( C )语句有语法错误。 A. int a=1,2,3; B. int a10=0; C. int a; D. int a5; 7. 下面的( C )保留字不能作为函数的返回类型。 A. void B. int C. new D. long 8. 下面的函数声明中,( B )是“void BC(int a, int b);”的重载函数。 A. int BC(int x, int y); B. void BC(int a, char b); C. float BC(int a, int b, int c=0); D. int BC(int a, int b=0); 9. 当类中一个字符指针成员指向具有n个字节的存储空间时,它所能存储字符串的最大长度为( C )。 A. n B. n+1 C. n-1 D. n-2 10. 假定AB为一个类,则该类的拷贝构造函数的声明语句为( D )。 A. AB&(AB x); B. AB(AB x); C. AB(AB* x); D. AB(AB&); 二、填空题(每小题2分,共20分) 1执行“cout5的相反表达式为_ x+y=5_。 5. 假定一个二维数组的定义为“int a36;”,则该数组含有_18_个元素。 6. 执行“typedef int ABC20;”语句把ABC定义为具有20个整型元素的_数组类型_。 7假定p所指对象的值为36,p+1所指对象的值为49,则*+p的值为_49_。 8. 假定a是一个一维数组,则ai的指针访问方式为_*(a+i)_。 9对一个类中的数据成员的初始化可以通过构造函数中的初始化表实现,也可以通过构造函数中的_函数体_实现。 10当一个类对象离开它的作用域时,系统将自动调用该类的_析构函数_。 三、写出下列每个程序运行后的输出结果(每小题6分,共30分) 1. #include #include int SD(int a, int b, char op) switch(op) case +: return a+b; case -: return a-b; default: cout操作符op出错,退出运行!;exit(1); void main() int x=20, y=6; coutSD(x,y,+) SD(x,y,-)endl; 运行结果:26 14 2. #include #include void main() char* a5=student,worker,cadre,soldier,apen; char *p1; p1=a0; for(int i=1;i0) p1=ai; coutp1endl; 运行结果:worker 3. #include int WF(int x, int y) x=x+y; y=x+y; return x+y; void main() coutWF(8,5)endl; 运行结果:31 4. #include const int n=9; void main() int an=2,4,6,8,10,12,14,16,18; int s=0; for(int i=0; in; i+) if(i%3=0) s+=ai; cout”s=”sendl; 运行结果:24 5. #include void main() int* d=new int5; int i; for(i=0;i5;i+) di=2*i+1; coutdi ; coutx; y+=x*x; while(-n0); return y; 函数功能:求出从键盘上输入的n个整数的平方和并返回。 2. bool WE(int a, int b, int n) for(int i=0;in;i+) if(ai!=bi) break; if(i=n) return true; return false; 函数功能:判断具有n个元素的两个数组a和b中对应元素值是否全部相等,若是则返回真,否则返回假。 3. void LK(int a, int n, int& m) float s=0; int i; for(i=0;in;i+) s+=ai; s/=n; m=0; for(i=0;i=s) m+; 函数功能:统计出数组a的前n个元素中大于等于其平均值的元素个数并由引用参数m带回。 五、按题目要求编写函数(6分) 假定一个函数声明为“void AD(int a, int n);”,要求把数组a中的n个元素值按相反的次序仍保存在数组a中。答: void AD(int a, int n) for(i=0; in/2; i+) int x=ai; ai=an-1-i; an-1-i=x; 训练第四套 一、单选题(每小题2分,共20分) 1. C+程序的基本功能模块为( D )。 A. 表达式 B. 标识符 C. 语句 D. 函数 2. 存储以下数据,占用存储字节最多的是( A )。 A. 0 B. 0 C. ”0” D. n 3. 在下面的一维数组定义中,有语法错误的是( C )。 A. int a=1,2,3; B. int a10=0; C. int a; D. int a5; 4. 在下面的语句或语句组中,( B )不正确。 A. int a5; B. int M=10; int aM; C. int a=1,5,10,45; D. const int N=12; int aN; 5C+语言中的每条简单语句以_B_作为结束符。 A. 逗号 B. 分号 C. 空格 D. 换行符 6. 含随机函数的表达式rand()%20的值在( C )区间内。 A. 119 B. 120 C. 019 D. 020 7. 当处理一个特定的问题时,若循环次数已知,则通常采用( A )来解决。 A. for循环 B. while循环 C. do循环 D. switch语句 8. 在下面循环语句中内层循环体S语句的执行总次数为( D )。 for(int i=0; in; i+) for(int j=i; jy的逻辑值为_假(false 或0)_。 6假定一个一维数组的定义为“char* a8;”,则该数组所占用存储空间的字节数为_32_。 7. 假定x=10,则表达式2+x+的值为_12_。 8假定p所指对象的值为25,p+1所指对象的值为46,则*p+的值为_25_。 9. 假定要动态分配一个类型为Worker的具有n个元素的数组,并由r指向这个动态数组,则使用的语句为Worker* r=_ new Workern;_。 10. 设px指向一个类的动态分配的对象,则执行“delete px;”语句时,将自动调用该类的_析构函数_。 三、写出下列每个程序运行后的输出结果(每小题6分,共30分) 1. #include void SB(char ch) switch(ch) case A: case a: coutwell! ; break; case B: case b: coutgood! ; break; case C: case c: coutpass! ; break; default: coutbad!;break; void main() SB(A); SB(c); SB(b); coutendl; 运行结果:well! pass! good! 2. #include void main() int a6=36,25,48,14,55,40; int b1=a0; for(int i=1;ib1) b1=ai; cout”b1=”b1endl; 运行结果:55 3. #include void main() int a9=3,5,7,9,11,13,15,17,25; int *p=a; for(int i=0;i9;i+) if(i+1)%3=0) cout*(p+i) ; coutendl; 运行结果:7 13 25 4. #include int* LG(int m) int* a=new intm; for(int i=0;im;i+) ai=3*i+1; return a; void main() int* b=LG(5); for(int i=0;i5;i+) coutbi ; coutendl; deleteb; 运行结果:1 4 7 10 13 5. #include #include struct Worker char name15; /姓名 int age; /年龄 float pay; /工资 ; void main() Worker x; strcpy(x.name, WeiRong); x.age=45; x.pay=1235; coutx.name x.age x.payb) a=b; if(ac) a=c; return a; 函数功能:求出a,b,c三个数中的最小值并返回。 2. double WA(int a, int n) double s=0; for(int i=0;in;i+) s+=ai; return s/n; 函数功能:求出数组a中n个元素的平均值并返回。 3. double SF(double x, int n) /n为大于等于0的整数 double p=1,s=1; for(int i=1;i=n;i+) p*=x; s+=p/(i+1); return s; 函数功能:计算出表达式的值并返回。 五、按题目要求编写函数(6分) 假定一个函数声明为“int FF(int a, int n);”,要求递归求出数组a中所有n个元素之积并返回。答:int FF(int a, int n) if(n=1) return an-1; else return an-1*FF(a,n-1); /或者if(n=0) return 1; / else return an-1*FF(a,n-1);If we dont do that it will go on and go on. We have to stop it; we need the courage to do it.His comments came hours after Fifa vice-president Jeffrey Webb - also in London for the FAs celebrations - said he wanted to meet Ivory Coast international Toure to discuss his complaint.CSKA general director Roman Babaev says the matter has been exaggerated by the Ivorian and the British media.Blatter, 77, said: It has been decided by the Fifa congress that it is a nonsense for racism to be dealt with with fines. You can always find money from somebody to pay them.It is a nonsense to have matches played without spectators because it is against the spirit of football and against the visiting team. It is all nonsense.We can do something better to fight racism and discrimination.This is one of the villains we have today in our game. But it is only with harsh sanctions that racism and discrimination can be washed out of football.The (lack of) air up there Watch mCayman Islands-based Webb, the head of Fifas anti-racism taskforce, is in London for the Football Associations 150th anniversary celebrations and will attend Citys Premier League match at Chelsea on Sunday.I am going to be at the match tomorrow and I have asked to meet Yaya Toure, he told BBC Sport.For me its about how he felt and I would like to speak to him first to find out what his experience was.Uefa hasopened disciplinary proceedings against CSKAfor the racist behaviour of their fans duringCitys 2-1 win.Michel Platini, president of European footballs governing body, has also ordered an immediate investigation into the referees actions.CSKA said they were surprised and disappointed by Toures complaint. In a statement the Russian side added: We found no racist insults from fans of CSKA.Baumgartner the disappointing news: Mission aborted.The supersonic descent could happen as early as Sunda.The weather plays an important role in this mission. Starting at the ground, conditions have to be very calm - winds less than 2 mph, with no precipitation or humidity and
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!