【计算机类职业资格】三级网络技术机试-270及答案解析.doc

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

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

2、ll 中,最后调用函数 WriteDat()把结果输出到文件 OUT16.DAT 中。注意:部分源程序已给出。请勿改动主函数 main()、渎函数 ReadDat()和写函数 WriteDat()的内容。试题程序:#include stdio.h#include mem.h#include string.h#include conio.h#include stdlib.h#define MAX 100typedef structchar dm5; /* 产品代码 */char mc11; /* 产品名称 */int dj; /* 单价 */int s1; /* 数量 */long je; /*

3、 金额 */PRO;PRO sell MAX;void ReadDat ();void WriteDat();void SortDat ()main ( )memset (sell, 0, sizeof(sell);ReadDat ();SortDat ();WriteDat ();void ReadDat ()FILE *fp;char str80, ch11;int i;fp = fopen(“IN16.DAT“, “r“);for(i=0; i100; i+)fgets (str, 80, fp);memcpy(selli.dm, str, 4);memcpy (sell i .mc,

4、str + 4, 10);memcpy(ch, str + 14, 4);ch4 = 0;selli .dj = atoi(ch);memcpy(ch, str +18, 5);ch5 = 0;selli.s1 = atoi(ch);selli.je = (long) selli.dj * selli.s1;fclose(fp);void WriteDat()FILE *fp;int i;fp = fopen(“OUT16.DAT“, “w“);for(i = 0; i100; i+)fprintf(fp, “%s %s %4d %5d %101d/n“, selli .dm, selli .

5、mc,selli.dj, selli.s1, selli.je);felose (fp);(分数:100.00)_三级网络技术机试-270 答案解析(总分:100.00,做题时间:90 分钟)一、上机题(总题数:1,分数:100.00)1.已知文件 IN16.DAT 中存有 100 个产品销售记录,每个产品销售记录由产品代码 dm(字符型 4 位)、产品名称 mc(字符型 10 位)、单价由(整型)、数量 s1(整型)、金额 je(长整型)几部分组成。其中:金额 =单价数量。函数 ReadDat()的功能是读取这 100 个销售记录并存入结构数组 sell 中。请编制函数SortDat(),其

6、功能要求:按产品名称从大到小进行排列,若产品名称相同,则按金额从大到小进行排列,最终排列结果仍存入结构数组 sell 中,最后调用函数 WriteDat()把结果输出到文件 OUT16.DAT 中。注意:部分源程序已给出。请勿改动主函数 main()、渎函数 ReadDat()和写函数 WriteDat()的内容。试题程序:#include stdio.h#include mem.h#include string.h#include conio.h#include stdlib.h#define MAX 100typedef structchar dm5; /* 产品代码 */char mc1

7、1; /* 产品名称 */int dj; /* 单价 */int s1; /* 数量 */long je; /* 金额 */PRO;PRO sell MAX;void ReadDat ();void WriteDat();void SortDat ()main ( )memset (sell, 0, sizeof(sell);ReadDat ();SortDat ();WriteDat ();void ReadDat ()FILE *fp;char str80, ch11;int i;fp = fopen(“IN16.DAT“, “r“);for(i=0; i100; i+)fgets (st

8、r, 80, fp);memcpy(selli.dm, str, 4);memcpy (sell i .mc, str + 4, 10);memcpy(ch, str + 14, 4);ch4 = 0;selli .dj = atoi(ch);memcpy(ch, str +18, 5);ch5 = 0;selli.s1 = atoi(ch);selli.je = (long) selli.dj * selli.s1;fclose(fp);void WriteDat()FILE *fp;int i;fp = fopen(“OUT16.DAT“, “w“);for(i = 0; i100; i+

9、)fprintf(fp, “%s %s %4d %5d %101d/n“, selli .dm, selli .mc,selli.dj, selli.s1, selli.je);felose (fp);(分数:100.00)_正确答案:(void SortDat()int i,j;PRO xy;for(i=0;iMAX-1;i+)for(j=i+1;jMAX;j+)if(strcmp(selli.mc,sellj.mc)xy=selli;sell i=sellj;sellj=xy;else if(strcmp(selli.mc,selli.mc)=0) *若产品名称相同,则按金额从大到小进行排

10、列*if(selli.jesellj.je)xy=selli;selli=sellj;sellj=xy;)解析:解析 本题是有关结构体数组的排序问题。可以用选择法来实现,即用第一个元素的产品名称依次和它后面的元素的产品名称进行比较,如果发现当前元素的产品名称比后面的某个元素的产品名称的对应位置的字符的 ASCII 码小(这里用到了字符串比较函数 strcmp(),则交换这两个元素的位置,继续和后面的其他元素进行比较,最终在第一个元素中存放的是产品名称最大的元素。以此类推,就实现了从大到小排序的功能。注意:这里要进行交换的是两个结构体变量,而不是它们的某一个域,因此,要借助第三个结构体变量来充当中间容器。若发现产品名称是相同的,则要按照金额从大到小进行排序。

展开阅读全文
相关资源
猜你喜欢
  • BS ISO 14502-2-2005 Determination of substances characteristic of green and black tea - Content of catechins in green tea - Method using high-performance liquid chromatography《绿茶和红.pdf BS ISO 14502-2-2005 Determination of substances characteristic of green and black tea - Content of catechins in green tea - Method using high-performance liquid chromatography《绿茶和红.pdf
  • BS ISO 14507-2003 Soil quality - Pretreatment of samples for determination of organic contaminants《土质 有机污物测定用样品的预处理》.pdf BS ISO 14507-2003 Soil quality - Pretreatment of samples for determination of organic contaminants《土质 有机污物测定用样品的预处理》.pdf
  • BS ISO 14511-2002 Measurement of fluid flow in closed conduits Thermal mass flowmeters《封闭管道流体流量测量 热质量流量计》.pdf BS ISO 14511-2002 Measurement of fluid flow in closed conduits Thermal mass flowmeters《封闭管道流体流量测量 热质量流量计》.pdf
  • BS ISO 14512-2000 Passenger cars - Straight-ahead braking on surfaces with split coefficient of friction - Open-loop test method《乘用车 具有裂口摩擦系数的正向前方地面制动系统 开环试验方法》.pdf BS ISO 14512-2000 Passenger cars - Straight-ahead braking on surfaces with split coefficient of friction - Open-loop test method《乘用车 具有裂口摩擦系数的正向前方地面制动系统 开环试验方法》.pdf
  • BS ISO 14513-2016 Road vehicles Pedestrian protection Head impact test method《道路车辆 行人保护 头的撞击试验方法》.pdf BS ISO 14513-2016 Road vehicles Pedestrian protection Head impact test method《道路车辆 行人保护 头的撞击试验方法》.pdf
  • BS ISO 14520-11-2006 Gaseous fire-extinguishing systems - Physical properties and system design - HFC 236fa extinguishant《气体灭火系统 物理性能和系统设计 HFC 236fa灭火剂》.pdf BS ISO 14520-11-2006 Gaseous fire-extinguishing systems - Physical properties and system design - HFC 236fa extinguishant《气体灭火系统 物理性能和系统设计 HFC 236fa灭火剂》.pdf
  • BS ISO 14520-2-2006 Gaseous fire-extinguishing systems - Physical properties and system design - CF3I extinguishant《气体灭火系统 物理性能和系统设计 CF3I灭火剂》.pdf BS ISO 14520-2-2006 Gaseous fire-extinguishing systems - Physical properties and system design - CF3I extinguishant《气体灭火系统 物理性能和系统设计 CF3I灭火剂》.pdf
  • BS ISO 14524-2009 Photography - Electronic still-picture Cameras - Methods for measuring optoelectronic conversion functions (OECFs)《摄影 数码照相机 光电转换函数(OECFs)的测量方法》.pdf BS ISO 14524-2009 Photography - Electronic still-picture Cameras - Methods for measuring optoelectronic conversion functions (OECFs)《摄影 数码照相机 光电转换函数(OECFs)的测量方法》.pdf
  • BS ISO 14531-2-2006 Plastics pipes and fittings - Crosslinked polyethylene (PE-X) pipe systems for the conveyance of gaseous fuels - Metric series - Specifications - Fittings for h.pdf BS ISO 14531-2-2006 Plastics pipes and fittings - Crosslinked polyethylene (PE-X) pipe systems for the conveyance of gaseous fuels - Metric series - Specifications - Fittings for h.pdf
  • 相关搜索

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

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