[计算机类试卷]国家三级信息管理技术机试模拟试卷47及答案与解析.doc

上传人:figureissue185 文档编号:494974 上传时间:2018-11-28 格式:DOC 页数:2 大小:30.50KB
下载 相关 举报
[计算机类试卷]国家三级信息管理技术机试模拟试卷47及答案与解析.doc_第1页
第1页 / 共2页
[计算机类试卷]国家三级信息管理技术机试模拟试卷47及答案与解析.doc_第2页
第2页 / 共2页
亲,该文档总共2页,全部预览完了,如果喜欢就下载吧!
资源描述

1、国家三级信息管理技术机试模拟试卷 47及答案与解析 一、程序设计题 1 函数 ReadDat()实现从文件 IN47.DAT中读取 1000个十进制整数到数组 xx中。请编制函数 Compute()分别计算出 xx中偶数的个数 even、奇数的平均值 avel、偶数的平均值 ave2及所有偶数的方差 toffc的值,最后调用函数 WriteDat()把结果输出到 OUT47.DAT文件中。 计算方差的公式如下: 设 N为偶数的个数, xxi为偶数, ave2为偶数的平均值。 原始数据的存放格式是:每行存放 10个数,并用逗号隔开 (每个数均大于 0且小于等于 2000)。 注意:部分源程序已给

2、出。 请勿改动主函数 main()、读函数 ReadDat()和写函数 WriteDat()的内容。 试题程序: #include stdio.h #include stdlib.h #include string.h #define MAX 1000 int xxMAX,odd=0,even=0; double avel=0.0,ave2=0.0,totfc=0,0 void WriteDat(void); int ReadDat(void) FILE *fp; int i,j; if(fp=fopen(“IN47.DAT“,“r“)=NULL) return 1; for(i=0;i 10

3、0;i+) for(j=0;j10;j+) fscanf(fp,“%d,“, fscanf(fp,“/n“); if(feof(fp) break; fclose(fp); viod Compute(void) void main( ) int i; for(i=0;i MAX;i+) xxi=0; if(ReadDat() print f ( “数据文件 IN47.DAT 不能打形式 !007n“); return; Compute(); printf( “EVEN=%dnAVE1=%fnAVE2=%fnTOTFC=%fn“,even,avel,ave2,totfc); WriteDat()

4、 void WriteDat(void) FILE *fp; int i; fp=fopen(“OUT47.DAT“,“w“); fprintf(fp,“%dn%lfn%lfn%lfn“,even,ave1,ave2,totfc); fclose(fp); 国家三级信息管理技术机试模拟试卷 47答案与解析 一、程序设计题 1 【正确答案】 void Compute(void) int i,yyMAX; for(i=0;i 1000;i+) if(xxi%2!=0) odd+; /*统计奇数的个数 */ ave1+=xx i; /*求奇数的总和 */ else even+ +; /*统计偶数的

5、个数 */ ave2+=xx i; /*求偶数的总和 */ yy even-1=xx i; /*将偶数存入数组 yy中 */ ave1/=odd; /*求奇数的平均数 */ ave2/=even; /*求偶数的平均数 */ for (i=0; i even; i+) /“*求所有偶数的方差 */ totfc+= (yyi-ave2)* (yy i-ave2)/even; 【试题解析】 本题考查的知识点如下: (1)从文件中读取数据。 (2)奇偶数的判断和方差的求法。 在 C语言中,有一结构体类型 FILE,其中包含 文件的一些属性信息。可定义指针指向该结构体,这个指针称为文件指针。要从文件中读取数据,首先要判断该文件是否能以 “读 ”的方式打开。若能打开,使用函数 int fscanf(FILE*fp,char*format,args)从 fp所指向的文件中依次读取数据。在本题中,数据的存放很有规律,将数据读出存入数组 xx时,只要控制数组下标就可以了。若文件结束,则退出读取循环。最后要关闭文件。若一个数除以 2取余得 0,则该数是偶数,否则为奇数。由方差公式可知,这是求一些连续的数的表达式的值,所以可以使用循环求得方差。

展开阅读全文
相关资源
猜你喜欢
  • ANSI UL 22-2008 UL Standard for Safety Amusement and Gaming Machines (Sixth Edition Reprint with Revisions Through and Including October 29 2014).pdf ANSI UL 22-2008 UL Standard for Safety Amusement and Gaming Machines (Sixth Edition Reprint with Revisions Through and Including October 29 2014).pdf
  • ANSI UL 2200-2012 UL Standard for Safety Stationary Engine Generator Assemblies (Second Edition Reprint with revisions through and including July 29 2015)《固定发电机组件用安全性标准》.pdf ANSI UL 2200-2012 UL Standard for Safety Stationary Engine Generator Assemblies (Second Edition Reprint with revisions through and including July 29 2015)《固定发电机组件用安全性标准》.pdf
  • ANSI UL 2201-2018 UL Standard for Safety Carbon Monoxide (CO) Emission Rate of Portable Generators (Second Edition Reprint with revisions through and including January 24 2018).pdf ANSI UL 2201-2018 UL Standard for Safety Carbon Monoxide (CO) Emission Rate of Portable Generators (Second Edition Reprint with revisions through and including January 24 2018).pdf
  • ANSI UL 2202-2009 UL Standard for Safety Electric Vehicle (EV) Charging System Equipment (Second Edition Reprint with revisions through and including December 14 2012)《电子车辆(EV)充电系统.pdf ANSI UL 2202-2009 UL Standard for Safety Electric Vehicle (EV) Charging System Equipment (Second Edition Reprint with revisions through and including December 14 2012)《电子车辆(EV)充电系统.pdf
  • ANSI UL 2208-2010 UL Standard for Safety Solvent Distillation Units (Third Edition Reprint with Revisions Through and Including September 4 2015).pdf ANSI UL 2208-2010 UL Standard for Safety Solvent Distillation Units (Third Edition Reprint with Revisions Through and Including September 4 2015).pdf
  • ANSI UL 2218-2010 UL Standard for Safety Impact Resistance of Prepared Roof Covering Materials (Second Edition Reprint with Revisions Through and Including January 12 2018).pdf ANSI UL 2218-2010 UL Standard for Safety Impact Resistance of Prepared Roof Covering Materials (Second Edition Reprint with Revisions Through and Including January 12 2018).pdf
  • ANSI UL 2225-2013 UL Standard for Safety Cables and Cable-Fittings For Use In Hazardous (Classified) Locations (Fourth Edition Reprint with revisions through and including March 24.pdf ANSI UL 2225-2013 UL Standard for Safety Cables and Cable-Fittings For Use In Hazardous (Classified) Locations (Fourth Edition Reprint with revisions through and including March 24.pdf
  • ANSI UL 2227-2007 UL Standard for Safety Overfilling Prevention Devices (Second Edition Reprint with revisions through and including June 6 2014)《防溢满装置的标准》.pdf ANSI UL 2227-2007 UL Standard for Safety Overfilling Prevention Devices (Second Edition Reprint with revisions through and including June 6 2014)《防溢满装置的标准》.pdf
  • ANSI UL 2231-1-2012 UL Standard for Safety Personnel Protection Systems for Electric Vehicle (EV) Supply Circuits General Requirements (Second Edition Reprint with revisions throug.pdf ANSI UL 2231-1-2012 UL Standard for Safety Personnel Protection Systems for Electric Vehicle (EV) Supply Circuits General Requirements (Second Edition Reprint with revisions throug.pdf
  • 相关搜索

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

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