[计算机类试卷]国家三级(数据库技术)机试模拟试卷123及答案与解析.doc

上传人:jobexamine331 文档编号:495267 上传时间:2018-11-28 格式:DOC 页数:3 大小:27.50KB
下载 相关 举报
[计算机类试卷]国家三级(数据库技术)机试模拟试卷123及答案与解析.doc_第1页
第1页 / 共3页
[计算机类试卷]国家三级(数据库技术)机试模拟试卷123及答案与解析.doc_第2页
第2页 / 共3页
[计算机类试卷]国家三级(数据库技术)机试模拟试卷123及答案与解析.doc_第3页
第3页 / 共3页
亲,该文档总共3页,全部预览完了,如果喜欢就下载吧!
资源描述

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

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

3、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; i 100; i+) fgets(str, 80, fp); memcpy(selli.code, str, 4); memcpy(selli.name, str+4, 1

4、0); 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; i 100; i+) printf(“%s %s %4d %5d %5dn“, selli. code

5、 selli.name, selli.uprice, selli. amount, selli. sum); fprintf(fp, “%s %s %4d %5d %5dn“, selli. code, selli. name, selli. uprice, selli. amount, selli. sum); fclose(fp); 国家三级(数据库技术)机试模拟试卷 123答案与解析 一、程序设计题 1 【正确答案】 void SortDat() int i, j; PRO xy; for (i=0; i 99; i+) for (j=i+1; j 100; j+) if (selli

6、 .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()比较两个产品的产品代码,如果前一个产品的代码大于后一个产品的代码,则这两个产品进行数据交换。 【知识模块】 三级数据库技术机试模拟

展开阅读全文
相关资源
猜你喜欢
  • ASTM B827-2005(2014) Standard Practice for Conducting Mixed Flowing Gas &40 MFG&41 Environmental Tests《传导混流气 (MFG) 的环境试验的标准实施规程》.pdf ASTM B827-2005(2014) Standard Practice for Conducting Mixed Flowing Gas &40 MFG&41 Environmental Tests《传导混流气 (MFG) 的环境试验的标准实施规程》.pdf
  • ASTM B828-2002 Standard Practice for Making Capillary Joints by Soldering of Copper and Copper Alloy Tube and Fittings《用铜、铜合金管和配件钎焊制作毛细管接缝的标准实施规程》.pdf ASTM B828-2002 Standard Practice for Making Capillary Joints by Soldering of Copper and Copper Alloy Tube and Fittings《用铜、铜合金管和配件钎焊制作毛细管接缝的标准实施规程》.pdf
  • ASTM B828-2002(2010) Standard Practice for Making Capillary Joints by Soldering of Copper and Copper Alloy Tube and Fittings《铜 铜合金管和配件钎焊制作毛细管接缝的标准实施规程》.pdf ASTM B828-2002(2010) Standard Practice for Making Capillary Joints by Soldering of Copper and Copper Alloy Tube and Fittings《铜 铜合金管和配件钎焊制作毛细管接缝的标准实施规程》.pdf
  • ASTM B828-2016 Standard Practice for Making Capillary Joints by Soldering of Copper and Copper Alloy Tube and Fittings《通过铜和铜合金管和配件的焊接来制备毛细管接头的标准实施规程》.pdf ASTM B828-2016 Standard Practice for Making Capillary Joints by Soldering of Copper and Copper Alloy Tube and Fittings《通过铜和铜合金管和配件的焊接来制备毛细管接头的标准实施规程》.pdf
  • ASTM B829-2004a Standard Specification for General Requirements for Nickel and Nickel Alloys Seamless Pipe and Tube《镍和镍合金无缝管一般要求的标准规范》.pdf ASTM B829-2004a Standard Specification for General Requirements for Nickel and Nickel Alloys Seamless Pipe and Tube《镍和镍合金无缝管一般要求的标准规范》.pdf
  • ASTM B829-2004a(2009) Standard Specification for General Requirements for Nickel and Nickel Alloys Seamless Pipe and Tube《镍和镍合金无缝管一般要求的标准规范》.pdf ASTM B829-2004a(2009) Standard Specification for General Requirements for Nickel and Nickel Alloys Seamless Pipe and Tube《镍和镍合金无缝管一般要求的标准规范》.pdf
  • ASTM B829-2004A(2009)e1 Standard Specification for General Requirements for Nickel and Nickel Alloys Seamless Pipe and Tube《镍和镍合金无缝管通用要求的标准规格》.pdf ASTM B829-2004A(2009)e1 Standard Specification for General Requirements for Nickel and Nickel Alloys Seamless Pipe and Tube《镍和镍合金无缝管通用要求的标准规格》.pdf
  • ASTM B829-2004a(2017) Standard Specification for General Requirements for Nickel and Nickel Alloys Seamless Pipe and Tube《镍和镍合金无缝管和管件通用要求的标准规格》.pdf ASTM B829-2004a(2017) Standard Specification for General Requirements for Nickel and Nickel Alloys Seamless Pipe and Tube《镍和镍合金无缝管和管件通用要求的标准规格》.pdf
  • ASTM B830-1997(2003) Standard Specification for Uniform Test Methods and Frequency《均匀试验方法和频率标准规范》.pdf ASTM B830-1997(2003) Standard Specification for Uniform Test Methods and Frequency《均匀试验方法和频率标准规范》.pdf
  • 相关搜索

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

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