[计算机类试卷]国家二级C语言机试(操作题)模拟试卷707及答案与解析.doc

上传人:jobexamine331 文档编号:498687 上传时间:2018-11-29 格式:DOC 页数:6 大小:32.50KB
下载 相关 举报
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷707及答案与解析.doc_第1页
第1页 / 共6页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷707及答案与解析.doc_第2页
第2页 / 共6页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷707及答案与解析.doc_第3页
第3页 / 共6页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷707及答案与解析.doc_第4页
第4页 / 共6页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷707及答案与解析.doc_第5页
第5页 / 共6页
点击查看更多>>
资源描述

1、国家二级 C语言机试(操作题)模拟试卷 707及答案与解析 一、程序填空题 1 函数 fun的功能是进行数字字符转换。若形参 ch中是数字字符 0 9,则 0转换成 9, 1转换成 8, 2转换成 7, , 9转换成 0;若是其他字符则保持不变;并将转换后的结果作为函数值返回。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的 BLANK1 C中。 不得增行或删行,也不得更改程序的结构 ! 1 #include stdio h 2 *found* 3 _1_fun(char ch) 4 5 *found* 6 if(ch =0 & _2_

2、 ) 7 *found* 8 return 9-(oh-_3_); 9 return ch; 10 11 main() 12 char c1, c2; 13 printf( nThe result: n); 14 c1=2; c2=fun(c1); 15 printf(c1=%c c2=%c n, c1, c2); 16 c1=8; c2=fun(c1); 17 printf(c1=%c c2=%c n, c1, c2); 18 c1=a; c2=fun(c1); 19 printf(cl=%c c2=%c n, c1, c2); 20 二、程序修改题 2 给定程序 MODI1 C中函数 fu

3、n的功能是:将 p所指字符串中的所有字符复制到 b中,要 求每复制三个字符之后插入一个空格。 例如,在调用 fun函数之前给 a输入字符串: ABCDEFGHIJK,调用函数之后,字符数组 b中的内容则为: ABC DEF GHI JK。 请改正程序中的错误,使它能得出正确结果。 注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构。 1 #include stdio h 2 void fun(char *p, char *b) 3 int i, k=0; 4 while(*p) 5 i=1; 6 while(i =3 *p) 7 *found* 8 bk=p; 9 k+; p+

4、 i+; 10 11 if(*p) 12 13 *found* 14 bk+= ; 15 16 17 bk= 0; 18 19 main() 20 char a80, b80; 21 printf(Enter a string: ); gets(a); 22 printf(The original string: ); puts(a); 23 fun(a, b); 24 printf( nThe string after insert space: ); puts(b); printf( n n); 25 三、程序设计题 3 N名学生的成绩已在主函数中放入一个带头节点的链表结构中, h指向链

5、表的头节点。请编写函数 fun,它的功能是:求出平均分,由函数值返回。 例如,若学生的成绩是: 85, 76, 69, 85, 91, 72, 64, 87,则平均分应当是:78 625。 注意:部分源程序在文件 PROG1 C中。 请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。 1 #include stdio h 2 #include stdlib h 3 #define N 8 4 struct slist 5 double s; 6 struct slist *next, 7 ; 8 typedef struct slist STREC

6、 9 double fun(STREC *h) 10 11 12 13 STREC * creat(double *s) 14 STREC *h, *p, *q; int i=0; 15 h=p=(STREC*)malloc(sizeof(STREC); p- s=0; 16 while(i N) 17 q=(STREC *)malloc(sizeof(STREC); 18 q- s=si; i+; p- next=q; p=q; 19 20 p- next=0; 21 return h; 22 23 outlist(STREC *h) 24 STREC *p; 25 p=h- next;

7、printf(head); 26 do 27 printf(- 4 1f, p- s); p=p- next; 28 while(p!=0); 29 printf( n n); 30 31 main() 32 double sN=85, 76, 69, 85, 91, 72, 64, 87, ave; 33 void NONO(); 34 STREC *h; 35 h=creat(s); outlist: (h); 36 ave=fun(h); 36 printf(ave= 6 3f n, ave); 38 NONO(); 39 40 void NONO() 41 *本函数用于打开文件,输入数

8、据,调用函数,输出数据,关闭文件。 * 42 FILE *in, *out; 43 int i, j; double sN, ave; 44 STREC *h; 45 in=fopen(in dat, r); 46 out=fopen(out dat, w); 47 for(i=0; i 10; i+) 48 for(j=0; j N; j+)fscanf(in, 1f, , sj); 49 h=creat(s); 50 ave=fun(h); 51 fprintf(out, 6 31f n, ave); 52 53 fclose(in); 54 fclose(out); 国家二级 C语言 机

9、试(操作题)模拟试卷 707答案与解析 一、程序填空题 1 【正确答案】 (1)char (2)ch =9 (3)0 【试题解析】 函数 fun的功能是进行数字字符转换。 第一空:由主函数内 fun函数的调用 “c1=2; c2=fun(c1); ”,而 c1和 c2是char变量,可知 fun函数的返回值类型是 char,故第一空处补充返回值类型应为“char”。 第二空:数字字符是 “0 9”,因此,数字字符必须 “ch =0”且 “ch =9”,故第二空处应为 “ch =9”。 第三空:数字字符转换规则是: “0”转换成 “9”, “1”,转换成 “8”, “2”转换成 “7, , 9”

10、转换成 “0”,即返回值为 “9-(ch-0)”,故第三空处应为“0”。 二、程序修改题 2 【正确答案】 (1)bk=*p; (2)bk+= ; 【试题解析】 函数的功能是将字符串 p中的所有字符复制到字符串 b中。 (1)p是指针, p存放的内容是地址值,第一标识下 “bk=p; ”含义是将 p存放的地址内容赋值给 bk, 而不是把 p指向的地址拷贝到 bk,显然不符合题意,应改成 “bk=*p; ”, *p是取 p指向的地址的内容。 (2)第二个标识符下是复制三个字符后在 b中插入空格,原题中给出的“bk+= ; ”,在 C语言中字符常量是由单引号括起的单个字符,即空格字符应为 “ ”,

11、而 “ ”是表示字符串常量且该字符串中只有一个空格字符。第二标识下是将空格字符复制给 bk+,因此,第二标识下应改为 “bk+= ; ”。 三、程序设计题 3 【正确答案】 1 STREC *p=h- next; *由于头结点中没有存放数据 * 2 double av=0 0; *对计算成绩平均值的变量进行初始化 * 3 int n=0; 4 while(p!=NULL) *判断链表是否结束 * 5 av=av+p- s; *对成绩进行累加 * 6 p=p0 next; *到下一个结点位置 * 7 n+; *人数加 1* 8 9 av =n; *计算成绩平均值 * 10 return av; *返回成绩平均值 * 【试题解析】 (1)首先定义存放平 均值的变量,并对其初始化。 (2)在循环中,依次取链表中存放的成绩,并对其求和。 (3)最后计算平均值,并返回值。

展开阅读全文
相关资源
猜你喜欢
  • API PUBL 4600-1995 Metals Criteria for Land Management of Exploration and Production Wastes Technical Support Document for API Recommended Guidance Values《石油工业废弃物陆地管理的金属标准 技术支持文件AP.pdf API PUBL 4600-1995 Metals Criteria for Land Management of Exploration and Production Wastes Technical Support Document for API Recommended Guidance Values《石油工业废弃物陆地管理的金属标准 技术支持文件AP.pdf
  • API PUBL 4601-1994 Transport and Fate of Dissolved Methanol Methyl-Tertiary-Butyl- Ether and Monoaromatic Hydrocarbons in a Shallow Sand Aquifer Appendix H Laboratory Biotransforma.pdf API PUBL 4601-1994 Transport and Fate of Dissolved Methanol Methyl-Tertiary-Butyl- Ether and Monoaromatic Hydrocarbons in a Shallow Sand Aquifer Appendix H Laboratory Biotransforma.pdf
  • API PUBL 4602-1994 Minimization Handling Treatment and Disposal of Petroleum Products Terminal Wastewaters Errata - 1994《石油产品的终端废水的最小化运输处理》.pdf API PUBL 4602-1994 Minimization Handling Treatment and Disposal of Petroleum Products Terminal Wastewaters Errata - 1994《石油产品的终端废水的最小化运输处理》.pdf
  • API PUBL 4605-1994 Investigation of MOBILE5a Emission Factors Evaluation of IM240-to-FTP Correlation and Base Emission Rate Equations《调查mobile5a排放系数 评价im240到ftp的相关性及基地发射速率方程》.pdf API PUBL 4605-1994 Investigation of MOBILE5a Emission Factors Evaluation of IM240-to-FTP Correlation and Base Emission Rate Equations《调查mobile5a排放系数 评价im240到ftp的相关性及基地发射速率方程》.pdf
  • API PUBL 4607-1994 User's Guide and Technical Resource Document Evaluation of Sediment Toxicity Tests for Biomonitoring Programs《用户指南和技术资源文件 生物监测程序用沉淀物毒性测试评估》.pdf API PUBL 4607-1994 User's Guide and Technical Resource Document Evaluation of Sediment Toxicity Tests for Biomonitoring Programs《用户指南和技术资源文件 生物监测程序用沉淀物毒性测试评估》.pdf
  • API PUBL 4608-1994 Evaluation of Sediment Toxicity Tests for Biomonitoring Programs《用户指南 生物监测程序用沉淀毒性测试评估》.pdf API PUBL 4608-1994 Evaluation of Sediment Toxicity Tests for Biomonitoring Programs《用户指南 生物监测程序用沉淀毒性测试评估》.pdf
  • API PUBL 4609-1995 In Situ Air Sparging Evaluation of Petroleum Industry Sites and Considerations for Applicability Design and Operation《设计和运行的考虑因素评估石油工业用地及适用性》.pdf API PUBL 4609-1995 In Situ Air Sparging Evaluation of Petroleum Industry Sites and Considerations for Applicability Design and Operation《设计和运行的考虑因素评估石油工业用地及适用性》.pdf
  • API PUBL 4610-1995 Critical Review of Draft EPA Guidance on Assessment and Control of Bioconcentratable Contaminants in Surface Waters《环保局严格审查地表水污染物的评估和控制草案》.pdf API PUBL 4610-1995 Critical Review of Draft EPA Guidance on Assessment and Control of Bioconcentratable Contaminants in Surface Waters《环保局严格审查地表水污染物的评估和控制草案》.pdf
  • API PUBL 4611-1995 Interlaboratory Study of EPA Methods 1662 1654A and 1663 for the Determination of Diesel Mineral and Crude Oils in Drilling Muds from Offshore Oil and Gas Indust.pdf API PUBL 4611-1995 Interlaboratory Study of EPA Methods 1662 1654A and 1663 for the Determination of Diesel Mineral and Crude Oils in Drilling Muds from Offshore Oil and Gas Indust.pdf
  • 相关搜索

    当前位置:首页 > 考试资料 > 职业资格

    copyright@ 2008-2019 麦多课文库(www.mydoc123.com)网站版权所有
    备案/许可证编号:苏ICP备17064731号-1