【计算机类职业资格】三级数据库技术-504及答案解析.doc

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

1、三级数据库技术-504 及答案解析(总分:100.00,做题时间:90 分钟)一、设计与应用题(总题数:1,分数:100.00)1.函数 ReadDat()实现从文件 in.dat中读取 1000个十进制整数到数组 xx中,请编制函数 Compute()分别计算出 xx中数值为偶数的个数 even,所有数值为奇数的平均值 ave1,偶数的平均值 ave2以及所有偶数的方差 totfc的值,最后调用函数 WriteDat()把结果输出到 out.dat文件中。 计算方差的公式如下: (分数:100.00)_三级数据库技术-504 答案解析(总分:100.00,做题时间:90 分钟)一、设计与应用

2、题(总题数:1,分数:100.00)1.函数 ReadDat()实现从文件 in.dat中读取 1000个十进制整数到数组 xx中,请编制函数 Compute()分别计算出 xx中数值为偶数的个数 even,所有数值为奇数的平均值 ave1,偶数的平均值 ave2以及所有偶数的方差 totfc的值,最后调用函数 WriteDat()把结果输出到 out.dat文件中。 计算方差的公式如下: (分数:100.00)_正确答案:()解析:int i, odd=0; /*循环变量 i从 0开始,每次增 1,直到其值小于 MAX,对数组 xx中的每个元素的奇偶性进行判断,如果是奇数,变量 odd加 1

3、同时把这个元素累加到变量 ave1,否则,变量 even加 1,同时把这个元素累加到变量 are2*/ for(i=0; iMAX; i+) if(xxi%2)/如果 xxi是奇数 odd+; /变量 odd加 1 avel+=xxi; /把 xxi累加到变量 ave1 else even+; /变量 even加 1 ave2+=xxi; /把 xxi累加到变量 ave2 ave1/=1.0*odd; /奇数的和 ave1除以奇数的个数 odd,得到所有奇数的平均值赋给 ave1 ave2/=1.0*even; /偶数的和 ave2除以偶数的个数 even,得到所有偶数的平均值赋给 are2

4、 /*根据方差的计算公式计算所有偶数的方差*/ for(i=0;iMAX;i+) if(xxi%2=0) /如果 xxi是偶数 totfc+=(xxi-ave2)*(xxi-are2); /把(xxi-are2)的平方累加到变量 totfc totfc/=1.0*even; /变量 totfc除以偶数的个数 even,得到所有偶数的方差 解析 读取 1000个数,奇数个数及平均值,偶数个数、平均值及方差。 定义循环变量 i、表示奇数个数的变量 odd并设置其值为 0。 采用 for循环语句,对数组 xx中每个数组元素 xxi对 2求余数,如果余数为 1,则说明数组元素xxi的值为奇数,则变量

5、odd的值加 1,并把数组元素 xxi的值累加到变量 ave1,否则,说明数组元数 xxi的值为偶数,则变量 even的值加 1,并把数组元素 xxi的值累加到变量 ave2。 退出 for循环语句后,用变量 ave1除以奇数的个数 odd,得到所有奇数的平均值赋给 ave1,用变量ave2除以偶数的个数 even,得到所有偶数的平均值赋给 ave2。 利用 for循环语句,对数组 xx中每个数组元素 xxi对 2求余数,如果余数等于 0,则说明数组元素xxi的值为偶数,这时把表达式 xxi-ave2的平方值累加到变量 totfc。退出循环后,用变量 totfc的值除以偶数的个数 even,得到所有偶数的方差赋给变量 totfc。

展开阅读全文
相关资源
猜你喜欢
  • GOST 20098-1974 Iron pattern plates for moulding boxes having inside dimensions 1000x800 mm for moulding foundry machines with turn of half mould with squeezing Design and dimensio.pdf GOST 20098-1974 Iron pattern plates for moulding boxes having inside dimensions 1000x800 mm for moulding foundry machines with turn of half mould with squeezing Design and dimensio.pdf
  • GOST 20099-1974 Iron pattern plates with changeable metal inserts for moulding boxes having inside dimensions 1000x800 mm for moulding foundry machines with turn of half mould with.pdf GOST 20099-1974 Iron pattern plates with changeable metal inserts for moulding boxes having inside dimensions 1000x800 mm for moulding foundry machines with turn of half mould with.pdf
  • GOST 20100-1974 Iron pattern plates for moulding boxes having inside dimensions 1200x1000 mm for moulding foundry machines with turn of half mould without squeezing Dezign and dime.pdf GOST 20100-1974 Iron pattern plates for moulding boxes having inside dimensions 1200x1000 mm for moulding foundry machines with turn of half mould without squeezing Dezign and dime.pdf
  • GOST 20101-1974 Steel pattern plates for moulding boxes having inside dimensions 400x300 mm 450x350 mm 500x400 mm for moulding foundry machines without turn of half mould with sque.pdf GOST 20101-1974 Steel pattern plates for moulding boxes having inside dimensions 400x300 mm 450x350 mm 500x400 mm for moulding foundry machines without turn of half mould with sque.pdf
  • GOST 20102-1974 Steel pattern plates with changeable metal inserts for moulding boxes having inside dimensions 400x300 mm 450x350 mm 500x400 mm for moulding foundry machines withoud di.pdf GOST 20102-1974 Steel pattern plates with changeable metal inserts for moulding boxes having inside dimensions 400x300 mm 450x350 mm 500x400 mm for moulding foundry machines withoud di.pdf
  • GOST 20103-1974 Steel pattern plates for moulding boxes having inside dimensions 1000x600 mm for moulding foundry machines without turn of half mould with squeezing Design and dime.pdf GOST 20103-1974 Steel pattern plates for moulding boxes having inside dimensions 1000x600 mm for moulding foundry machines without turn of half mould with squeezing Design and dime.pdf
  • GOST 20104-1974 Steel pattern plates for moulding boxes having inside dimensions 1200x1000 mm for moulding foundry machines without turn of half mould without squeezing Design and .pdf GOST 20104-1974 Steel pattern plates for moulding boxes having inside dimensions 1200x1000 mm for moulding foundry machines without turn of half mould without squeezing Design and .pdf
  • GOST 20106-1974 Steel pattern plates with changeable metal inserts for moulding boxes having inside dimensions 600x500 mm for moulding foundry machines without turn of half mould w.pdf GOST 20106-1974 Steel pattern plates with changeable metal inserts for moulding boxes having inside dimensions 600x500 mm for moulding foundry machines without turn of half mould w.pdf
  • GOST 20108-1974 Steel pattern plates with changeable metal inserts for moulding boxes having inside dimensions 800x700 mm for moulding foundry machines without turn of half mould w.pdf GOST 20108-1974 Steel pattern plates with changeable metal inserts for moulding boxes having inside dimensions 800x700 mm for moulding foundry machines without turn of half mould w.pdf
  • 相关搜索

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

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