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

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

1、国家二级 C语言机试(操作题)模拟试卷 306及答案解析(总分:6.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:2.00)1.给定程序中,函数 fun的功能是:判断形参 s所指字符串是否是“回文“(Palindrome),若是,函数返回值为 1;不是,函数返回值为 0。“回文是正读和反读都一样的字符串(不区分大小写字母)。 例如,LEVEL和 Level是回文“,而 LEVLEV不是“回文“。 请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。 注意:部分源程序在文件 BLANK1C 中。 不得增行或删行,也不得更改程序的结构! 试题程序: #includ

2、estdioh #includestringh #includectypeh int fun(char*s) char*lp,*rp; *found* lp= 【1】 ; rp=s+strlen(s)1; while(toupper(*ip)=toupper (*rp)(lprp) *found* lp+;rp 【2】 ; *found* if(lprp) 【3】 ; else return 1; main() char s81; printf(“Enter a string:“); scanf(“s“,s); if(fun(s) printf(“n“sis a Palindromenn”,s

3、); else printf(“n“s“isnt a Palindromenn“,s); (分数:2.00)_二、程序修改题(总题数:1,分数:2.00)2.下列给定程序中,函数 fun的功能是:找出一个大于给定整数 m且紧随 m的素数,并作为函数值返回。请改正程序中的错误,使它能得出正确的结果。注意:部分源程序在文件 MODI1C 中,不要改动 main函数,不得增行或删行,也不得更改程序的结构!试题程序:#includestdlibh#includeconioh#includestdiohint fun(int m) int i,k; for(i=m+1;i+) for(k=2;ki;k+

4、)*found* if(ik!=0) break;*found* if(ki) return(i); void main()int n; system(“CLS“);printf(“nPlease enter n:“); scanf(“d“,n); print;f(dn,fun(n);(分数:2.00)_三、程序设计题(总题数:1,分数:2.00)3.学生的记录由学号和成绩组成,N 名学生的数据已放入主函数中的结构体数组 s中,请编写函数 fun,其功能是:把分数最高的学生数据放在 b所指的数组中。注意:分数最高的学生可能不止一个,函数返回分数最高的学生人数。注意:部分源程序给出如下。请勿改动

5、主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。试题程序: #includestdioh #define N 16 typedef struct char num10; int s; STREC; int fun(STREC*a,STREC*b) void main() STREC SN=“GA005“,85,“GA003“,76,“GA002“,69,“GA004“,85,“GA001“,91,“GA007“,72,“GA008“,64,“GA006“,87,“GA015“,85,“GA013“,91,“GA012“,64,“GA014“,91,“GA

6、011“,77,“GA017“,64,“GA018“,64,“GA016“,72; STREC hN; int i,n; n=fun(s,h); printf(“Thed highest score:n“,n); for(i=0 ;in;i+) printf(“s4dn“,hinum,his);*输出最高分学生的学号和成绩* printf(“n“);(分数:2.00)_国家二级 C语言机试(操作题)模拟试卷 306答案解析(总分:6.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:2.00)1.给定程序中,函数 fun的功能是:判断形参 s所指字符串是否是“回文“(Palindr

7、ome),若是,函数返回值为 1;不是,函数返回值为 0。“回文是正读和反读都一样的字符串(不区分大小写字母)。 例如,LEVEL和 Level是回文“,而 LEVLEV不是“回文“。 请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。 注意:部分源程序在文件 BLANK1C 中。 不得增行或删行,也不得更改程序的结构! 试题程序: #includestdioh #includestringh #includectypeh int fun(char*s) char*lp,*rp; *found* lp= 【1】 ; rp=s+strlen(s)1; while(touppe

8、r(*ip)=toupper (*rp)(lprp) *found* lp+;rp 【2】 ; *found* if(lprp) 【3】 ; else return 1; main() char s81; printf(“Enter a string:“); scanf(“s“,s); if(fun(s) printf(“n“sis a Palindromenn”,s); else printf(“n“s“isnt a Palindromenn“,s); (分数:2.00)_正确答案:(正确答案:(1)s (2)- (3)retum 0)解析:解析:填空 1:根据函数体 fun中,对变量 lp

9、和 rp的使用可知,lp 应指向形参 s的起始地址,rp指向 s的结尾地址,所以应填 s。 填空 2:rp 是指向字符串的尾指针,当每做一次循环 rp向前移动一个位置,所以应填:-。 填空 3:当 lp和 rp相等时,表示字符串是回文并返回 1,否则就返回 0,所以应填 return 0。二、程序修改题(总题数:1,分数:2.00)2.下列给定程序中,函数 fun的功能是:找出一个大于给定整数 m且紧随 m的素数,并作为函数值返回。请改正程序中的错误,使它能得出正确的结果。注意:部分源程序在文件 MODI1C 中,不要改动 main函数,不得增行或删行,也不得更改程序的结构!试题程序:#inc

10、ludestdlibh#includeconioh#includestdiohint fun(int m) int i,k; for(i=m+1;i+) for(k=2;ki;k+)*found* if(ik!=0) break;*found* if(ki) return(i); void main()int n; system(“CLS“);printf(“nPlease enter n:“); scanf(“d“,n); print;f(dn,fun(n);(分数:2.00)_正确答案:(正确答案:(1)if(ik=0) (2)if(k=i)解析:解析:(1)判断当前数是否为素数,若存在一

11、个数(除 1和其自身)能整除当前数,则跳出本次循环,所以 if条件应为 ik=0。 (2)如果 i是素数,则循环结束时 k=i,将该值返回。三、程序设计题(总题数:1,分数:2.00)3.学生的记录由学号和成绩组成,N 名学生的数据已放入主函数中的结构体数组 s中,请编写函数 fun,其功能是:把分数最高的学生数据放在 b所指的数组中。注意:分数最高的学生可能不止一个,函数返回分数最高的学生人数。注意:部分源程序给出如下。请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。试题程序: #includestdioh #define N 16 typed

12、ef struct char num10; int s; STREC; int fun(STREC*a,STREC*b) void main() STREC SN=“GA005“,85,“GA003“,76,“GA002“,69,“GA004“,85,“GA001“,91,“GA007“,72,“GA008“,64,“GA006“,87,“GA015“,85,“GA013“,91,“GA012“,64,“GA014“,91,“GA011“,77,“GA017“,64,“GA018“,64,“GA016“,72; STREC hN; int i,n; n=fun(s,h); printf(“Th

13、ed highest score:n“,n); for(i=0 ;in;i+) printf(“s4dn“,hinum,his);*输出最高分学生的学号和成绩* printf(“n“);(分数:2.00)_正确答案:(正确答案:int fun(STREC*a,STREC*b) int i,j=0,max=a0s; for(i=0;iN;i+) if(maxais)*找出最大值* max=ais; for(i=0;iN;i+) if(max=ais) bj+=ai; *找出成绩与 max相等的学生的记录,存入结构体 b中* return j; *返回最高成绩的学生人数* )解析:解析:本题考查:结构体数组操作;用循环判断结构查找数组中的最大值。 该程序使用两个循环判断语句,第 1个循环判断语句的作用是找出最大值;第 2个循环判断语句的作用是找出与 max相等的成绩(即最高成绩)的学生记录,并存入 b中。 对于如何找出数组中最大值(多个相等)的方法,我们已经不陌生。如何对结构体数组进行类似操作呢? 掌握以下语句: for(i=0;iN;i+) if(maxais)max=ais;

展开阅读全文
相关资源
猜你喜欢
  • ISO 8845 CORR 1-1995 Small craft with inboard engine - Propeller shaft ends and bosses with 1 16 taper Technical Corrigendum 1《舷内机小艇 带1 16锥度的螺旋桨轴端和轴毂 技术勘误1》.pdf ISO 8845 CORR 1-1995 Small craft with inboard engine - Propeller shaft ends and bosses with 1 16 taper Technical Corrigendum 1《舷内机小艇 带1 16锥度的螺旋桨轴端和轴毂 技术勘误1》.pdf
  • ISO 8845-1994 Small craft with inboard engine - Propeller shaft ends and bosses with 1 16 taper《舷内机小艇 带1 16锥度的螺旋桨轴端和轴毂》.pdf ISO 8845-1994 Small craft with inboard engine - Propeller shaft ends and bosses with 1 16 taper《舷内机小艇 带1 16锥度的螺旋桨轴端和轴毂》.pdf
  • ISO 8851-1-2004 Butter - Determination of moisture non-fat solids and fat contents (Routine methods) - Part 1 Determination of moisture content《黄油 水分、非脂肪固体和脂肪含量.pdf ISO 8851-1-2004 Butter - Determination of moisture non-fat solids and fat contents (Routine methods) - Part 1 Determination of moisture content《黄油 水分、非脂肪固体和脂肪含量.pdf
  • ISO 8851-2-2004 Butter - Determination of moisture non-fat solids and fat contents (Routine methods) - Part 2 Determination of non-fat solids content《黄油 水分、非脂肪固.pdf ISO 8851-2-2004 Butter - Determination of moisture non-fat solids and fat contents (Routine methods) - Part 2 Determination of non-fat solids content《黄油 水分、非脂肪固.pdf
  • ISO 8851-3-2004 Butter - Determination of moisture non-fat solids and fat contents (Routine methods) - Part 3 Calculation of fat content《黄油 水分、非脂肪固体和脂肪含量的测定(常规法.pdf ISO 8851-3-2004 Butter - Determination of moisture non-fat solids and fat contents (Routine methods) - Part 3 Calculation of fat content《黄油 水分、非脂肪固体和脂肪含量的测定(常规法.pdf
  • ISO 8853-1989 Safety harnesses for competition drivers requirements and test methods《赛车驾驶员的安全带 要求和测试方法》.pdf ISO 8853-1989 Safety harnesses for competition drivers requirements and test methods《赛车驾驶员的安全带 要求和测试方法》.pdf
  • ISO 8858-1-1990 Hard coal froth flotation testing part 1 laboratory procedure《硬煤 泡沫浮选试验 第1部分 实验室程序》.pdf ISO 8858-1-1990 Hard coal froth flotation testing part 1 laboratory procedure《硬煤 泡沫浮选试验 第1部分 实验室程序》.pdf
  • ISO 8858-2-2004 Hard coal - Froth flotation testing - Part 2 Sequential evaluation《硬煤 泡沫浮选试验 第2部分 顺序评估》.pdf ISO 8858-2-2004 Hard coal - Froth flotation testing - Part 2 Sequential evaluation《硬煤 泡沫浮选试验 第2部分 顺序评估》.pdf
  • ISO 8858-3-2004 Hard coal - Froth flotation testing - Part 3 Release evaluation《硬煤 泡沫浮选试验 第3部分 释放评价》.pdf ISO 8858-3-2004 Hard coal - Froth flotation testing - Part 3 Release evaluation《硬煤 泡沫浮选试验 第3部分 释放评价》.pdf
  • 相关搜索

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

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