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

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

1、三级数据库技术机试-192 及答案解析(总分:100.00,做题时间:90 分钟)一、上机题(总题数:1,分数:100.00)1.已知在文件 IN. dat 中存有 100 个产品销售记录,每个产品销售记录由产品代码 code(字符型 4 位)、产品名称 name(字符型 10 位)、单价 uprice(整型)、数量 amount(整型)、金额 sum(长整型)5 部分组成。其中:金额=单价数量。函数 Rdata()是读取这 100 个销售记录并存入结构数组 sell 中。请编写函数SortDat(),其功能要求:按金额从小到大进行排列,若金额相等,则按产品代码从小到大进行排列,最终排列结果仍

2、存入结构数组 sell 中。最后调用函数 Wdata(),把结果输出到 OUT. dat 文件中。注意:部分源程序已经给出。请勿改动主函数 main()、读数据函数 Rdata()和输出数据函数 Wdata()的内容。#include stdio. h#include string. h#include conio. h#include stdlib. h#define MAX 100typedef structchar code5; /* 产品代码 */char name11; /* 产品名称 */int uprice; /* 单价 */int amount; /* 数量 */long su

3、m; /* 金额 */PRO;PRO sell MAX;void Rdata();void Wdata();void SortDat()void main ()memset(sell, 0, sizeof(sell)Rdata();SortDat();Wdata();void Rdata()FILE *fp;char str80, ch11;int i;fp = fopen(“IN. dat“, “r“);for (i=0; i100; i+)fgets(str, 80, fp);memcpy(selli.code, str, 4);memcpy(selli.name, str+4, 10);

4、memcpy(ch, str+14, 4);ch4 = 0;selli.uprice = atoi(ch);memcpy(ch, str+18, 5);ch5 = 0;selli. amount = atoi(ch);selli.sum = (long)selli. uprice * selli. amount;fclose(fp);void Wdata()FILE *fp;int i;fp = fopen(“OUT. dat“, “w“);for (i=0; i100; i+)printf(“%s %s %4d %5d %5d/n“, selli. code, selli.name,sell

5、i.uprice, selli. amount, selli. sum);fprintf(fp, “%s %s %4d %5d %5d/n“, selli. code,selli. name, selli. uprice, selli. amount, selli. sum);fclose(fp);(分数:100.00)_三级数据库技术机试-192 答案解析(总分:100.00,做题时间:90 分钟)一、上机题(总题数:1,分数:100.00)1.已知在文件 IN. dat 中存有 100 个产品销售记录,每个产品销售记录由产品代码 code(字符型 4 位)、产品名称 name(字符型 10

6、 位)、单价 uprice(整型)、数量 amount(整型)、金额 sum(长整型)5 部分组成。其中:金额=单价数量。函数 Rdata()是读取这 100 个销售记录并存入结构数组 sell 中。请编写函数SortDat(),其功能要求:按金额从小到大进行排列,若金额相等,则按产品代码从小到大进行排列,最终排列结果仍存入结构数组 sell 中。最后调用函数 Wdata(),把结果输出到 OUT. dat 文件中。注意:部分源程序已经给出。请勿改动主函数 main()、读数据函数 Rdata()和输出数据函数 Wdata()的内容。#include stdio. h#include stri

7、ng. h#include conio. h#include stdlib. h#define MAX 100typedef structchar code5; /* 产品代码 */char name11; /* 产品名称 */int uprice; /* 单价 */int amount; /* 数量 */long sum; /* 金额 */PRO;PRO sell MAX;void Rdata();void Wdata();void SortDat()void main ()memset(sell, 0, sizeof(sell)Rdata();SortDat();Wdata();void

8、Rdata()FILE *fp;char str80, ch11;int i;fp = fopen(“IN. dat“, “r“);for (i=0; i100; i+)fgets(str, 80, fp);memcpy(selli.code, str, 4);memcpy(selli.name, str+4, 10);memcpy(ch, str+14, 4);ch4 = 0;selli.uprice = atoi(ch);memcpy(ch, str+18, 5);ch5 = 0;selli. amount = atoi(ch);selli.sum = (long)selli. upric

9、e * selli. amount;fclose(fp);void Wdata()FILE *fp;int i;fp = fopen(“OUT. dat“, “w“);for (i=0; i100; i+)printf(“%s %s %4d %5d %5d/n“, selli. code, selli.name,selli.uprice, selli. amount, selli. sum);fprintf(fp, “%s %s %4d %5d %5d/n“, selli. code,selli. name, selli. uprice, selli. amount, selli. sum);

10、fclose(fp);(分数:100.00)_正确答案:(void SortDat() int i, j;PRO xy;for (i=0; i99; i+)for (j=i+1; j100; j+)if (selli .sum sellj .sum) xy = selli;selli = sellj;sellj = xy;else if (selli.sum = sellj.sum) if (strcmp (sell i . code, sellj. code) 0) xy = selli;selli = sellj;sellj = xy;)解析:解题思路 这里我们通过一个双重循环来实现,首先按产品的金额进行比较,如果前一个产品的金额大于后一个产品的金额,则这两个产品进行数据交换;如果两个产品的金额相等,用字符串比较函数strcmp()比较两个产品的产品代码,如果前一个产品的代码大于后一个产品的代码,则这两个产品进行数据交换。

展开阅读全文
相关资源
猜你喜欢
  • DIN EN 14609-2004 Windows - Determination of the resistance to static torsion German version EN 14609 2004《窗 抗静力扭转的测定》.pdf DIN EN 14609-2004 Windows - Determination of the resistance to static torsion German version EN 14609 2004《窗 抗静力扭转的测定》.pdf
  • DIN EN 14610-2005 Welding and allied processes - Definitions of metal welding processes Trilingual version EN 14610 2004《焊接和相关工艺 金属焊接工艺的定义》.pdf DIN EN 14610-2005 Welding and allied processes - Definitions of metal welding processes Trilingual version EN 14610 2004《焊接和相关工艺 金属焊接工艺的定义》.pdf
  • DIN EN 14614-2005 Water quality - Guidance standard for assessing the hydromorphological features of rivers German version EN 14614 2004《水质 河流的水生形态特性评定用指导标准》.pdf DIN EN 14614-2005 Water quality - Guidance standard for assessing the hydromorphological features of rivers German version EN 14614 2004《水质 河流的水生形态特性评定用指导标准》.pdf
  • DIN EN 14617-1-2013 Agglomerated stone - Test methods - Part 1 Determination of apparent density and water absorption German version EN 14617-1 2013《烧结石料 试验方法 第1部分 表观密度和吸水率测定 德文版本E.pdf DIN EN 14617-1-2013 Agglomerated stone - Test methods - Part 1 Determination of apparent density and water absorption German version EN 14617-1 2013《烧结石料 试验方法 第1部分 表观密度和吸水率测定 德文版本E.pdf
  • DIN EN 14617-10-2012 Agglomerated stone - Test methods - Part 10 Determination of chemical resistance German version EN 14617-10 2012《烧结石料 试验方法 第10部分 耐化学性测定》.pdf DIN EN 14617-10-2012 Agglomerated stone - Test methods - Part 10 Determination of chemical resistance German version EN 14617-10 2012《烧结石料 试验方法 第10部分 耐化学性测定》.pdf
  • DIN EN 14617-11-2005 Agglomerated stone - Test methods - Part 11 Determination of linear thermal expansion coefficient German version EN 14617-11 2005《烧结石料 试验方法 第11部分 线性热膨胀系数测定》.pdf DIN EN 14617-11-2005 Agglomerated stone - Test methods - Part 11 Determination of linear thermal expansion coefficient German version EN 14617-11 2005《烧结石料 试验方法 第11部分 线性热膨胀系数测定》.pdf
  • DIN EN 14617-12-2012 Agglomerated stone - Test methods - Part 12 Determination of dimensional stability German version EN 14617-12 2012《烧结石料 试验方法 第12部分 尺寸稳定性测定》.pdf DIN EN 14617-12-2012 Agglomerated stone - Test methods - Part 12 Determination of dimensional stability German version EN 14617-12 2012《烧结石料 试验方法 第12部分 尺寸稳定性测定》.pdf
  • DIN EN 14617-13-2013 Agglomerated stone - Test methods - Part 13 Determination of electrical resistivity German version EN 14617-13 2013《烧结石料 试验方法 第13部分 电阻率的测定 德文版本EN 14617-13-2013.pdf DIN EN 14617-13-2013 Agglomerated stone - Test methods - Part 13 Determination of electrical resistivity German version EN 14617-13 2013《烧结石料 试验方法 第13部分 电阻率的测定 德文版本EN 14617-13-2013.pdf
  • DIN EN 14617-15-2005 Agglomerated stone - Test methods - Part 15 Determination of compressive strength German version EN 14617-15 2005《烧结石料 试验方法 第15部分 抗压强度测定》.pdf DIN EN 14617-15-2005 Agglomerated stone - Test methods - Part 15 Determination of compressive strength German version EN 14617-15 2005《烧结石料 试验方法 第15部分 抗压强度测定》.pdf
  • 相关搜索

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

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