【计算机类职业资格】国家二级C语言机试(操作题)模拟试卷316及答案解析.doc

上传人:registerpick115 文档编号:1332130 上传时间:2019-10-17 格式:DOC 页数:3 大小:34KB
下载 相关 举报
【计算机类职业资格】国家二级C语言机试(操作题)模拟试卷316及答案解析.doc_第1页
第1页 / 共3页
【计算机类职业资格】国家二级C语言机试(操作题)模拟试卷316及答案解析.doc_第2页
第2页 / 共3页
【计算机类职业资格】国家二级C语言机试(操作题)模拟试卷316及答案解析.doc_第3页
第3页 / 共3页
亲,该文档总共3页,全部预览完了,如果喜欢就下载吧!
资源描述

1、国家二级 C语言机试(操作题)模拟试卷 316及答案解析(总分:6.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:2.00)1.给定程序中,函数 fun的功能是:利用指针数组对形参 ss所指字符串数组中的字符串按由长到短的顺序排序,并输出排序结果。ss 所指字符串数组中共有 N个字符串,且串长小于 M。 请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。 注意:部分源程序在文件 BLANK1C 中。 不得增行或删行,也不得更改程序的结构! 试题程序: #includestdioh #includestringh #define N 5 #define M 8

2、 void fun(char(*ss)M) char*psN,*tp;int i,j,k; for(i=0;iN;i+) psi=ssi; for(i=0 ;iN 一 1;i+) *found* k= 【1】 ; for(j=i+1;jN; j+) *found* if(strlen(psk)strlen ( 【2】 )k=j; *found* tp=psi; psi=psk; psk= 【3】 ; printf(“nThe string after sorting by length:nn“); for(i=0;iN;i+)puts(psi); main() char chNM=“red“,

3、green“,“blue“,“yellow“,“black“); int i; printf(“nThe original stringnn“); for(i=0;iN;i+) puts(chi);printf(“n); fun(ch); (分数:2.00)_二、程序修改题(总题数:1,分数:2.00)2.下列给定程序中,函数 fun的功能是:求出 s所指字符串中最后一次出现的 t所指字符串的地址,并通过函数值返回,在主函数中输出从此地址开始的字符串;若未找到,则函数值为 NULL。例如,当字符串中的内容为“abcdabfabcdx”,t 中内容为“ab”时,输出结果应是“abedx”。当字

4、符串中的内容为“abcdabfabcdx”,t 中内容为“abd”时,则程序输出未找到信息“not be found!”。请改正程序中的错误,使它能得出正确的结果。注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构!试题程序:#includestdlibh#includestdioh#includeconioh#includestringhchar *fun(char*s,char*t) char*p,*r,*a;*found* a=Null; while(*s) p=s;r=t; while(*r)*found* if(r=P) r+,P+, else break; if(*

5、r=0)a=s; s+; return a;void main() char s100,t100,*P; system(“CLS“); printf(“nPlease enter string s:“); scanf(“s“,s); printf(“nPlease enter substring t:“); scanf(“s“,t); p=fun(s,t); if(p) printf(“nThe result is:sn“,p); else printf(“nNot found!n“);(分数:2.00)_三、程序设计题(总题数:1,分数:2.00)3.请编写函数 fun,该函数的功能是:判断

6、字符串是否为回文,若是,则函数返回 1,主函数中输出“YES“,否则返回 0,主函数中输出“NO“。回文是指顺读和倒读都一样的字符串。例如,字符串 LEVEL是回文,而字符串 123312就不是回文。注意:部分源程序在文件 PROG1C 中。请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。试题程序:#includestdioh#define N 80int fun(char*str)main() char sN; FILE*out; char*test=“1234321“,“123421“,“123321“,“abcdCBA“; int i; p

7、rintf(“Enter a string:“); gets(s), printf(“nn“); puts(s); if(fun(S) printf(“YESn“); else printf(“NOn“); * out=fopen(“outdat“,“w“); for(i=0;i4;i+) if(fun(testi) fprintf(out,“YESn“); else fprintf(out,“NOn“); fclose(out); * (分数:2.00)_国家二级 C语言机试(操作题)模拟试卷 316答案解析(总分:6.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:2.00)

8、1.给定程序中,函数 fun的功能是:利用指针数组对形参 ss所指字符串数组中的字符串按由长到短的顺序排序,并输出排序结果。ss 所指字符串数组中共有 N个字符串,且串长小于 M。 请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。 注意:部分源程序在文件 BLANK1C 中。 不得增行或删行,也不得更改程序的结构! 试题程序: #includestdioh #includestringh #define N 5 #define M 8 void fun(char(*ss)M) char*psN,*tp;int i,j,k; for(i=0;iN;i+) psi=ssi;

9、for(i=0 ;iN 一 1;i+) *found* k= 【1】 ; for(j=i+1;jN; j+) *found* if(strlen(psk)strlen ( 【2】 )k=j; *found* tp=psi; psi=psk; psk= 【3】 ; printf(“nThe string after sorting by length:nn“); for(i=0;iN;i+)puts(psi); main() char chNM=“red“,“green“,“blue“,“yellow“,“black“); int i; printf(“nThe original stringn

10、n“); for(i=0;iN;i+) puts(chi);printf(“n); fun(ch); (分数:2.00)_正确答案:(正确答案:(1)i (2)psj (3)tp)解析:解析:本题是按字符串的长短进行排序。 填空 1:外循环每循环一次,k 应保存当前的 i值,所以应填 i。 填空 2:使用内循环对 i+1后面的字符串长度进行比较,所以应填 psj。 填空 3:此处的作用是交换两个变量的值,所以应填 tp。二、程序修改题(总题数:1,分数:2.00)2.下列给定程序中,函数 fun的功能是:求出 s所指字符串中最后一次出现的 t所指字符串的地址,并通过函数值返回,在主函数中输出从

11、此地址开始的字符串;若未找到,则函数值为 NULL。例如,当字符串中的内容为“abcdabfabcdx”,t 中内容为“ab”时,输出结果应是“abedx”。当字符串中的内容为“abcdabfabcdx”,t 中内容为“abd”时,则程序输出未找到信息“not be found!”。请改正程序中的错误,使它能得出正确的结果。注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构!试题程序:#includestdlibh#includestdioh#includeconioh#includestringhchar *fun(char*s,char*t) char*p,*r,*a;*f

12、ound* a=Null; while(*s) p=s;r=t; while(*r)*found* if(r=P) r+,P+, else break; if(*r=0)a=s; s+; return a;void main() char s100,t100,*P; system(“CLS“); printf(“nPlease enter string s:“); scanf(“s“,s); printf(“nPlease enter substring t:“); scanf(“s“,t); p=fun(s,t); if(p) printf(“nThe result is:sn“,p); e

13、lse printf(“nNot found!n“);(分数:2.00)_正确答案:(正确答案:(1)a=NULL; (2)if(*r=*p)解析:解析:(1)a=Null;是个明显的语法错误,指针指向空值的关键字应为 NULL。 (2)r 和 p均为指针变量,分别指向两个字符串中的字符变量,循环条件是当 r和 p所指向的字符相同时,进行指针后移操作,故此处应为 if(*r=*p)。三、程序设计题(总题数:1,分数:2.00)3.请编写函数 fun,该函数的功能是:判断字符串是否为回文,若是,则函数返回 1,主函数中输出“YES“,否则返回 0,主函数中输出“NO“。回文是指顺读和倒读都一样的

14、字符串。例如,字符串 LEVEL是回文,而字符串 123312就不是回文。注意:部分源程序在文件 PROG1C 中。请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。试题程序:#includestdioh#define N 80int fun(char*str)main() char sN; FILE*out; char*test=“1234321“,“123421“,“123321“,“abcdCBA“; int i; printf(“Enter a string:“); gets(s), printf(“nn“); puts(s); if(fu

15、n(S) printf(“YESn“); else printf(“NOn“); * out=fopen(“outdat“,“w“); for(i=0;i4;i+) if(fun(testi) fprintf(out,“YESn“); else fprintf(out,“NOn“); fclose(out); * (分数:2.00)_正确答案:(正确答案:int fun(char*str) int i,n=0,fg=1; char*p=str; while(*p)*将指针p置位到字符串末尾,并统计字符数* n+; p+; for(i=0;in2;i+) *循环比较字符* if(stri=strn 一 1一 i);*相同,什么都不作* else*不同,直接跳出循环* fg=0; break; return fg; )解析:解析:判断回文就是将第一个字符与最后一个字符比较,第二个字符与倒数第二个字符进行比较,依此类推,直到中间的字符,如果比较的结果都相同,那么这个字符串就是回文,否则不是。程序中循环语句用来遍历字符串,条件语句用来判断当前字符与对应位置的字符是否相同。

展开阅读全文
相关资源
猜你喜欢
  • SANS 61280-1-3-1998 Fibre optic communication subsystem basic test procedures Part 1-3 Test procedures for general communication subsystems - Central wavelength and spectral width .pdf SANS 61280-1-3-1998 Fibre optic communication subsystem basic test procedures Part 1-3 Test procedures for general communication subsystems - Central wavelength and spectral width .pdf
  • SANS 61280-2-2-2009 Fibre optic communication subsystem test procedures Part 2-2 Digital systems - Optical eye pattern waveform and extinction ratio measurement《光纤通信子系统的测试程序 第2-2部分.pdf SANS 61280-2-2-2009 Fibre optic communication subsystem test procedures Part 2-2 Digital systems - Optical eye pattern waveform and extinction ratio measurement《光纤通信子系统的测试程序 第2-2部分.pdf
  • SANS 61281-1-1999 Fibre optic communication subsystems Part 1 Generic specification《光纤通信子系统 第1部分:总规范》.pdf SANS 61281-1-1999 Fibre optic communication subsystems Part 1 Generic specification《光纤通信子系统 第1部分:总规范》.pdf
  • SANS 61282-1-2000 Fibre optic communication system design guides Part 1 Single-mode digital and analogue systems《纤维光学通信系统的设计指南 第1部分:单模数字系统和模拟系统》.pdf SANS 61282-1-2000 Fibre optic communication system design guides Part 1 Single-mode digital and analogue systems《纤维光学通信系统的设计指南 第1部分:单模数字系统和模拟系统》.pdf
  • SANS 61282-3-2007 Fibre optic communication system design guides Part 3 Calculation of link polarization mode dispersion《光纤通信系统设计指南 第3部分 链路极化模色散的计算》.pdf SANS 61282-3-2007 Fibre optic communication system design guides Part 3 Calculation of link polarization mode dispersion《光纤通信系统设计指南 第3部分 链路极化模色散的计算》.pdf
  • SANS 61284-1997 Overhead lines - Requirements and tests for fittings《架空线 接头要求和试验》.pdf SANS 61284-1997 Overhead lines - Requirements and tests for fittings《架空线 接头要求和试验》.pdf
  • SANS 61290-3-2009 Optical amplifiers - Test methods Part 3 Noise figure parameters《光学放大器 试验方法 第3部分 噪声数字参数》.pdf SANS 61290-3-2009 Optical amplifiers - Test methods Part 3 Noise figure parameters《光学放大器 试验方法 第3部分 噪声数字参数》.pdf
  • SANS 61290-5-1-2007 Optical amplifiers - Test methods Part 5-1 Reflectance parameters - Optical spectrum analyzer method《光学放大器 试验方法 第5-1部分 反射参数 光谱分析仪法》.pdf SANS 61290-5-1-2007 Optical amplifiers - Test methods Part 5-1 Reflectance parameters - Optical spectrum analyzer method《光学放大器 试验方法 第5-1部分 反射参数 光谱分析仪法》.pdf
  • SANS 61291-1-2007 Optical amplifiers Part 1 Generic specification《光放大器 第1部分 总规范》.pdf SANS 61291-1-2007 Optical amplifiers Part 1 Generic specification《光放大器 第1部分 总规范》.pdf
  • 相关搜索

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

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