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

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

1、国家二级 C语言机试(操作题)模拟试卷 221及答案与解析 一、程序填空题 1 给定程序中,函数 fun的功能是:将形参 S所指字符串中所有 ASCII码值小于97的字符存入形参 t所指字符数组中,形成一个新串,并统计出符合条件的字符个数作为函数值返回。 例如,形参 s所指的字符串为: Abe1x56*,程序执行后 t所指字符数组中的字符串应为: A156*。 注意:部分源程序在文件 BLANK1 C中。 不得增行或删行,也不得更改程序的结构 ! 试题程序: 1 #include stdio h 2 int fun(char*s, char*t) 3 int n=0; 4 while(*s)

2、5 if(*s 97) 6 *found* 7 *(t+n)=【 1】 ; n+; 8 *found* 9 【 2】 ; 10 11 *(t+n)=0; 12 * found* 13 return【 3】 ; 14 15 main() 16 char s81, t81; int n; 17 printf( nEnter a string: n); 18 gets(s); 19 n=fun(s, t); 20 printf( nThere are d letter which ASCII code is less than 97: %s n, n,t); 21 二、程序修改题 2 下列给定程序中

3、函数 fun的功能是:将 s所指字符串中最后 一次出现的与 t1所指字符串相同的子串替换成 t2所指字符串,所形成的新串放在 w所指的数组中。要求 t1和 t2所指字符串的长度相同。 例如,当 s所指字符串中的内容为 “abcdab-fabc”, t1所指串中的内容为 “ab”, t2所指子串中的内容为 “99”时,结果在 W所指的数组中的内容应为 “abcdabf99c”。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构 ! 试题程序: 1 #include conio h 2 #include stdio h 3 #incl

4、ude string h 4 void fun(char * s, char t1, char t2, char w) 5 6 char* p, *r, *a; 7 strcpy(w, s); 8 *found* 9 while(w) 10 11 p=w; 12 r=t1; 13 while(*r) 14 *found* 15 IF(*r=*p) 16 17 r+; 18 p+; 19 20 else 21 22 break; 23 24 if(*r= 0) 25 a=w; 26 w+; 27 28 r=t2; 29 while(*r) 30 31 *a=*r; 32 a+; 33 r+; 3

5、4 35 36 main() 37 38 char s100, t1100, t2100, w100; 39 printf( nPlease enter string s: ); 40 scanf( s, s); 41 printf( nPlease enter substring tl: ); 42 scanf( s, t1); 43 print f( nPlease enter substring t2: ); 44 scanf( s, t2); 45 if(strlen(t1)=strlen(t2) 46 47 fun(s, t1, t2, w); 48 printf( nThe res

6、ult is: s n, w); 49 50 else 51 52 printf( nError: strlen(t1)!=strlen(t2) n); 53 54 三、程序设计题 3 学生的记录由学号和成绩组成, N名学生的数据已在主函数中放入结构体数组 s中,请编写函数 fun,其功能是:把低于平均分的学生数 据放入 b所指的数组中,低于平均分的学生人数通过形参 n传回,平均分通过函数值返回。 注意:部分源程序给出如下。 请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。 试题程序: 1 #include stdio h 2 #define N

7、 8 3 typedef struct 4 5 char num10; 6 double s; 7 STREC; 8 double fun(STREC*a, STREC*b,int * n) 9 10 11 12 void main() 13 14 STREC sN=GA05, 85, GA03, 76, GA02, 69, GA04,85, GA01, 91, GA07, 72, GA08, 64, GA06, 87; 15 STREC hN; 16 int i, n; 17 double ave; 18 ave=fun(s, h, n); 19 printf(The d student d

8、ata which is lower than %7 3f: n, n , ave); 20 for(i=0; in , i+) 21 *输出成绩低于平均值的学生记录 * 22 printf( s 4 1 f n, hi num, hi s); 23 printf( n); 24 国家二级 C语言机试(操作题)模拟试卷 221答案与解析 一、程序填空题 1 【正确答案】 (1)*s (2)s+ (3)n 【试题解析】 填空 1:判断 s所指向的字符串中的字符符合条件时,将当前字符存放到 t指向的字符串中,所以应填 *s。 填空 2:判断完一个字符之后,将字符串的指针移到下一个位置,所以应填 s

9、 填空 3:题目要求函数要返回符合条件的字符个数 n,所以应填 n。 二、程序修改题 2 【正确答案】 (1)while(*w) (2)it(*r=*p) 【试题解析】 (1)此处要判断的是值的真假,而不是地址,所以改为 while(*w)。 (2)C语言中关键字区分大小写,只需运行程序,就可以根据 错误提示找到。 三、程序设计题 3 【正确答案】 1 double fun(STREC *a, STREC *b, int *n) 2 3 int i, j=0; 4 double av=0 0 ; 5 for(i=0; iN; i+) 6 av=av+ai s; 7 av=av N; *求平均值 * 8 for(i=0; iN; i+) 9 if(ai sav) 10 bj+=ai; 11 *将低于平均值的学生 记录存入结构体数组 b中 * 12 *n=j; *指针传回低于平均值的学生人数 * 13 return av; *返回平均值 * 14 【试题解析】 本题使用循环语句和条件判断语句来实现程序操作,第 1个循环语句的作用是求出总分,然后求出平均分 av。第 2个循环的作用是将分数低于平均分的学生记录存人结构体数组 b中。

展开阅读全文
相关资源
猜你喜欢
  • BS PD ISO TS 13399-305-2017 Cutting tool data representation and exchange Creation and exchange of 3D models Modular tooling systems with adjustable cartridges for boring《切削工具数据表示和交换 三维模型的创造和交流.pdf BS PD ISO TS 13399-305-2017 Cutting tool data representation and exchange Creation and exchange of 3D models Modular tooling systems with adjustable cartridges for boring《切削工具数据表示和交换 三维模型的创造和交流.pdf
  • BS PD ISO TS 19337-2016 Nanotechnologies Characteristics of working suspensions of nano-objects for $ii$in $iv$ii$it$ir$io assays to evaluate inherent nano-object toxi city《纳米技术 评估纳米物体固有毒性的体外试验所.pdf BS PD ISO TS 19337-2016 Nanotechnologies Characteristics of working suspensions of nano-objects for $ii$in $iv$ii$it$ir$io assays to evaluate inherent nano-object toxi city《纳米技术 评估纳米物体固有毒性的体外试验所.pdf
  • BS PD ISO TS 21219-2-2014 Intelligent transport systems Traffic and travel information (TTI) via transport protocol experts group generation 2 (TPEG2) UML modelling rules《智能运输系统 利用第二代传输协议专家组 (TPEG.pdf BS PD ISO TS 21219-2-2014 Intelligent transport systems Traffic and travel information (TTI) via transport protocol experts group generation 2 (TPEG2) UML modelling rules《智能运输系统 利用第二代传输协议专家组 (TPEG.pdf
  • BS PD ISO TS 28560-4-2014 Information and documentation RFID in libraries Encoding of data elements based on rules from ISO IEC 15962 in an RFID tag with partitioned memory《信息与文献 图书馆中应用的无线射频识别技术.pdf BS PD ISO TS 28560-4-2014 Information and documentation RFID in libraries Encoding of data elements based on rules from ISO IEC 15962 in an RFID tag with partitioned memory《信息与文献 图书馆中应用的无线射频识别技术.pdf
  • BS S 150-1975 Specification for chromium-molybdenum-vanadium-niobium heat-resisting steel billets bars forgings and parts (930-1080 MPa) (Cr 10 5 Mo 0 6 V 0 2 Nb 0 3)《铬-钼-钒-铌-耐热钢坯、棒材、锻件及零件规范(930-.pdf BS S 150-1975 Specification for chromium-molybdenum-vanadium-niobium heat-resisting steel billets bars forgings and parts (930-1080 MPa) (Cr 10 5 Mo 0 6 V 0 2 Nb 0 3)《铬-钼-钒-铌-耐热钢坯、棒材、锻件及零件规范(930-.pdf
  • BS PD ISO IEC TR 20000-12-2016 Information technology Service management Guidance on the relationship between ISO IEC 20000-1 2011 and service management frameworks CMMI-SVC 《信息技术 .pdf BS PD ISO IEC TR 20000-12-2016 Information technology Service management Guidance on the relationship between ISO IEC 20000-1 2011 and service management frameworks CMMI-SVC 《信息技术 .pdf
  • BS PD ISO IEC TR 20007-2014 Information technology Cultural and linguistic interoperability Definitions and relationship between symbols icons animated icons pictograms characters .pdf BS PD ISO IEC TR 20007-2014 Information technology Cultural and linguistic interoperability Definitions and relationship between symbols icons animated icons pictograms characters .pdf
  • BS PD ISO IEC TR 29110-5-1-3-2017 Systems and software engineering Lifecycle profiles for Very Small Entities (VSEs) Software engineering Management and engineering guide Generic p.pdf BS PD ISO IEC TR 29110-5-1-3-2017 Systems and software engineering Lifecycle profiles for Very Small Entities (VSEs) Software engineering Management and engineering guide Generic p.pdf
  • BS PD ISO IEC TR 29110-5-6-1-2015 Systems and software engineering Lifecycle profiles for Very Small Entities (VSEs) Systems engineering Management and engineering guide Generic pr.pdf BS PD ISO IEC TR 29110-5-6-1-2015 Systems and software engineering Lifecycle profiles for Very Small Entities (VSEs) Systems engineering Management and engineering guide Generic pr.pdf
  • 相关搜索

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

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