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

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

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

2、勿改动主函数 main()和输出数据函数 WriteDat()的内容。试题程序:#includestdio.h#includestdlib.h#includestring.h#define MAX 1000int xxMAX,odd=0,even=0;double aver=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()*/*/fclose(fp);return 0;void Compute(void)

3、int i;for(i=0;iMAX;i+)if(xxi%2)测试结点 i 是否是奇数odd+;累加变量 odd 记录奇数数的个数else如果结点 i 不是奇数even+;累加变量 even 记录偶数数的个数aver+=xxi;将 xxi累加存入 aver 中aver/=MAX;计算平均数for(i=0;iMAX;i+)totfc 十=(xxi=aver)*(xxi=aver);totfc/=MAX;void main()int i;for(i=0;iMAX;i+)xxi=0;if(ReadDat()printf(“数据文件 IN.DAT 不能打开!/007/n“);return;Comput

4、e();printf(“ODD=%d/nOVEN=%d/nAVER=%f/nTOTFC=%f/n“,odd,even,aver,totfc);WriteDat();void WriteDat(void)FILE*fp;fp=fopen(“OUT.DAT“,“w“);fprintf(fp,“%d/n%d/n%f/n%f/n“,odd,even,aver,totfc);fclose(fp);(分数:100.00)_三级网络技术机试-239 答案解析(总分:100.00,做题时间:90 分钟)一、上机题(总题数:1,分数:100.00)1.请编制函数 ReadDat()实现从文件 IN.DAT 中读

5、取 1000 个十进制整数到数组 XX 中;请编制函数Compute(),分别计算出 XX 中奇数的个数 odd,偶数的个数 even,平均值 aver 以及方差 totfc 的值,最后调用函数 WriteDat()把结果输出到 OUT.DAT 文件中。计算方差的公式如下:* 原始数据文件存放的格式是:每行存放 10 个数,并用逗号隔开(每个数均大于 0 且小于等于 2000)。注意:部分源程序已给出如下。请勿改动主函数 main()和输出数据函数 WriteDat()的内容。试题程序:#includestdio.h#includestdlib.h#includestring.h#define

6、 MAX 1000int xxMAX,odd=0,even=0;double aver=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()*/*/fclose(fp);return 0;void Compute(void)int i;for(i=0;iMAX;i+)if(xxi%2)测试结点 i 是否是奇数odd+;累加变量 odd 记录奇数数的个数else如果结点 i 不是奇数even+;累加变量 eve

7、n 记录偶数数的个数aver+=xxi;将 xxi累加存入 aver 中aver/=MAX;计算平均数for(i=0;iMAX;i+)totfc 十=(xxi=aver)*(xxi=aver);totfc/=MAX;void main()int i;for(i=0;iMAX;i+)xxi=0;if(ReadDat()printf(“数据文件 IN.DAT 不能打开!/007/n“);return;Compute();printf(“ODD=%d/nOVEN=%d/nAVER=%f/nTOTFC=%f/n“,odd,even,aver,totfc);WriteDat();void WriteDa

8、t(void)FILE*fp;fp=fopen(“OUT.DAT“,“w“);fprintf(fp,“%d/n%d/n%f/n%f/n“,odd,even,aver,totfc);fclose(fp);(分数:100.00)_正确答案:(int i;for(i=0;iMAX;i+)if(xxi%2)测试结点 i 是否是奇数odd+;累加变量 odd 记录奇数数的个数else如果结点 i 不是奇数even+;累加变量 even 记录偶数数的个数aver+=xxi;将 xxi累加存入 aver 中aver/=MAX;计算平均数for(i=0;iMAX;i+)totfc+=(xxi=aver)*(x

9、xi-aver);totfc/=MAX;)解析:本题考查文件的操作、奇偶判断和数学公式的计算。函数 ReadDat 的作用是将从文件中读取的数据存入数组 XX 中,因为数据存放入文件的格式是每个数据被逗号隔开,所以 fscanf(fp,“%d,“,xxi)语句中字符串“%d,“中要加入逗号。函数 Compute 的作用是计算方差,思路是首先顺序读取数组 XX 中的结点,若是奇数(xxi%2,xxi为奇数余数为 1 条件表达式为真)累加存入 avel,个数存入 odd,若不是奇数(即为偶数)累加结果存入 ave2,个数存入 even。然后计算奇数和偶数的平均数,利用循环结构依次读取数组 XX,计算方差 totfc。

展开阅读全文
相关资源
猜你喜欢
  • NF C48-331-2-5-2008 Alarm systems - Intrusion and hold-up systems - Part 2-5  requirements for combined passive infrared and ultrasonic detectors 《报警系统 侵入和拦截系统 第2-5部分 组合的无源红外和超声探测器.pdf NF C48-331-2-5-2008 Alarm systems - Intrusion and hold-up systems - Part 2-5 requirements for combined passive infrared and ultrasonic detectors 《报警系统 侵入和拦截系统 第2-5部分 组合的无源红外和超声探测器.pdf
  • NF C48-331-2-6-2008 Alarm systems - Intrusion and hold-up systems - Part 2-6  opening contacts (magnetic) 《报警系统 侵入好惹拦截系统 第2-6部分 开放式(磁性)触点》.pdf NF C48-331-2-6-2008 Alarm systems - Intrusion and hold-up systems - Part 2-6 opening contacts (magnetic) 《报警系统 侵入好惹拦截系统 第2-6部分 开放式(磁性)触点》.pdf
  • NF C48-331-5-3-2005 Alarm systems - Intrusion systems - Part 5-3  requirements for interconnections equipment using radio frequency techniques 《警报系统 干扰系统 第5-3部分 使用射频技术的互联设备要求》.pdf NF C48-331-5-3-2005 Alarm systems - Intrusion systems - Part 5-3 requirements for interconnections equipment using radio frequency techniques 《警报系统 干扰系统 第5-3部分 使用射频技术的互联设备要求》.pdf
  • NF C48-331-6-2008 Alarm systems - Intrusion and hold-up systems - Part 6  power supplies 《警报系统 侵入和拦截系统 第6部分 电源 》.pdf NF C48-331-6-2008 Alarm systems - Intrusion and hold-up systems - Part 6 power supplies 《警报系统 侵入和拦截系统 第6部分 电源 》.pdf
  • NF C48-333-1-1997 Alarm systems Access control systems for use in security applications Part 1  system requirements 《报警系统 安全操作用接触控制系统 第1部分 系统要求》.pdf NF C48-333-1-1997 Alarm systems Access control systems for use in security applications Part 1 system requirements 《报警系统 安全操作用接触控制系统 第1部分 系统要求》.pdf
  • NF C48-345-2005 Alarm systems - Social alarm systems - Part 5  interconnections and communications 《警报系统 社会警报系统 第5部分 互连和通信》.pdf NF C48-345-2005 Alarm systems - Social alarm systems - Part 5 interconnections and communications 《警报系统 社会警报系统 第5部分 互连和通信》.pdf
  • NF C48-361-5-2008 Alarm systems - Alarm transmission systems and equipment - Part 1-5  requirements for Packet Switched Network PSN 《报警系统 报警传输系统和设备 第1-5部分 包交换网络PSN用要求 n》.pdf NF C48-361-5-2008 Alarm systems - Alarm transmission systems and equipment - Part 1-5 requirements for Packet Switched Network PSN 《报警系统 报警传输系统和设备 第1-5部分 包交换网络PSN用要求 n》.pdf
  • NF C48-386-2008 Equipment for use in audio and video door-entry systems 《音频和视频的进门系统用设备》.pdf NF C48-386-2008 Equipment for use in audio and video door-entry systems 《音频和视频的进门系统用设备》.pdf
  • NF C48-438-2002 Alarm systems - Intrusion detection - Events controller-recorder function integrated in central alarm units or telephone alarm transmitters 《报警系统 侵入检测 与中央报警装置或电话报警传.pdf NF C48-438-2002 Alarm systems - Intrusion detection - Events controller-recorder function integrated in central alarm units or telephone alarm transmitters 《报警系统 侵入检测 与中央报警装置或电话报警传.pdf
  • 相关搜索

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

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