【计算机类职业资格】三级网络技术机试-244及答案解析.doc

上传人:medalangle361 文档编号:1321946 上传时间:2019-10-17 格式:DOC 页数:4 大小:29.50KB
下载 相关 举报
【计算机类职业资格】三级网络技术机试-244及答案解析.doc_第1页
第1页 / 共4页
【计算机类职业资格】三级网络技术机试-244及答案解析.doc_第2页
第2页 / 共4页
【计算机类职业资格】三级网络技术机试-244及答案解析.doc_第3页
第3页 / 共4页
【计算机类职业资格】三级网络技术机试-244及答案解析.doc_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
资源描述

1、三级网络技术机试-244 及答案解析(总分:100.00,做题时间:90 分钟)一、上机题(总题数:1,分数:100.00)1.请编制函数 ReadDat()实现从文件 IN.DAT 中读取 1000 个十进制整数到数组 xx 中;请编制函数Compute()分别计算出 XX 中偶数的个数 even,奇数的平均值 avel,偶数的平均值 ave2 以及方差 totfc 的值,最后调用函数 WriteDat()把结果输出到 OUT.DAT 文件中。计算方差的公式如下:*设 N 为偶数的个数,xxi为偶数,ave2 为偶数的平均值。原始数据文件存放的格式是:每行存放 10 个数,并用逗号隔开(每个

2、数均大于 0 且小于等于 2000)。注意:部分源程序已给出。请勿改动主函数 main()和输出数据函数 WriteDat()的内容。试题程序:#includestdio.h#includestdlib.h#includestring.h#define MAX 1000int xxMAX,odd=0,even=0;double avel=0.0,ave2=0.0,totfc=0.0;void WriteDat(void);int ReadDat(void)int i;FILE*fp;if(fp=fopen(“IN.DAT“,“r“)=NULL)return 1;/*编制函数 ReadDat()

3、的部分*/*/fclose(fp);return 0;void Compute(void)int i,yyMAX;for(i=0;iMAX;i+)yyi=0;for(i=0;iMAX;i+)if(xxi%2=0) 测试结点 i 是否是偶数yyeven+=xxi;将结点 i 存入数组 yy 中ave2+=xxi; 将结点 i 累加存入 ave2 中else如果结点 i 不是偶数odd+;累加变量 odd 记录奇数数的个数avel+=xxi; 将 xxi累加存入 avel 中if(odd=0)avel=0;else avel/=odd;计算奇数数的平均数if(even=0)ave2=0;else

4、ave2/=even;计算偶数数的平均数for(i=0;ieven;i+)totfc+=(yyi-ave2)*(yyi-ave2)/even;void main()int i;for(i=0;iMAX;i+)xxi=0;if(ReadDat()printf(“数据文件 IN.DAT 不能打开!/007/n“);return;Compute();printf(“EVEN=%d/nAVE1=%f/nAVER2=%f/nTOTFC=%f/n“,even,avel,ave2,totfc);WriteDat();void WriteDat(void)FILE*fp;int i;fp=fopen(“OUT

5、DAT“,“w“);fprintf(fp,“%d/n%f/n%f/n%f/n“,even,avel,ave2,totfc);fclose(fp);(分数:100.00)_三级网络技术机试-244 答案解析(总分:100.00,做题时间:90 分钟)一、上机题(总题数:1,分数:100.00)1.请编制函数 ReadDat()实现从文件 IN.DAT 中读取 1000 个十进制整数到数组 xx 中;请编制函数Compute()分别计算出 XX 中偶数的个数 even,奇数的平均值 avel,偶数的平均值 ave2 以及方差 totfc 的值,最后调用函数 WriteDat()把结果输出到 OU

6、T.DAT 文件中。计算方差的公式如下:*设 N 为偶数的个数,xxi为偶数,ave2 为偶数的平均值。原始数据文件存放的格式是:每行存放 10 个数,并用逗号隔开(每个数均大于 0 且小于等于 2000)。注意:部分源程序已给出。请勿改动主函数 main()和输出数据函数 WriteDat()的内容。试题程序:#includestdio.h#includestdlib.h#includestring.h#define MAX 1000int xxMAX,odd=0,even=0;double avel=0.0,ave2=0.0,totfc=0.0;void WriteDat(void);in

7、t ReadDat(void)int i;FILE*fp;if(fp=fopen(“IN.DAT“,“r“)=NULL)return 1;/*编制函数 ReadDat()的部分*/*/fclose(fp);return 0;void Compute(void)int i,yyMAX;for(i=0;iMAX;i+)yyi=0;for(i=0;iMAX;i+)if(xxi%2=0) 测试结点 i 是否是偶数yyeven+=xxi;将结点 i 存入数组 yy 中ave2+=xxi; 将结点 i 累加存入 ave2 中else如果结点 i 不是偶数odd+;累加变量 odd 记录奇数数的个数avel

8、xxi; 将 xxi累加存入 avel 中if(odd=0)avel=0;else avel/=odd;计算奇数数的平均数if(even=0)ave2=0;else ave2/=even;计算偶数数的平均数for(i=0;ieven;i+)totfc+=(yyi-ave2)*(yyi-ave2)/even;void main()int i;for(i=0;iMAX;i+)xxi=0;if(ReadDat()printf(“数据文件 IN.DAT 不能打开!/007/n“);return;Compute();printf(“EVEN=%d/nAVE1=%f/nAVER2=%f/nTOTFC=

9、f/n“,even,avel,ave2,totfc);WriteDat();void WriteDat(void)FILE*fp;int i;fp=fopen(“OUT.DAT“,“w“);fprintf(fp,“%d/n%f/n%f/n%f/n“,even,avel,ave2,totfc);fclose(fp);(分数:100.00)_正确答案:(for(i=0;iMAX;i+)fscanf(fp,“%d,“,xxi); 读取文件中的数据存入变量 xxi中if(i+1)%10=0) 每行存 10 个数fscanf(fp,“/n“);读取行后的换行符)解析:本题考查文件的操作、奇偶判断和数学公式的计算。函数 ReadDat 的作用是将从文件中读取数据存入数组 xx 中,图为数据存放入文件的格式是每个数据被逗号隔开,所以 fscanf(fp,“%d,“,&xxi)语句中字符串“%d,“中要加入逗号。函数 Compute 的作用是计算方差,思路是首先顺序读取数组 xx 中的结点,若是偶数累加存入 ave2,个数存入 even,若不是偶数(即为奇数)累加结果存入 avel,个数存入odd。然后计算奇数和偶数的平均数,利用循环结构依次读取存放偶数的数组 yy,计算方差 totfc。

展开阅读全文
相关资源
猜你喜欢
  • GOST EN 15928-2013 Fertilizers Determination of the fineness of grinding (dry method)《肥料 粉碎细度的测定 (干燥法)》.pdf GOST EN 15928-2013 Fertilizers Determination of the fineness of grinding (dry method)《肥料 粉碎细度的测定 (干燥法)》.pdf
  • GOST EN 15956-2012 Fertilizers Extraction of phosphorus soluble in mineral acids《肥料 无机酸中可溶性磷的萃取》.pdf GOST EN 15956-2012 Fertilizers Extraction of phosphorus soluble in mineral acids《肥料 无机酸中可溶性磷的萃取》.pdf
  • GOST EN 15957-2012 Fertilizers Extraction of phosphorus which is soluble in neutral ammonium citrate《肥料 中性柠檬酸铵中可溶性磷的萃取》.pdf GOST EN 15957-2012 Fertilizers Extraction of phosphorus which is soluble in neutral ammonium citrate《肥料 中性柠檬酸铵中可溶性磷的萃取》.pdf
  • GOST EN 15960-2014 Fertilizers Extraction of total calcium total magnesium total sodium and total sulfur in the forms of sulfates《肥料 硫酸盐形式中的钙 镁 钠和硫总量的萃取 》.pdf GOST EN 15960-2014 Fertilizers Extraction of total calcium total magnesium total sodium and total sulfur in the forms of sulfates《肥料 硫酸盐形式中的钙 镁 钠和硫总量的萃取 》.pdf
  • GOST EN 15961-2014 Fertilizers Extraction of water-soluble calcium magnesium sodium and sulfur in the form of sulfates《 肥料 硫酸盐形式中的水溶性钙 镁 钠和硫的萃取》.pdf GOST EN 15961-2014 Fertilizers Extraction of water-soluble calcium magnesium sodium and sulfur in the form of sulfates《 肥料 硫酸盐形式中的水溶性钙 镁 钠和硫的萃取》.pdf
  • GOST EN 15962-2014 Fertilizers Determination of the complexed micro-nutrient content and of the complexed fraction of micro-nutrients《肥料 微量营养物质复杂微量营养素含量和复杂分数的测定》.pdf GOST EN 15962-2014 Fertilizers Determination of the complexed micro-nutrient content and of the complexed fraction of micro-nutrients《肥料 微量营养物质复杂微量营养素含量和复杂分数的测定》.pdf
  • GOST EN 1601-2012 Liquid petroleum products Unleaded petrol Determination of organic oxygenate compounds and total organically bound oxygen content by gas chromatography method usiD)《液.pdf GOST EN 1601-2012 Liquid petroleum products Unleaded petrol Determination of organic oxygenate compounds and total organically bound oxygen content by gas chromatography method usiD)《液.pdf
  • GOST EN 1602-2011 Thermal insulating products in building applications Method for determination of the apparent density《建筑物用热绝缘产品 表观密度的测定方法》.pdf GOST EN 1602-2011 Thermal insulating products in building applications Method for determination of the apparent density《建筑物用热绝缘产品 表观密度的测定方法》.pdf
  • GOST EN 1604-2011 Thermal insulating products in building applications Method for determination of dimensional stability under specified temperature and humidity conditions《建筑用热绝缘产.pdf GOST EN 1604-2011 Thermal insulating products in building applications Method for determination of dimensional stability under specified temperature and humidity conditions《建筑用热绝缘产.pdf
  • 相关搜索

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

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