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

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

1、国家二级 C语言机试(操作题)模拟试卷 431及答案解析(总分:6.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:2.00)1.给定程序中,函数 fun的功能是:计算出形参 s所指字符串中包含的单词个数,作为函数值返回。为便于统计,规定各单词之间用空格隔开。 例如,形参 s所指的字符串为:This is a clan guage program,函数的返回值为 6。 请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。 注意:部分源程序在文件 BIANK1C 中。 不得增行或删行,也不得更改程序的结构! 试题程序:#include stdioh int fun

2、char,* s) int n=0,flag=0; while(* s!=/0) if(*s!=&f1ag=0) /*found*/ 【1】 ;f1ag=1; /*found*/ if(* s=)f1ag= 【2】 ; /*found*/ 【3】 ; returen; main() char str81;int n; printf(“/nEnter a line text:/n“); gets(str); n=fun(str); printf(“/nThere ared words in this text/n/n“,n); (分数:2.00)_二、程序修改题(总题数:1,分数:2.00)2

3、下列给定程序中,函数 fun的功能是:从 n个学生的成绩中统计出低于平均分的学生人数,此人数作为函数值返回,平均分存放在形参 aver所指的存储单元中。 例如,输入 8名学生的成绩:805、60、72、905、98、515、88、64 则低于平均分的学生人数为 4(平均分为 755625)。 请改正程序中的错误,使它能得出正确的结果。 注意:部分源程序在文件 MODI1C 中,不要改动 main函数,不得增行或删行,也不得更改程序的结构! 试题程序:#include stdlibh #include stdioh #include conioh #define N 2 0 int fun(f

4、loat *s,int n,float *ave7)float=ave,t=00; int count=0,k,i; for(k=0; k n;k+)/*found*/ t=sk; ave=t/n; for(i=0;i n;i+) if(si ave)count;+;/*found*/ *aver=&ave; return count; void main() float:s30,aver; int m,i; system(“CLS“); print:f(“/nPlease enter m:“); scanf(“d“,&m); print;f(“/nPlease enterd mark:/n“

5、m);for(i=0;i m;i+) scanf(“f“,s+i); print:f(“/nThe number of students:d/n“,fun(s,m,&aver); print:f(“Ave=f/n“,aver); (分数:2.00)_三、程序设计题(总题数:1,分数:2.00)3.请编写一个函数 int fun(int*s,int t,int*k),用来求出数组的最大元素在数组中的 下标并存放在k所指向的存储单元中。 例如,输入如下整数: 876 675 896 101 301 401 980 431 45l 777 则输出结果为 6,980。 注意:部分源程序在文件 PRO

6、G1C 中。 请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。 试题程序:#include conioh #include stdioh #include stdlibh int fun(int*s,int t,int*k)void main() FILE*wf; int a10=87 6,67 5,896,101,301,4 01,980,431,451,7 7 7,k; system(“CLS“); fun(a,10,&k); print:f(“d,d/n“,k,ak);/*found*/ wf=fopen(“outdat“,“w“); fp

7、rintf(wf,“d,d“,k,ak); fclose(wf);/*/(分数:2.00)_国家二级 C语言机试(操作题)模拟试卷 431答案解析(总分:6.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:2.00)1.给定程序中,函数 fun的功能是:计算出形参 s所指字符串中包含的单词个数,作为函数值返回。为便于统计,规定各单词之间用空格隔开。 例如,形参 s所指的字符串为:This is a clan guage program,函数的返回值为 6。 请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。 注意:部分源程序在文件 BIANK1C 中。 不得增

8、行或删行,也不得更改程序的结构! 试题程序:#include stdioh int fun(char,* s) int n=0,flag=0; while(* s!=/0) if(*s!=&f1ag=0) /*found*/ 【1】 ;f1ag=1; /*found*/ if(* s=)f1ag= 【2】 ; /*found*/ 【3】 ; returen; main() char str81;int n; printf(“/nEnter a line text:/n“); gets(str); n=fun(str); printf(“/nThere ared words in this te

9、xt/n/n“,n); (分数:2.00)_正确答案:(正确答案:(1)n+ (2)0 (3)s+)解析:解析:填空 1:单词个数用变量 n来统计,当前字母不是空格且 f1ag状态标志为 0时,可以判断出现一个新的单词,则单词数就加 1,将状态标志 f1ag置为 l,所以应填 n+。 填空 2:当前字符是空格时,f1ag 状态标志置 0,所以应填 0。 填空 3:判断完一个字符之后,要继续判断字符串的下一个位置,所以应填 s+。二、程序修改题(总题数:1,分数:2.00)2.下列给定程序中,函数 fun的功能是:从 n个学生的成绩中统计出低于平均分的学生人数,此人数作为函数值返回,平均分存放在

10、形参 aver所指的存储单元中。 例如,输入 8名学生的成绩:805、60、72、905、98、515、88、64 则低于平均分的学生人数为 4(平均分为 755625)。 请改正程序中的错误,使它能得出正确的结果。 注意:部分源程序在文件 MODI1C 中,不要改动 main函数,不得增行或删行,也不得更改程序的结构! 试题程序:#include stdlibh #include stdioh #include conioh #define N 2 0 int fun(float *s,int n,float *ave7)float=ave,t=00; int count=0,k,i; fo

11、r(k=0; k n;k+)/*found*/ t=sk; ave=t/n; for(i=0;i n;i+) if(si ave)count;+;/*found*/ *aver=&ave; return count; void main() float:s30,aver; int m,i; system(“CLS“); print:f(“/nPlease enter m:“); scanf(“d“,&m); print;f(“/nPlease enterd mark:/n“,m);for(i=0;i m;i+) scanf(“f“,s+i); print:f(“/nThe number of

12、students:d/n“,fun(s,m,&aver); print:f(“Ave=f/n“,aver); (分数:2.00)_正确答案:(正确答案:(1)t+=sk; (2)*aver=ave;)解析:解析:根据题目要求,可利用循环语句累计 n个学生的总分,求得平均成绩后,再利用循环语句和条件选择语句进行后面的操作。若小于平均值,则将该值存放于 aver存储单元中。t=sk是循环叠加错误,* aver=&ave 为语法指向的错误。三、程序设计题(总题数:1,分数:2.00)3.请编写一个函数 int fun(int*s,int t,int*k),用来求出数组的最大元素在数组中的 下标并存放

13、在k所指向的存储单元中。 例如,输入如下整数: 876 675 896 101 301 401 980 431 45l 777 则输出结果为 6,980。 注意:部分源程序在文件 PROG1C 中。 请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。 试题程序:#include conioh #include stdioh #include stdlibh int fun(int*s,int t,int*k)void main() FILE*wf; int a10=87 6,67 5,896,101,301,4 01,980,431,451,7 7

14、 7,k; system(“CLS“); fun(a,10,&k); print:f(“d,d/n“,k,ak);/*found*/ wf=fopen(“outdat“,“w“); fprintf(wf,“d,d“,k,ak); fclose(wf);/*/(分数:2.00)_正确答案:(正确答案:int fun (int * s,int t,int *k) int i; *k=0;/*k 所指的数是数组的下标值*/ for(i=0,i t; i+) if(s*k si) *k=i; /* 找到数组的最大元素,把该元素的下标赋给 k所指的数*/ return s*k;/*返回数组的最大元素*/ )解析:解析:本题中直接使用指针变量 k,使用时要注意对 k进行指针运算。程序一开始让 k指向数组中的第一个元素,即*k =0。

展开阅读全文
相关资源
猜你喜欢
  • IEC 80001-1-2010 Application of risk management for IT-networks incorporating medical devices - Part 1 Roles responsibilities and activities《并入IT网络的医疗设备用风险管理的应用.第1部分 作用 职责和活动》.pdf IEC 80001-1-2010 Application of risk management for IT-networks incorporating medical devices - Part 1 Roles responsibilities and activities《并入IT网络的医疗设备用风险管理的应用.第1部分 作用 职责和活动》.pdf
  • IEC 80369-5-2016 Small-bore connectors for liquids and gases in healthcare applications - Part 5 Connectors for limb cuff inflation applications《医疗保健设施中液体与气体用小孔连接器 第5部分 肢体袖口充气应用连接器》.pdf IEC 80369-5-2016 Small-bore connectors for liquids and gases in healthcare applications - Part 5 Connectors for limb cuff inflation applications《医疗保健设施中液体与气体用小孔连接器 第5部分 肢体袖口充气应用连接器》.pdf
  • IEC 80416-1-2008 Basic principles for graphical symbols for use on equipment - Part 1 Creation of graphical symbols for registration《设备用图形符号的基本原则.第1部分 注册用图形符号的制定 n》.pdf IEC 80416-1-2008 Basic principles for graphical symbols for use on equipment - Part 1 Creation of graphical symbols for registration《设备用图形符号的基本原则.第1部分 注册用图形符号的制定 n》.pdf
  • IEC 80416-3-2002 Basic principles for graphical symbols for use on equipment - Part 3 Guidelines for the application of graphical symbols《用在设备上的图形符号的基本原则.第3部分 图形符号使用导则》.pdf IEC 80416-3-2002 Basic principles for graphical symbols for use on equipment - Part 3 Guidelines for the application of graphical symbols《用在设备上的图形符号的基本原则.第3部分 图形符号使用导则》.pdf
  • IEC 80601-2-35-2009 Medical electrical equipment - Part 2-35 Particular requirements for the basic safety and essential performance of heating devices using blankets pads or mattre.pdf IEC 80601-2-35-2009 Medical electrical equipment - Part 2-35 Particular requirements for the basic safety and essential performance of heating devices using blankets pads or mattre.pdf
  • IEC 80601-2-60-2012 Medical electrical equipment - Part 2-60 Particular requirements for basic safety and essential performance of dental equipment《医用电气设备.第2-60部分 牙科设备基本安全和基本性能的详细要求.》.pdf IEC 80601-2-60-2012 Medical electrical equipment - Part 2-60 Particular requirements for basic safety and essential performance of dental equipment《医用电气设备.第2-60部分 牙科设备基本安全和基本性能的详细要求.》.pdf
  • IEC 81714-2-2006 Design of graphical symbols for use in the technical documentation of products - Part 2 Specification for graphical symbols in a computer sensible form including g.pdf IEC 81714-2-2006 Design of graphical symbols for use in the technical documentation of products - Part 2 Specification for graphical symbols in a computer sensible form including g.pdf
  • IEC 82079-1-2012 Preparation of instructions for use - Structuring content and presentation - Part 1 General principles and detailed requirements《使用说明书的准备.结构化 内容和陈述.第1部分 总则和详细要求》.pdf IEC 82079-1-2012 Preparation of instructions for use - Structuring content and presentation - Part 1 General principles and detailed requirements《使用说明书的准备.结构化 内容和陈述.第1部分 总则和详细要求》.pdf
  • IEC 82304-1-2016 Health software - Part 1 General requirements for product safety《健康软件 第1部分 产品安全通用要求》.pdf IEC 82304-1-2016 Health software - Part 1 General requirements for product safety《健康软件 第1部分 产品安全通用要求》.pdf
  • 相关搜索

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

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