【计算机类职业资格】三级信息管理技术机试-288及答案解析.doc

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

1、三级信息管理技术机试-288 及答案解析(总分:100.00,做题时间:90 分钟)一、上机题(总题数:1,分数:100.00)1.已知文件 IN42.DAT 中存有 100 个产品销售记录,每个产品销售记录由产品代码 dm(字符型 4 位)、产品名称 mc(字符型 10 位)、单价 dj(整型)、数量 sl(整型)、金额 je(长整型)几部分组成。其中:金额=单价数量。函数 ReadDat()的功能是读取这 100 个销售记录并存入结构数组 sell 中。请编制函数 SortDat(),其功能要求:按产品代码从小到大进行排列,若产品代码相同,则按金额从小到大进行排列,最终排列结果仍存入结构数

2、组 sell 中,最后调用函数 WriteDat()把结果输出到文件 0UT42.DAT 中。注意:部分源程序已给出。请勿改动主函数 main()、读函数 ReadDat()和写函数 WfiteDat()的内容。试题程序#includestdio.h#includememory.h#includestring.h#includestdlib.h#define MAX 100typedef structchar dm5;/*产品代码*/char mc11;/*产品名称*/int dj;/*单价*/int S1;/*数量*/long je;/*金额*/PRO;PRO sellMAX;void Re

3、adDat();void WriteDat();void SortDat()voidmain()memset(sell,0,sizeof(sell);ReadDat();SortDat();WriteDat();void ReadDat()FILE*fp;char str80,ch11;int i;fp=fopen(“IN42.DAT“,“r“);for(i=0;i100;i+)fgets(str,80,fp);memcpy(sellidm,str,4);memcpy(sellimc,str+4,10);memcpy(ch,str+14,4);ch4=0;selli.dj=atoi(ch);m

4、emcpy(ch,str+18,5);ch5=0;selli.sl=atoi(ch);selli.je=(long)selli.dj*selli.sl;fclose(fp);void WriteDat()FILE*fp;int i;fp=fopen(“OUT42.DAT“,“W“);for(i=0;i100;i+)fprintf(fp,“%s%s%4d%5d%10ld/n“,selli.dm,selli.mc,selli.dj,sellisl,selli.je);fclose(fp);(分数:100.00)_三级信息管理技术机试-288 答案解析(总分:100.00,做题时间:90 分钟)一、

5、上机题(总题数:1,分数:100.00)1.已知文件 IN42.DAT 中存有 100 个产品销售记录,每个产品销售记录由产品代码 dm(字符型 4 位)、产品名称 mc(字符型 10 位)、单价 dj(整型)、数量 sl(整型)、金额 je(长整型)几部分组成。其中:金额=单价数量。函数 ReadDat()的功能是读取这 100 个销售记录并存入结构数组 sell 中。请编制函数 SortDat(),其功能要求:按产品代码从小到大进行排列,若产品代码相同,则按金额从小到大进行排列,最终排列结果仍存入结构数组 sell 中,最后调用函数 WriteDat()把结果输出到文件 0UT42.DAT

6、 中。注意:部分源程序已给出。请勿改动主函数 main()、读函数 ReadDat()和写函数 WfiteDat()的内容。试题程序#includestdio.h#includememory.h#includestring.h#includestdlib.h#define MAX 100typedef structchar dm5;/*产品代码*/char mc11;/*产品名称*/int dj;/*单价*/int S1;/*数量*/long je;/*金额*/PRO;PRO sellMAX;void ReadDat();void WriteDat();void SortDat()voidma

7、in()memset(sell,0,sizeof(sell);ReadDat();SortDat();WriteDat();void ReadDat()FILE*fp;char str80,ch11;int i;fp=fopen(“IN42.DAT“,“r“);for(i=0;i100;i+)fgets(str,80,fp);memcpy(sellidm,str,4);memcpy(sellimc,str+4,10);memcpy(ch,str+14,4);ch4=0;selli.dj=atoi(ch);memcpy(ch,str+18,5);ch5=0;selli.sl=atoi(ch);s

8、elli.je=(long)selli.dj*selli.sl;fclose(fp);void WriteDat()FILE*fp;int i;fp=fopen(“OUT42.DAT“,“W“);for(i=0;i100;i+)fprintf(fp,“%s%s%4d%5d%10ld/n“,selli.dm,selli.mc,selli.dj,sellisl,selli.je);fclose(fp);(分数:100.00)_正确答案:(void SortDat()int i,j: /*定义循环控制变量*/PRO temp; /*定义数据交换时的暂存变量(这里是 PRO 类型的结构体变量)*/fo

9、r(i=0;i99;i+) /*利用选择法进行排序*/for(j=i+1;j100;j+)if(strcmp(selli.dm,sellj.dm)0) /*按产品代码从小到大进行排列*/temp=selli;selli=sellj;sellj=temp;else if(strcmp(selli.dm,sellj.dm)=0)/*若产品代码相同,则按金额从小到大进行排列*/if(selli.jesellj.je)temp=selli;selli=sellj;sellj=temp;)解析:解析 本题是有关结构体数组的排序问题。这可以用选择法来实现,即用第一个元素的产品代码依次同它后面的元素的产品代码进行比较,如果发现当前元素的产品代码比后面的某个元素的产品代码对应字符的 ASC码大(这里用到了字符串比较函数strcmp(),则交换这两个元素的位置,继续和后面的其他元素进行比较。最终在第一个元素中存放的是产品代码最小的元素,以此类推,就实现了按产品代码从小到大排序的功能。在排序过程中,若产品代码相同,则要按照金额从小到大进行排列。

展开阅读全文
相关资源
猜你喜欢
  • BS ISO TR 12470-1998 Fire resistance tests Guidance on the application and extension of results《防火试验 试验结果的应用和扩展指南》.pdf BS ISO TR 12470-1998 Fire resistance tests Guidance on the application and extension of results《防火试验 试验结果的应用和扩展指南》.pdf
  • BS ISO TR 12765-1999 Measurement of fluid flow in closed conduits Methods using transit-time ultrasonic flowmeters《封闭式管道中液体流量的测量 使用转接-时间超声流量计法》.pdf BS ISO TR 12765-1999 Measurement of fluid flow in closed conduits Methods using transit-time ultrasonic flowmeters《封闭式管道中液体流量的测量 使用转接-时间超声流量计法》.pdf
  • BS ISO TR 14179-2-2001 Gears - Thermal capacity - Thermal load carrying capacity《齿轮 热容量 热承载能力》.pdf BS ISO TR 14179-2-2001 Gears - Thermal capacity - Thermal load carrying capacity《齿轮 热容量 热承载能力》.pdf
  • BS ISO TR 3666-1999 Viscosity of water《水的粘度》.pdf BS ISO TR 3666-1999 Viscosity of water《水的粘度》.pdf
  • BS ISO TR 5925-2-1998 Fire tests - Smoke control door and shutter assemblies - Commentary on test method and test data application《防火试验 烟雾防护门和防护屏组件 试验方法和试验数据的应用说明》.pdf BS ISO TR 5925-2-1998 Fire tests - Smoke control door and shutter assemblies - Commentary on test method and test data application《防火试验 烟雾防护门和防护屏组件 试验方法和试验数据的应用说明》.pdf
  • BS ISO TR 7066-1-1997 Assessment of uncertainty in calibration and use of flow measurement devices - Linear calibration relationships《流量测量设备的校验校验和校验不可信度的评定 第1部分 线性校验关系》.pdf BS ISO TR 7066-1-1997 Assessment of uncertainty in calibration and use of flow measurement devices - Linear calibration relationships《流量测量设备的校验校验和校验不可信度的评定 第1部分 线性校验关系》.pdf
  • BS ISO TR 7470-2000 Valve outlets for gas cylinders - List of provisions which are either standardized or in use《储气瓶阀门出口 已标准化或使用中的供应目录》.pdf BS ISO TR 7470-2000 Valve outlets for gas cylinders - List of provisions which are either standardized or in use《储气瓶阀门出口 已标准化或使用中的供应目录》.pdf
  • BS ISO TR 9705-2-2001 Reaction to fire tests - Full scale room tests for surface products - Technical background and guidance《燃烧试验反应 表面产品的全尺寸室内试验 技术背景和指南》.pdf BS ISO TR 9705-2-2001 Reaction to fire tests - Full scale room tests for surface products - Technical background and guidance《燃烧试验反应 表面产品的全尺寸室内试验 技术背景和指南》.pdf
  • BS ISO TS 12927-2000 Lubricants industrial oils and related products (class L) - Family M (metalworking) - Guidelines for establishing specifications《润滑剂、工业油和相关产品(L级) M系列(.pdf BS ISO TS 12927-2000 Lubricants industrial oils and related products (class L) - Family M (metalworking) - Guidelines for establishing specifications《润滑剂、工业油和相关产品(L级) M系列(.pdf
  • 相关搜索

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

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