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

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

1、国家二级 C语言机试(操作题)模拟试卷 276及答案解析(总分:6.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:2.00)1.下列给定程序中,函数 fun的功能是:求 ss所指字符串数组中长度最短的字符串所在的行下标,作为函数值返回,并把其串长放在形参 n所指的变量中。ss 所指字符串数组中共有 M个字符串,且串长小于N。 请在程序的下画线处填入正确的内容并将下画线删除,使程序得出正确的结果。 注意:部分源程序给出如下。 不得增行或删行,也不得更改程序的结构! 试题程序: #includestdioh #includestringh #define M 5 #define N

2、 20 int fun(char(*ss)N,int*n) int i,k=0,len=N; *found* for(i=0;i 【1】 ;i+) fen=strlen(ssi); if(i=0) *n=len; *found* if(len 【2】 *n) *n=len; k=i; *found* return( 【3】 ); main() char ssMN=“ shang hai“,“guangzhou“,“beijing“,“tianjing“,“chongqing“; int n,k,i; printf(“nThe original strings are:n“); for(i=0;

3、iM;i+)puts(ssi); k=fun(ss,&n); printf(“nThe length of shortest string is:dn“,n); printf(“nThe shortest string is:sn“,ssk); (分数:2.00)_二、程序修改题(总题数:1,分数:2.00)2.下列给定程序中,函数 fun的功能是:将 s所指字符串中最后一次出现的与 t1所指字符串相同的子串替换成 t2所指字符串,所形成的新串放在 w所指的数组中。要求 t1和 t2所指字符串的长度相同。例如,当 S所指字符串中的内容为“abcdabfabc”,t1 所指串中的内容为“ab”,

4、t2 所指子串中的内容为“99”时,结果在 w所指的数组中的内容应为“abcdabt99c”。请改正程序中的错误,使它能得出正确的结果。注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构!试题程序:#includeconioh#includestdioh#includestringhvoid fun(char *s,char t1,char t2,char w) char*P,*r,*a; strcpy(w,S);*found* while(w) p=W; r=t1; while(*r)*found* IF(*r=*P) r+; p+; else break; if(*r=0)

5、 a=w; w+; r=t2; while(*r) *a=*r; a+; r+; main() char s100,t1100,t2100,W100; printf(“nPlease enter string S:“); scanf(“s“,s); printf(“nPlease enter substring t1:“); scanf(“s“,t1); printf(“nPlease enter substring t2:“); scanf(“s“,t2); if(strlen(t1)=strlen(t2) fun(s,t1,t2,W); printf (“nThe result is:sn

6、W); else printf(“nError: strlen(t1)!=strlen(t2)n“); (分数:2.00)_三、程序设计题(总题数:1,分数:2.00)3.m个人的成绩存放在 score数组中,请编写函数 fun,它的功能是:将低于平均分的人数作为函数值返回,将低于平均分的分数放在 below所指的数组中。例如,当 score数组中的数据为10、20、30、40、50、60、70、80、90 时,函数返回的人数应该是 4,below 中的数据应为10、20、30、40。注意:部分源程序在文件 PROG1C 中。请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun

7、的花括号中填入你编写的若干语句。试题程序:#includeconioh#includestdioh#includestringh#includestdlibhint fun(int score,int m,int below)void main() FILE*wf; int i,n,below9; int score9=10,20,30,40,50,60,70,80,90; system(“CLS“); n=fun(score,9,below); printf(“nBelow the average score are:“); for(i=0;in;i+) printf(“d“,belowi)

8、 wf=fopen(“outdat“,“w“); for(i=0;in;i+) fprintf(wf,“d“,belowi); fclose(wf);*(分数:2.00)_国家二级 C语言机试(操作题)模拟试卷 276答案解析(总分:6.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:2.00)1.下列给定程序中,函数 fun的功能是:求 ss所指字符串数组中长度最短的字符串所在的行下标,作为函数值返回,并把其串长放在形参 n所指的变量中。ss 所指字符串数组中共有 M个字符串,且串长小于N。 请在程序的下画线处填入正确的内容并将下画线删除,使程序得出正确的结果。 注意:部分

9、源程序给出如下。 不得增行或删行,也不得更改程序的结构! 试题程序: #includestdioh #includestringh #define M 5 #define N 20 int fun(char(*ss)N,int*n) int i,k=0,len=N; *found* for(i=0;i 【1】 ;i+) fen=strlen(ssi); if(i=0) *n=len; *found* if(len 【2】 *n) *n=len; k=i; *found* return( 【3】 ); main() char ssMN=“ shang hai“,“guangzhou“,“beij

10、ing“,“tianjing“,“chongqing“; int n,k,i; printf(“nThe original strings are:n“); for(i=0;iM;i+)puts(ssi); k=fun(ss,&n); printf(“nThe length of shortest string is:dn“,n); printf(“nThe shortest string is:sn“,ssk); (分数:2.00)_正确答案:(正确答案:(1)M (2) (3)k)解析:解析:本题考查:for 循环语句的循环条件;if 语句条件表达式;return 语句完成函数值的返回。填

11、空 1:题目指出 ss所指字符串数组中共有 M个字符串,所以 for循环语句的循环条件是 iM。 填空2:要求求长度最短的字符串,*n 中存放的是已知字符串中长度最短的字符串的长度,将当前字符串长度与*n 比较,若小于*n,则将该长度值赋给*n,因此 if语句的条件表达式为 len*n。 填空 3:将最短字符串的行下标作为函数值返回,变量 k存储行下标的值。二、程序修改题(总题数:1,分数:2.00)2.下列给定程序中,函数 fun的功能是:将 s所指字符串中最后一次出现的与 t1所指字符串相同的子串替换成 t2所指字符串,所形成的新串放在 w所指的数组中。要求 t1和 t2所指字符串的长度相

12、同。例如,当 S所指字符串中的内容为“abcdabfabc”,t1 所指串中的内容为“ab”,t2 所指子串中的内容为“99”时,结果在 w所指的数组中的内容应为“abcdabt99c”。请改正程序中的错误,使它能得出正确的结果。注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构!试题程序:#includeconioh#includestdioh#includestringhvoid fun(char *s,char t1,char t2,char w) char*P,*r,*a; strcpy(w,S);*found* while(w) p=W; r=t1; while(*r

13、)*found* IF(*r=*P) r+; p+; else break; if(*r=0) a=w; w+; r=t2; while(*r) *a=*r; a+; r+; main() char s100,t1100,t2100,W100; printf(“nPlease enter string S:“); scanf(“s“,s); printf(“nPlease enter substring t1:“); scanf(“s“,t1); printf(“nPlease enter substring t2:“); scanf(“s“,t2); if(strlen(t1)=strlen

14、t2) fun(s,t1,t2,W); printf (“nThe result is:sn“,W); else printf(“nError: strlen(t1)!=strlen(t2)n“); (分数:2.00)_正确答案:(正确答案:(1)while(*w) (2)if(*r=*p)解析:解析:(1)此处要判断的是值的真假,而不是地址,所以改为 while(*w)。 (2)c 语言中关键字区分大小写,只需运行程序,就可以根据错误提示找到。三、程序设计题(总题数:1,分数:2.00)3.m个人的成绩存放在 score数组中,请编写函数 fun,它的功能是:将低于平均分的人数作为函数值返

15、回,将低于平均分的分数放在 below所指的数组中。例如,当 score数组中的数据为10、20、30、40、50、60、70、80、90 时,函数返回的人数应该是 4,below 中的数据应为10、20、30、40。注意:部分源程序在文件 PROG1C 中。请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。试题程序:#includeconioh#includestdioh#includestringh#includestdlibhint fun(int score,int m,int below)void main() FILE*wf; int

16、i,n,below9; int score9=10,20,30,40,50,60,70,80,90; system(“CLS“); n=fun(score,9,below); printf(“nBelow the average score are:“); for(i=0;in;i+) printf(“d“,belowi);* wf=fopen(“outdat“,“w“); for(i=0;in;i+) fprintf(wf,“d“,belowi); fclose(wf);*(分数:2.00)_正确答案:(正确答案:int fun(int score,int m,int below) int i,j=0 ; float av=00; for(i=0;im;i+) av=av+scoreim;*求平均值* for(i=0 ;im;i+) if(scoreiav)*如果分数低于平均分,则将此分数放入 below数组中* belowj+=scorei; return j;*返回低于平均分的人数* )解析:解析:要计算低于平均分的人数,首先应该求出平均分,然后通过 for循环语句和 if条件语句找出低于平均分的分数。该题第 1个循环的作用是求出平均分 aV,第 2个循环的作用是找出低于平均分的成绩记录并存入 below数组中。

展开阅读全文
相关资源
猜你喜欢
  • ISO 7969-1985 Manganese ores and concentrates Determination of sodium and potassium contents Flame atomic absorption spectrometric method《锰矿石和锰精矿 钠和钾含量的测定 火焰原子吸.pdf ISO 7969-1985 Manganese ores and concentrates Determination of sodium and potassium contents Flame atomic absorption spectrometric method《锰矿石和锰精矿 钠和钾含量的测定 火焰原子吸.pdf
  • ISO 797-1973 Aluminium and aluminium alloys Determination of silicon Gravimetric method《铝和铝合金 硅含量的测定 重量法》.pdf ISO 797-1973 Aluminium and aluminium alloys Determination of silicon Gravimetric method《铝和铝合金 硅含量的测定 重量法》.pdf
  • ISO 7973-1992 Cereals and milled cereal products determination of the viscosity of flour method using an amylograph《谷物和精制谷物制品 面粉粘度的测定 (淀粉)糊化力测定法》.pdf ISO 7973-1992 Cereals and milled cereal products determination of the viscosity of flour method using an amylograph《谷物和精制谷物制品 面粉粘度的测定 (淀粉)糊化力测定法》.pdf
  • ISO 7975-2006 Passenger cars - Braking in a turn - Open-loop test method《乘用车 转向时制动 开环试验法》.pdf ISO 7975-2006 Passenger cars - Braking in a turn - Open-loop test method《乘用车 转向时制动 开环试验法》.pdf
  • ISO 7976-1-1989 Tolerances for building methods of measurement of buldings and building products part 1 methods and instruments《建筑公差 建筑物和建筑制品的测量方法 第1部分 方法和仪器》.pdf ISO 7976-1-1989 Tolerances for building methods of measurement of buldings and building products part 1 methods and instruments《建筑公差 建筑物和建筑制品的测量方法 第1部分 方法和仪器》.pdf
  • ISO 7976-2-1989 Tolerances for building methods of measurement of buildings and building products part 2 position of measuring points《建筑公差 建筑物和建筑制品的测量方法 第2部分 测点.pdf ISO 7976-2-1989 Tolerances for building methods of measurement of buildings and building products part 2 position of measuring points《建筑公差 建筑物和建筑制品的测量方法 第2部分 测点.pdf
  • ISO 7980-1986 Water quality Determination of calcium and magnesium Atomic absorption spectrometric method《水质 钙和镁的测定 原子吸收光谱法》.pdf ISO 7980-1986 Water quality Determination of calcium and magnesium Atomic absorption spectrometric method《水质 钙和镁的测定 原子吸收光谱法》.pdf
  • ISO 7983-1988 Woodworking machines single blade circular sawing machines with travelling table nomenclature and acceptance conditions《木工机械 带移动工作台木工圆锯机 术语及验收条件》.pdf ISO 7983-1988 Woodworking machines single blade circular sawing machines with travelling table nomenclature and acceptance conditions《木工机械 带移动工作台木工圆锯机 术语及验收条件》.pdf
  • ISO 7984-1988 Woodworking machines technical classification of woodworking machines and auxiliary machines for woodworking《木工机械 木工机床及辅机的分类》.pdf ISO 7984-1988 Woodworking machines technical classification of woodworking machines and auxiliary machines for woodworking《木工机械 木工机床及辅机的分类》.pdf
  • 相关搜索

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

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