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

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

1、计算机三级数据库技术-120 及答案解析(总分:100.00,做题时间:90 分钟)一、上机题(总题数:1,分数:100.00)1.已知数据文件 IN.DAT中存有 300个 4位数,并已调用函数 readDat()把这些数存入数组 a中,请编写函数 jsValue(),其功能是:求出这些 4位数中素数的个数 cnt,再求出这些素数的平均值 pjz1,以及非素数的平均值 pjz2,最后调用函数 writeDat(),把结果 cnt、pjz1 和 pjz2,输出到 OUT.DAT文件中。 例如,5591 是素数,则该数满足条件,计算平均值 pjz1,且个数 cnt=cnt+1。 9812是非素数

2、则该数不满足条件,计算平均值 pjz2。 注意:程序中已定义数组 a300、b300,已定义变量 cnt、pjz1 和 pjz2。请勿改动主函数 main()、读函数 readDat()和写函数 writeDat()的内容。 【试题程序】 #include stdio.h int a300, cnt=0; double pjz1=0.0,pjz2=0.0; void readDat(); void writeDat(); int isP(int m) int i; for(i =2;i m;i +) if(m%i =0) return 0; return i; void jsValue()

3、void main () readDat(); jsValue(); writeDat(); printf (“cnt=%dn 满足条件的平均值 pjz1 =%7.21fn不满足条件的平均值 pjz2 =%7.21fn“,cnt,pjz1,pjz2); void readDat() FILE * fp; int i; fp = fopen( “IN.DAT“,“r“); for(i=0;i 300;i +) fscanf(fp,“%d,“, fclose(fp); void writeDat() FILE * fp; fp = fopen(“OUT.DAT“,“w“); fprintf (fp

4、dn%7.21fn%7.21fn“, cnt ,pjz1,pjz2); fclose(fp); (分数:100.00)_计算机三级数据库技术-120 答案解析(总分:100.00,做题时间:90 分钟)一、上机题(总题数:1,分数:100.00)1.已知数据文件 IN.DAT中存有 300个 4位数,并已调用函数 readDat()把这些数存入数组 a中,请编写函数 jsValue(),其功能是:求出这些 4位数中素数的个数 cnt,再求出这些素数的平均值 pjz1,以及非素数的平均值 pjz2,最后调用函数 writeDat(),把结果 cnt、pjz1 和 pjz2,输出到 OUT.

5、DAT文件中。 例如,5591 是素数,则该数满足条件,计算平均值 pjz1,且个数 cnt=cnt+1。 9812是非素数,则该数不满足条件,计算平均值 pjz2。 注意:程序中已定义数组 a300、b300,已定义变量 cnt、pjz1 和 pjz2。请勿改动主函数 main()、读函数 readDat()和写函数 writeDat()的内容。 【试题程序】 #include stdio.h int a300, cnt=0; double pjz1=0.0,pjz2=0.0; void readDat(); void writeDat(); int isP(int m) int i; fo

6、r(i =2;i m;i +) if(m%i =0) return 0; return i; void jsValue() void main () readDat(); jsValue(); writeDat(); printf (“cnt=%dn 满足条件的平均值 pjz1 =%7.21fn不满足条件的平均值 pjz2 =%7.21fn“,cnt,pjz1,pjz2); void readDat() FILE * fp; int i; fp = fopen( “IN.DAT“,“r“); for(i=0;i 300;i +) fscanf(fp,“%d,“, fclose(fp); voi

7、d writeDat() FILE * fp; fp = fopen(“OUT.DAT“,“w“); fprintf (fp,“%dn%7.21fn%7.21fn“, cnt ,pjz1,pjz2); fclose(fp); (分数:100.00)_正确答案:()解析:void jsValue() int i,n=0; /*定义循环控制变量和计数器变量*/ for(i=0;i300;i+) /*逐个取 4位数*/ if(isP(ai) /*如果该数为素数*/ pjz1+=ai; /*将满足条件的数求和*/ cnt+; /*统计满足条件的数的个数*/ else pjz2+=ai; /*将不满足条

8、件的数求和*/ n+; /*统计不满足条件的数的个数*/ pjz1/=cnt; /*求满足条件的数的平均值*/ pjz2/=n; /*求不满足条件的数的平均值*/ 考点 本题考查对多个整数的筛选以及求平均值的。考查的知识点主要包括:函数的调用方法,逻辑表达式,平均值的计算方法。 解析 此题属于 4位数的筛选题型,并且涉及统计及平均值计算问题。解题时,需主要解决 2个问题:问题 1如何通过判断条件(本题为该 4位数为素数)对目标进行筛选,再分别统计出满足和不满足条件的数的和以及数目;问题 2分别求出两类数的平均值。 解此题的思路为:首先通过循环和 if判断结构筛选素数,本题中已经提供判断素数的函数,只需调用即可;然后分别统计满足和不满足条件的数的个数及计算和值,最后用和除以个数得出相应的平均值。 函数的调用方法。

展开阅读全文
相关资源
猜你喜欢
  • BS PD ISO TS 21569-6-2016 Horizontal methods for molecular biomarker analysis Methods of analysis for the detection of genetically modified organisms and derived products Real-timef.pdf BS PD ISO TS 21569-6-2016 Horizontal methods for molecular biomarker analysis Methods of analysis for the detection of genetically modified organisms and derived products Real-timef.pdf
  • BS PD ISO TS 21929-2-2015 Sustainability in building construction Sustainability indicators Framework for the development of indicators for civil engineering works《建筑结构的可持续性 可持续性指标.pdf BS PD ISO TS 21929-2-2015 Sustainability in building construction Sustainability indicators Framework for the development of indicators for civil engineering works《建筑结构的可持续性 可持续性指标.pdf
  • BS PD ISO TS 22002-4-2013 Prerequisite programmes on food safety Food packaging manufacturing《食品安全的前提方案 食品包装生产》.pdf BS PD ISO TS 22002-4-2013 Prerequisite programmes on food safety Food packaging manufacturing《食品安全的前提方案 食品包装生产》.pdf
  • BS PD ISO TS 28560-4-2014 Information and documentation RFID in libraries Encoding of data elements based on rules from ISO IEC 15962 in an RFID tag with partitioned memory《信息与文献 图.pdf BS PD ISO TS 28560-4-2014 Information and documentation RFID in libraries Encoding of data elements based on rules from ISO IEC 15962 in an RFID tag with partitioned memory《信息与文献 图.pdf
  • BS PD ISO TS 81346-10-2015 Industrial systems installations and equipment and industrial products Structuring principles and reference designation Power plants《工业系统 装置与设备以及工业产品 结构原.pdf BS PD ISO TS 81346-10-2015 Industrial systems installations and equipment and industrial products Structuring principles and reference designation Power plants《工业系统 装置与设备以及工业产品 结构原.pdf
  • BS PL 4-2005 Properties of unsaturated polyester resins for low pressure laminating of high strength fibre reinforced composites - Specification《高强度纤维增强复合物的低压层压用不饱和聚酯树脂的特性 规范》.pdf BS PL 4-2005 Properties of unsaturated polyester resins for low pressure laminating of high strength fibre reinforced composites - Specification《高强度纤维增强复合物的低压层压用不饱和聚酯树脂的特性 规范》.pdf
  • BS PL 5-2005 Unsaturated polyester resins for low pressure laminating of high strength fibre reinforced composites - Test methods《高强度纤维增强复合物的低压层压用不饱和聚酯树脂 试验方法》.pdf BS PL 5-2005 Unsaturated polyester resins for low pressure laminating of high strength fibre reinforced composites - Test methods《高强度纤维增强复合物的低压层压用不饱和聚酯树脂 试验方法》.pdf
  • BS PL 6-2005 Properties of unsaturated polyester resins for low pressure laminating of glass fibre reinforced composites - Specification《高强度纤维增强复合物的低压层压用不饱和聚酯树脂 试验方法》.pdf BS PL 6-2005 Properties of unsaturated polyester resins for low pressure laminating of glass fibre reinforced composites - Specification《高强度纤维增强复合物的低压层压用不饱和聚酯树脂 试验方法》.pdf
  • BS PL 7-2005 Unsaturated polyester resins for low pressure laminating of glass fibre reinforced laminates - Test methods《玻璃纤维增强叠层制品的低压层压用不饱和聚酯树脂 试验方法》.pdf BS PL 7-2005 Unsaturated polyester resins for low pressure laminating of glass fibre reinforced laminates - Test methods《玻璃纤维增强叠层制品的低压层压用不饱和聚酯树脂 试验方法》.pdf
  • 相关搜索

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

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