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

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

1、三级数据库技术-526 及答案解析(总分:100.00,做题时间:90 分钟)一、设计与应用题(总题数:1,分数:100.00)1.已知数据文件 IN1.DAT 和 IN2.DAT 中分别存有 100 个两位十进制数,并且己调用读函数 readDat()把这两个文件中的数存入数组 a 和 b 中,请考生编制一个函数 jsVal(),实现的功能是依次对数组 a 和 b 中的数按条件重新组成一个新数并依次存入数组 c 中,再对数组 c 中的数按从小到大的顺序进行排序,最后调用输出函数 writeDat()把结果 c 输出到文件 out.dat 中。 组成新数的条件:如果数组 a 和 b 中相同下标

2、位置的数均是奇数,则数组 a 中十位数字为新数的千位数字,个位数字仍为新数的个位数字,数组 b 中的十位数字为新数的百位数字,个位数字为新数的十位数字,这样组成的新数并存入数组 c 中。 例如:a:12 31 24 15 21 15 b:32 45 17 27 18 15 c:3451 1275 1155 排序后 c:1155 1275 3451 程序中已定义:a100、b100和 c100。 请勿改动数据文件 IN1.DAT 和 IN2.DAT 中的任何数据、主函数 main()、读函数 readDat()和写函数writeDat()的内容。 #include stdio.h #define

3、 MAX 100 int aMAX, bMAX, cMAX; int cnt=0; /*存放符合条件数的个数*/ void jsVal() /*把数据文件 IN1.DAT 和 IN2.DAT 中的 100 个两位十进制数存入数组 a 和 b 中*/ void readDat() int i; FILE *fp; fp=fopen(“in1.dat“, “r“); for(i=0; iMAX; i+) fscanf(fp, “%d“, fclose (fp); fp=fopen(“in2.dat“, “r“); for(i=0; iMAX; i+) fscanf(fp, “%d“, fclose

4、fp); void main() int i; void writeDat(); for(i=0; iMAX; i+) ci=0; readDat (); jsVal (); for(i=0; iMAX i+) printf(“%dn“, ci); writeDat (); /*把结果数组 c 输出到文件 out.dat 中*/ void writeDat() FILE *fp; int i; fp=fopen(“out.dat“, “w“); for(i=0; iMAX i+) fprintf(fp, “%dn“, ci); fclose (fp); (分数:100.00)_三级数据库技术

5、526 答案解析(总分:100.00,做题时间:90 分钟)一、设计与应用题(总题数:1,分数:100.00)1.已知数据文件 IN1.DAT 和 IN2.DAT 中分别存有 100 个两位十进制数,并且己调用读函数 readDat()把这两个文件中的数存入数组 a 和 b 中,请考生编制一个函数 jsVal(),实现的功能是依次对数组 a 和 b 中的数按条件重新组成一个新数并依次存入数组 c 中,再对数组 c 中的数按从小到大的顺序进行排序,最后调用输出函数 writeDat()把结果 c 输出到文件 out.dat 中。 组成新数的条件:如果数组 a 和 b 中相同下标位置的数均是奇数

6、则数组 a 中十位数字为新数的千位数字,个位数字仍为新数的个位数字,数组 b 中的十位数字为新数的百位数字,个位数字为新数的十位数字,这样组成的新数并存入数组 c 中。 例如:a:12 31 24 15 21 15 b:32 45 17 27 18 15 c:3451 1275 1155 排序后 c:1155 1275 3451 程序中已定义:a100、b100和 c100。 请勿改动数据文件 IN1.DAT 和 IN2.DAT 中的任何数据、主函数 main()、读函数 readDat()和写函数writeDat()的内容。 #include stdio.h #define MAX 100

7、 int aMAX, bMAX, cMAX; int cnt=0; /*存放符合条件数的个数*/ void jsVal() /*把数据文件 IN1.DAT 和 IN2.DAT 中的 100 个两位十进制数存入数组 a 和 b 中*/ void readDat() int i; FILE *fp; fp=fopen(“in1.dat“, “r“); for(i=0; iMAX; i+) fscanf(fp, “%d“, fclose (fp); fp=fopen(“in2.dat“, “r“); for(i=0; iMAX; i+) fscanf(fp, “%d“, fclose(fp); vo

8、id main() int i; void writeDat(); for(i=0; iMAX; i+) ci=0; readDat (); jsVal (); for(i=0; iMAX i+) printf(“%dn“, ci); writeDat (); /*把结果数组 c 输出到文件 out.dat 中*/ void writeDat() FILE *fp; int i; fp=fopen(“out.dat“, “w“); for(i=0; iMAX i+) fprintf(fp, “%dn“, ci); fclose (fp); (分数:100.00)_正确答案:()解析:int i

9、j,tmp; /*对数组 a 和 b 中每个元素逐个进行扫描,如果 ai和 bi)同时为奇数,由 ai的十位数字为新数的千位数字,个位数字为新数的个位数字,bi的十位数字为新数的百位数字,个位数字为新数的十位数字,把这个新组成的数存入数组元素 ccn,同时数组下标变量 cn 加 1*/ for(i=0; iMAX;i+) if(ai%2) /*对数组 c 中的元素按从小到大的顺序进行排序*/ for(i=0;icnt;i+) for(j=i+1; jcnt; j+) if(cicj) /如果数组元素 ci大于 cj,则两者进行互换 tmp=ci; ci=cj; cj=tmp; 解析 数组相同

10、下标位置上的奇数,数组 a 中十位数等于新数的千位数字,个位等于新数个位数字,数组 b 中的十位等于新数的百位数字,个位数字等于新数的十位数字,存入数组,从小到大排序。 定义整型循环变量 i、j 和局部变量 tmp。 在 for 循环语句中,循环变量 i 从 0 开始,依次递增直到其值等于或大于 MAX,用 if 条件语句判断如果 ai和 bi同时为奇数,由 ai的十位数字为新数的千位数字,个位数字为新数的个位数字,bi的十位数字为新数的百位数字,个位数字为新数的十位数字,把这个新组成的数存入数组元素 ccn,同时数组下标变量 cn 加 1。 在第一层 for 循环语句中,循环变量 i 从 0 开始,依次递增直到其值等于或大于 cnt,在第二层循环中,循环变量 j 从 i+1 开始,依次递增直到其值等于 cnt,用 if 条件语句判断如果数组元素 ci大于 cj,则两者进行互换,实现数组 c 中的数按从小到大的顺序进行排序。

展开阅读全文
相关资源
猜你喜欢
  • TIS 2466 2-2009 Steel tubes and fittings symbols for use in specifications part 2 square and rectangular hollow sections《钢管和管件 规范中使用的符号 第2部分 正方形和矩形中空截面》.pdf TIS 2466 2-2009 Steel tubes and fittings symbols for use in specifications part 2 square and rectangular hollow sections《钢管和管件 规范中使用的符号 第2部分 正方形和矩形中空截面》.pdf
  • TIS 2467-2009 Plain end steel tubes welded and seamless general tables of dimensions and masses per unit length《焊接和无缝平口钢管 一般尺寸表和单位长度质量表》.pdf TIS 2467-2009 Plain end steel tubes welded and seamless general tables of dimensions and masses per unit length《焊接和无缝平口钢管 一般尺寸表和单位长度质量表》.pdf
  • TIS 247-2009 Polyester sewing thread《聚酯缝纫线》.pdf TIS 247-2009 Polyester sewing thread《聚酯缝纫线》.pdf
  • TIS 2470-2009 Seamless steel tubes for pressure purposes full peripheral ultrasonic testing for the detection of transverse imperfections《承压用无缝钢管 横向缺陷的全圆周超声波检测》.pdf TIS 2470-2009 Seamless steel tubes for pressure purposes full peripheral ultrasonic testing for the detection of transverse imperfections《承压用无缝钢管 横向缺陷的全圆周超声波检测》.pdf
  • TIS 2471-2009 Seamless and welded (except submerged arc-welded) steel tubes for pressure purposes electromagnetic testing for verification of hydraulic leak tightness《承压无缝和焊接(埋弧焊除外.pdf TIS 2471-2009 Seamless and welded (except submerged arc-welded) steel tubes for pressure purposes electromagnetic testing for verification of hydraulic leak tightness《承压无缝和焊接(埋弧焊除外.pdf
  • TIS 2472-2009 Seamless and welded (except submerged arc-welded) steel tubes for pressure purposes full peripheral ultrasonic testing for the detection of longitudinal imperfections.pdf TIS 2472-2009 Seamless and welded (except submerged arc-welded) steel tubes for pressure purposes full peripheral ultrasonic testing for the detection of longitudinal imperfections.pdf
  • TIS 2473-2009 Seamless and welded (except submerged arc welded) steel tubes for pressure purposes eddy current testing for the detection of imperfections《承压无缝和焊接(埋弧焊除外)钢管 探测缺欠的涡流检测.pdf TIS 2473-2009 Seamless and welded (except submerged arc welded) steel tubes for pressure purposes eddy current testing for the detection of imperfections《承压无缝和焊接(埋弧焊除外)钢管 探测缺欠的涡流检测.pdf
  • TIS 2475-2009 Seamless and welded steel tubes for pressure purposes ultrasonic testing of tube ends for detection of laminar imperfections《承压无缝和焊接(埋弧焊除外)钢管 层间不完整性检查的管端超声波检测》.pdf TIS 2475-2009 Seamless and welded steel tubes for pressure purposes ultrasonic testing of tube ends for detection of laminar imperfections《承压无缝和焊接(埋弧焊除外)钢管 层间不完整性检查的管端超声波检测》.pdf
  • TIS 2476-2009 Household rubber gloves《家用橡胶手套》.pdf TIS 2476-2009 Household rubber gloves《家用橡胶手套》.pdf
  • 相关搜索

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

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