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

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

1、计算机三级数据库技术-92 及答案解析(总分:100.00,做题时间:90 分钟)1.已知在文件 IN.DAT 中存有若干个(个数200)4 位正整数,函数 ReadDat()的功能是读取这些正整数并存入数组 xx 中。请编写函数 CalValue(),其功能是:(1)求出该文件中正整数的个数 totNum。(2)求这些数右移 1 位后,产生的新数中偶数的个数 totCnt,以及满足此条件的这些数(右移前的值)的算术平均值totPjz,最后调用函数 WriteDat(),把结果输出到文件 OUT.DAT 中。 请勿改动主函数 main()、读函数 ReadDat()和写函数 WriteDat(

2、)的内容。 试题程序 #includestdio.h #includestdlib.h #define MAXNUM 200 int xxMAXNUM; int totNum=0; /文件 IN.DAT 正整数的个数*/ int totCnt=0; /符合条件的正整数的个数 double totPjz=0.0; /平均值 int ReadDat(void); void WriteDat(void); void CalValue(void) void main() int i; system(“CLS“); for(i=0; iMAXNUM; i+) xxi=0; if(ReadDat() pr

3、intf(“数据文件 IN.DAT 无法打开!007n“); return; CalValue(); printf(“文件 IN.DAT 中正整数的个数=%d 个n“, totNum); printf(“符合条件的正整数的个数=%d 个n“, totCnt); printf(“平均值=%.21fn“, totPjz); WriteDat(); int ReadDat(void) FILE*fp; int i=0; if(fp=fopen(“IN.DAT“, “r“)=NULL) return 1; while(!feof(fp) fscanf(fP, “%d,“, fclose(fp); re

4、turn 0; void WriteDat(void) FILE*fp; fp=fopen(“OUT.DAT“, “w“); fprintf(fp, “%dn%dn%.21fn“, totNum, totCnt, totPjz); fclose(fp); (分数:100.00)_计算机三级数据库技术-92 答案解析(总分:100.00,做题时间:90 分钟)1.已知在文件 IN.DAT 中存有若干个(个数200)4 位正整数,函数 ReadDat()的功能是读取这些正整数并存入数组 xx 中。请编写函数 CalValue(),其功能是:(1)求出该文件中正整数的个数 totNum。(2)求这些

5、数右移 1 位后,产生的新数中偶数的个数 totCnt,以及满足此条件的这些数(右移前的值)的算术平均值totPjz,最后调用函数 WriteDat(),把结果输出到文件 OUT.DAT 中。 请勿改动主函数 main()、读函数 ReadDat()和写函数 WriteDat()的内容。 试题程序 #includestdio.h #includestdlib.h #define MAXNUM 200 int xxMAXNUM; int totNum=0; /文件 IN.DAT 正整数的个数*/ int totCnt=0; /符合条件的正整数的个数 double totPjz=0.0; /平均值

6、 int ReadDat(void); void WriteDat(void); void CalValue(void) void main() int i; system(“CLS“); for(i=0; iMAXNUM; i+) xxi=0; if(ReadDat() printf(“数据文件 IN.DAT 无法打开!007n“); return; CalValue(); printf(“文件 IN.DAT 中正整数的个数=%d 个n“, totNum); printf(“符合条件的正整数的个数=%d 个n“, totCnt); printf(“平均值=%.21fn“, totPjz);

7、WriteDat(); int ReadDat(void) FILE*fp; int i=0; if(fp=fopen(“IN.DAT“, “r“)=NULL) return 1; while(!feof(fp) fscanf(fP, “%d,“, fclose(fp); return 0; void WriteDat(void) FILE*fp; fp=fopen(“OUT.DAT“, “w“); fprintf(fp, “%dn%dn%.21fn“, totNum, totCnt, totPjz); fclose(fp); (分数:100.00)_正确答案:()解析:void CalVal

8、ue(void) int i; /*定义循环控制变量*/ int data; /*用于保存处理后产生的新数*/ for(i=0; i200; i+) /*逐个取数组 xx 中的数进行统计*/ if(xxi0) /*判断是否正整数*/ totNum+; /*统计正整数的个数*/ data=xxi1; /*将数右移一位*/ if(data%2=0) /*如果产生的新数是偶数*/ totCnt+; /*统计这些数的个数*/ totPjz+=xxi; /*并将满足条件的原数求和*/ totPjz/=totCnt; /*求满足条件的这些数(右移前的值)的算术平均值*/ 考点 本题考查对多个整数的右移、统计以及求平均值。考查的知识点主要包括:位移算法,逻辑表达式,求平均值的算法。 本题是数学类题。本题的解题思路是:首先利用一个 for 循环来依次从数组中取得各数,由于题目要求数组中正整数的个数,如果取得的数大于零,这时就给变量 totNum(正整数的个数)累加 1,然后把该正整数右移一位后的结果临时保存在变量 data 中,再判断产生的新数是否是偶数。如果是,就给变量totCnt(符合判断条件的正整数个数)累加 1,并把原数的值累加到变量 totPjz 中,当所有符合判断条件的数都被找出后,再对 totPjz 求平均值。

展开阅读全文
相关资源
猜你喜欢
  • BS EN 62744-2015 Representation of states of objects by graphical symbols《图形符号对象的状态表示》.pdf BS EN 62744-2015 Representation of states of objects by graphical symbols《图形符号对象的状态表示》.pdf
  • BS EN 62747-2014 Terminology for voltage-sourced converters (VSC) for high-voltage direct current (HVDC) systems《高压直流 (HVDC) 系统用电压源换流器 (VSC) 术语》.pdf BS EN 62747-2014 Terminology for voltage-sourced converters (VSC) for high-voltage direct current (HVDC) systems《高压直流 (HVDC) 系统用电压源换流器 (VSC) 术语》.pdf
  • BS EN 62751-1-2014 Power losses in voltage sourced converter (VSC) valves for high-voltage direct current (HVDC) systems General requirements《高压直流 (HVDC) 系统用电压源换流器 (VSC) 阀门损耗的测定 通用.pdf BS EN 62751-1-2014 Power losses in voltage sourced converter (VSC) valves for high-voltage direct current (HVDC) systems General requirements《高压直流 (HVDC) 系统用电压源换流器 (VSC) 阀门损耗的测定 通用.pdf
  • BS EN 62751-2-2014 Power losses in voltage sourced converter (VSC) valves for high-voltage direct current (HVDC) systems Modular multilevel converters《高压直流 (HVDC) 系统用电压源换流器 (VSC) 阀.pdf BS EN 62751-2-2014 Power losses in voltage sourced converter (VSC) valves for high-voltage direct current (HVDC) systems Modular multilevel converters《高压直流 (HVDC) 系统用电压源换流器 (VSC) 阀.pdf
  • BS EN 62752-2016 In-cable control and protection device for mode 2 charging of electric road vehicles (IC-CPD)《用于电动道路车辆2型充电的电缆控制和保护装置(IC-CPD)》.pdf BS EN 62752-2016 In-cable control and protection device for mode 2 charging of electric road vehicles (IC-CPD)《用于电动道路车辆2型充电的电缆控制和保护装置(IC-CPD)》.pdf
  • BS EN 62753-2015 Digital terrestrial television receivers for the DTMB system《DTMB系统的地面数字电视接收机》.pdf BS EN 62753-2015 Digital terrestrial television receivers for the DTMB system《DTMB系统的地面数字电视接收机》.pdf
  • BS EN 62756-1-2015 Digital load side transmission lighting control Basic requirements《数字负载端传输照明控制 基本要求》.pdf BS EN 62756-1-2015 Digital load side transmission lighting control Basic requirements《数字负载端传输照明控制 基本要求》.pdf
  • BS EN 62759-1-2015 Photovoltaic (PV) modules Transportation testing Transportation and shipping of module package units《光伏 (PV) 模块 运输试验 模块封装单元的运输和船运》.pdf BS EN 62759-1-2015 Photovoltaic (PV) modules Transportation testing Transportation and shipping of module package units《光伏 (PV) 模块 运输试验 模块封装单元的运输和船运》.pdf
  • BS EN 62760-2016 Audio reproduction method for normalized loudness level《标准化响度级的音频再现方法》.pdf BS EN 62760-2016 Audio reproduction method for normalized loudness level《标准化响度级的音频再现方法》.pdf
  • 相关搜索

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

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