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

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

1、三级数据库技术机试-229 及答案解析(总分:100.00,做题时间:90 分钟)一、上机题(总题数:1,分数:100.00)1.已知数据文件 IN.dat 中存有 300 个四位数,并已调用读函数 Rdata()把这些数存入数组 a 中,请编写函数 diffVal(),其功能是:求出个位数上的数减千位数上的数减百位数上的数减十位数上的数大于 0 的个数 count,再求出所有满足此条件的四位数的平均值 Ave1,以及不满足此条件的四位数平均值 Ave2。最后调用写函数 Wdata(),把结果输出到 OUT.dat 文件中。例如,1239,9-1-2-30,则该数满足条件,计算平均值 Ave1

2、且个数 count=count+1。 8129,9-8-1-20,则该数不满足条件,计算平均值 Ave2。注意:部分源程序已经给出。程序中已定义数组 a300,已定义变量 count、Ave1、Ave2。请勿改动主函数 main()、读函数 Rdata()和写函数 Wdata()的内容。#include stdio.h#int a300, count = 0;double Ave1 = 0.0, Ave2 = 0.0;void diffVal()void Rdata()FILE *fp;int i;fp = fopen(“IN. dat“, “r“);for (i=0; i300; i+)f

3、scanf(fp, “%d,“, fclose(fp);void Wdata()FILE *fp;fp = fopen (“OUT. dat“, “w“);fprintf(fp, “%d/n%7.2f/n%7.2f/n“, count, Ave1, Ave2);fclose(fp);main()Rdata();diffVal();Wdata();printf (“count=%d/n 满足条件的平均值 pzj 1=%7.2f/n 不满足条件的平均值 pzj2=%7.2f/n“, count, Ave1, Ave2);(分数:100.00)_三级数据库技术机试-229 答案解析(总分:100.0

4、0,做题时间:90 分钟)一、上机题(总题数:1,分数:100.00)1.已知数据文件 IN.dat 中存有 300 个四位数,并已调用读函数 Rdata()把这些数存入数组 a 中,请编写函数 diffVal(),其功能是:求出个位数上的数减千位数上的数减百位数上的数减十位数上的数大于 0 的个数 count,再求出所有满足此条件的四位数的平均值 Ave1,以及不满足此条件的四位数平均值 Ave2。最后调用写函数 Wdata(),把结果输出到 OUT.dat 文件中。例如,1239,9-1-2-30,则该数满足条件,计算平均值 Ave1,且个数 count=count+1。 8129,9-8

5、1-20,则该数不满足条件,计算平均值 Ave2。注意:部分源程序已经给出。程序中已定义数组 a300,已定义变量 count、Ave1、Ave2。请勿改动主函数 main()、读函数 Rdata()和写函数 Wdata()的内容。#include stdio.h#int a300, count = 0;double Ave1 = 0.0, Ave2 = 0.0;void diffVal()void Rdata()FILE *fp;int i;fp = fopen(“IN. dat“, “r“);for (i=0; i300; i+)fscanf(fp, “%d,“, fclose(fp);

6、void Wdata()FILE *fp;fp = fopen (“OUT. dat“, “w“);fprintf(fp, “%d/n%7.2f/n%7.2f/n“, count, Ave1, Ave2);fclose(fp);main()Rdata();diffVal();Wdata();printf (“count=%d/n 满足条件的平均值 pzj 1=%7.2f/n 不满足条件的平均值 pzj2=%7.2f/n“, count, Ave1, Ave2);(分数:100.00)_正确答案:(void diffVal() int i, thou, hun, ten, data, n = 0

7、for (i=0; i300; i+) thou = ai/1000;hun = ai%1000/100;ten = ai%100/10;data = ai%10;if (data-thou-hun-ten0) count+;Ave1 += ai;else n+;Ave2 += ai;Ave1 /= count;Ave2 /= n;)解析:解题思路 对于每一个四位数,用这个四位数除以 1000,可得到这个四位数千位上的数字输给变量 thou:这个四位数对 1000 求余然后再除以 100,可得到这个四位数百位上的数字输给变量 hun;这个四位数对 100 求余然后再除以 10,可得到这个四位数十位上的数字输给变量 ten;这个四位数对 10 求余,可得到这个四位数个位上的数字输给变量 data。然后判断表达式 data-thou-hun-ten 是否大于 0,如果大于 0,则计数变量 count 加 1,同时把这个数加到变量 Ave1 上;否则计数变量 n 加 1,同时把这个数加到变量 Ave2 上。退出循环后,变量 Ave1 的值除以 count 值就得到所有满足此条件的四位数的平均值,变量 Ave2 的值除以 n 值就得到所有不满足此条件的四位数的平均值。

展开阅读全文
相关资源
猜你喜欢
  • BS EN 61300-2-7-2013 Fibre optic interconnecting devices and passive components Basic test and measurement procedures Tests Bending moment《纤维光学互连器件和无源元件 基本试验和测量程序 试验 弯矩》.pdf BS EN 61300-2-7-2013 Fibre optic interconnecting devices and passive components Basic test and measurement procedures Tests Bending moment《纤维光学互连器件和无源元件 基本试验和测量程序 试验 弯矩》.pdf
  • BS EN 61300-2-8-1997 Fibre optic interconnecting devices and passive components Basic test and measurement procedures Tests Bump《光纤互联装置和无源部件 基本试验和测量规程 试验 连续冲击试验》.pdf BS EN 61300-2-8-1997 Fibre optic interconnecting devices and passive components Basic test and measurement procedures Tests Bump《光纤互联装置和无源部件 基本试验和测量规程 试验 连续冲击试验》.pdf
  • BS EN 61300-2-9-2017 Fibre optic interconnecting devices and passive components Basic test and measurement procedures Tests Shock《光纤互联装置和无源部件 基本试验和测试规程 试验 冲击》.pdf BS EN 61300-2-9-2017 Fibre optic interconnecting devices and passive components Basic test and measurement procedures Tests Shock《光纤互联装置和无源部件 基本试验和测试规程 试验 冲击》.pdf
  • BS EN 61300-3-1-2005 Fire optic interconnecting devices and passive components - Basic test and measurement procedures - Part 3-1 Examinations and measurements - Visual examination.pdf BS EN 61300-3-1-2005 Fire optic interconnecting devices and passive components - Basic test and measurement procedures - Part 3-1 Examinations and measurements - Visual examination.pdf
  • BS EN 61300-3-10-2007 Fibre optic interconnecting devices and passive components - Basic test and measurement procedures - Examinations and measurements - Gauge retention force《光纤互.pdf BS EN 61300-3-10-2007 Fibre optic interconnecting devices and passive components - Basic test and measurement procedures - Examinations and measurements - Gauge retention force《光纤互.pdf
  • BS EN 61300-3-11-1997 Fibre optic interconnecting devices and passive components - Basic test and measurement procedures - Examinations and measurements - Engagement and separation.pdf BS EN 61300-3-11-1997 Fibre optic interconnecting devices and passive components - Basic test and measurement procedures - Examinations and measurements - Engagement and separation.pdf
  • BS EN 61300-3-13-1997 Fibre optic interconnecting devices and passive components - Basic test and measurement procedures - Examinations and measurements - Control stability of a fi.pdf BS EN 61300-3-13-1997 Fibre optic interconnecting devices and passive components - Basic test and measurement procedures - Examinations and measurements - Control stability of a fi.pdf
  • BS EN 61300-3-14-2014 Fibre optic interconnecting devices and passive components Basic test and measurement procedures Examinations and measurements Error and repeatability of the u.pdf BS EN 61300-3-14-2014 Fibre optic interconnecting devices and passive components Basic test and measurement procedures Examinations and measurements Error and repeatability of the u.pdf
  • BS EN 61300-3-18-2006 Fibre optic interconnecting devices and passive components - Basic test and measurement procedures - Examinations and measurements - Keying accuracy of an ang.pdf BS EN 61300-3-18-2006 Fibre optic interconnecting devices and passive components - Basic test and measurement procedures - Examinations and measurements - Keying accuracy of an ang.pdf
  • 相关搜索

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

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