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

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

1、国家三级(数据库技术)机试模拟试卷 137及答案与解析 一、程序设计题 1 已知在文件 IN34.DAT中存有 100个产品销售记录,每个产品销售记录由产品代码 dm(字符型 4位 )、产品名称 mc(字符型 10位 )、单价 dj(整型 )、数量 s1(整型 )、金额 je(长整型 )几部分组成。其中,金额 =单价 数量可计算得出。函数 ReadDat()的功能是读取这 100个销售记录并存入数组 sell中。请编制函数 SortDat(),其功能要求:按产品代码从大到小进行排列,若产品代码相同,则按金额从大到小进行排列,最终排列结果仍存 入结构数组 sell中,最后调用函数 WriteDa

2、t( )把结果输出到文件 OUT34.DAT中。 注意:部分源程序已给出。 请勿改动主函数 main()、读函数 ReadDat()和写函数 WriteDat()的内容。 试题程序: #include stdio.h #include mem.h #include string.h #include conio.h #include stdlib.h #define MAX 100 typedef struct char dm5; char mc11; int dj; int s1; long je; PRO; PRO sellMAX; void ReadDat(); void WriteDa

3、t(); void SortDat() void main () memset(sell,0,sizeof sell); ReadDat(); SortDat(); WriteDat(); void ReadDat () FILE *fp; char str80,ch11; int i; fp=fopen ( “IN34. DAT“, “r“ ); for (i=0; i 100; i+) fgets(str,80,fp); memcpy (sell i .dm, str, 4); memcpy(selli .mc,str+4,10 ; memcpy (ch, str+14,4); ch4=0

4、 sell i .dj =atoi (ch); memcpy (ch, str+18,5); ch5=0; sell i . s1=atoi (ch); sell i .je=(long)selli.dj*selli .s1; fclose (fp); void WriteDat () FILE *fp; int i ; fp=fopen ( “OUT34. DAT“, “w“ ); for (i=0; i 100; i+) fprintf(fp,“%s %s %4d %5d %101dn“, sell Ii .dm, sell i .mc, sell i .dj, selli .s1,se

5、ll i .je); fclose (fp); 国家三级(数据库技术)机试模拟试卷 137答案与解析 一、程序设计题 1 【正确答案】 void SortDat () int i,j; PRO xy; for (i=0; i 99; i+) for (j=i+1; j 100; j+) if (strcmp (sell i .dm, sell j . dm) 0 /*按产品代码从大到小进行排列 */ xy=sell i; selli=sellj; sell j =xy; else if (strcmp(selli.dm, sellj .dm)=0) /*若产品代码相同 */ if (sell

6、i. je sell j . je) /*则按金额从大到小进行排列 */ xy=sell i; sell i =sell j; sell j =xy; 【试题解析】 本题考查的知识点如下: (1)结构体及结构数组。 (2)结构数组的排序。 (3)字符型数组的比较。 本题着重考查结构体变量的访问、赋值,包括结构体本身及结构体中各个成员的访问和赋值。根据题意要求,我们首先要比较产品代码。因为产品代码为字符型,所以不能使用简单的比较运算符进行比较。在这里,我们使用了字符串处理函数 strcmp(char*str11,char*str12,unsignedintcout)对其进行比较。对于比较结果,若是代码相同,则要按照金额进行新的比较,否则可直接存入数组。 因为己定义了结构数组,就可以使用循环进行比较排序。排序同样采用前面介绍的 “选择排序法 ”。

展开阅读全文
相关资源
猜你喜欢
  • STAS SR CEI 747-8-1993 Semiconductor devices Discrete devices Part 8 Field effect transistors《半导体装置 分离装置 第8部分:场效应晶体管 》.pdf STAS SR CEI 747-8-1993 Semiconductor devices Discrete devices Part 8 Field effect transistors《半导体装置 分离装置 第8部分:场效应晶体管 》.pdf
  • STAS SR CEI 748-2 A1-1994 DISPOZITIVE CU SEMICONDUCTOARE Circuite integrate Partea 2 Circuite integrate digitale《处置性CU半导体 集成电路 第2部分:数字集成电路》.pdf STAS SR CEI 748-2 A1-1994 DISPOZITIVE CU SEMICONDUCTOARE Circuite integrate Partea 2 Circuite integrate digitale《处置性CU半导体 集成电路 第2部分:数字集成电路》.pdf
  • STAS SR CEI 755+A1+A2-1995 General requirements for residual current operated protective devices《剩余电流动作保护装置的一般要求 》.pdf STAS SR CEI 755+A1+A2-1995 General requirements for residual current operated protective devices《剩余电流动作保护装置的一般要求 》.pdf
  • STAS SR CEI 761-2-1996 Equipment for continuously monitoring radioactivity in gaseous effluents Part 2 Specific requirements for aerosol effluent monitors.《连续监测放射性气体排放的设备 第2部分:气溶胶排.pdf STAS SR CEI 761-2-1996 Equipment for continuously monitoring radioactivity in gaseous effluents Part 2 Specific requirements for aerosol effluent monitors.《连续监测放射性气体排放的设备 第2部分:气溶胶排.pdf
  • STAS SR CEI 770-1984 Methods of evaluating the performance of transmitters for use n industrial-process control systems《用于工业过程控制系统的发射器性能评估的方法 》.pdf STAS SR CEI 770-1984 Methods of evaluating the performance of transmitters for use n industrial-process control systems《用于工业过程控制系统的发射器性能评估的方法 》.pdf
  • STAS SR CEI 770-2-1989 Transmitters for use in industrial-process control systems Part 2 Guidance for inspection and routine testing《用于工业过程控制系统的发射器 第2部分:检查和例行测试指导 》.pdf STAS SR CEI 770-2-1989 Transmitters for use in industrial-process control systems Part 2 Guidance for inspection and routine testing《用于工业过程控制系统的发射器 第2部分:检查和例行测试指导 》.pdf
  • STAS SR CEI 771-1995 Calculation of maximum overall diameter of cables and specification of minimum tensile strength of suspension strand for low-frequency cables with polyolefin i《.pdf STAS SR CEI 771-1995 Calculation of maximum overall diameter of cables and specification of minimum tensile strength of suspension strand for low-frequency cables with polyolefin i《.pdf
  • STAS SR CEI 776-1983 Expression of the properties of logic analyzers《逻辑分析仪表现 》.pdf STAS SR CEI 776-1983 Expression of the properties of logic analyzers《逻辑分析仪表现 》.pdf
  • STAS SR CEI 804+A1+A2-1995 Integrating - averaging sound level meters《积分平均声级计 》.pdf STAS SR CEI 804+A1+A2-1995 Integrating - averaging sound level meters《积分平均声级计 》.pdf
  • 相关搜索

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

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