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

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

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

2、L 中,最后调用函数 WriteDat()把结果输出到文件 OUT.DAT 中。注意:部分源程序给出如下。请勿改动主函数 main()、读数据函数 ReadDat()和输出数据函数 WriteDat()的内容。试题源程序#includeStdio.h#includestring.h#includeconio.h#includestdlib.h#define MAX 100typedef Structchar dm5;/*产品代码*/char mc11;/*产品名称*/int dj;/*单价*/int Sl;/*数量*/long je;/*金额*/PRO;PRO SeiiMAX;void Rea

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

4、Selli.dj=atoi(ch);memcpy(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;if(fp=fopen(“OUT.DAT“,“w“)=NULL)return;for(i=0;i100;i+)printf(“%s%s%4d%5d%5d/n“,selli.dm,selli.mc,selli.dj,selli.sl,selli.je);fprintf(fp,“%S%S%4d%5d%10ld/n“,selli

5、.dm,selli.mc,selli.dj,selli.sl,selli.je);fclose(fp);(分数:100.00)_三级网络技术机试-168 答案解析(总分:100.00,做题时间:90 分钟)一、上机题(总题数:1,分数:100.00)1.已知在文件 IN.DAT 中存有 100 个产品销售记录,每个产品销售记录由产品代码 DM(字符型,4 位)、产品名称 MC(字符型,10 位)、单价 DJ(整型)、数量 SL(整型)、金额 JE(长整型)五部分组成。其中:金额=单价数量。函数 ReadDat()读取这 100 个销售记录并将其存入结构数组 SELL 中。请编制函数 SortD

6、at(),其功能要求为:按金额从小到大进行排列,若金额相同,则按产品代码从大到小进行排列,最终排列结果仍存入结构数组距 SELL 中,最后调用函数 WriteDat()把结果输出到文件 OUT.DAT 中。注意:部分源程序给出如下。请勿改动主函数 main()、读数据函数 ReadDat()和输出数据函数 WriteDat()的内容。试题源程序#includeStdio.h#includestring.h#includeconio.h#includestdlib.h#define MAX 100typedef Structchar dm5;/*产品代码*/char mc11;/*产品名称*/i

7、nt dj;/*单价*/int Sl;/*数量*/long je;/*金额*/PRO;PRO SeiiMAX;void ReadDat();void WriteDat();void SortDat()void main()memset(sell,0,sizeof(sell);ReadDat();SortDat();WriteDat();void ReadDat()FILE *fp;char str80,ch11;int i; if(fp=fopen(“IN.DAT“,“r“)=NULL)return;for(i=0;i100; i+)fgets(str,80,fp);memcpy(selli.

8、dm,str,4);memcpy(selli.mc,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);selli.je=(long) Selli.dj*selli.sl;fclose(fp);void WriteDat()FILE *fp;int i;if(fp=fopen(“OUT.DAT“,“w“)=NULL)return;for(i=0;i100;i+)printf(“%s%s%4d%5d%5d/n“,selli.dm,selli.mc,s

9、elli.dj,selli.sl,selli.je);fprintf(fp,“%S%S%4d%5d%10ld/n“,selli.dm,selli.mc,selli.dj,selli.sl,selli.je);fclose(fp);(分数:100.00)_正确答案:(void SortDat()int i,j;PRO swap;for(i=0; iMAX-1;i+)for(j=i+1; jMAX;j+)if(selli.Jesellj.je) swap=selli;selli=sellj;sellj=swap;elSe if(selli.je=sellj.je)if(strcmp(selli.d

10、m,sellj.dm)0)swap=selli; selli=sellj; sellj=swap;)解析:解析本题主要考查的是产品因素的比较排列问题。和冒泡排序法相似,用一个两重 for 循环来实现。第一个for 循环用来遍历每个结构体(除了最后一个),第二个 for 循环用来遍历某个结构体 selli之后的每个结构体 sellj,将两者的 je 进行比较。如果 selli.je 大,则使用临时变量 swap 来交换两者的位置;如果相等,则再比较 selli.dm 和 selli.dm,如果前者小,则交换位置。字符串的比较通过 strcmp()函数进行,若两个字符串相等则返回 0,如果前者大于后者则返回一个正整数,否则返回一个负整数。

展开阅读全文
相关资源
猜你喜欢
  • DIN EN ISO 14891-2002 Milk and milk products - Determination of nitrogen content - Routine method using combustion according to the Dumas principle (ISO 14891 2002) German version .pdf DIN EN ISO 14891-2002 Milk and milk products - Determination of nitrogen content - Routine method using combustion according to the Dumas principle (ISO 14891 2002) German version .pdf
  • DIN EN ISO 14895-2016 Small craft - Liquid-fuelled galley stoves and heating appliances (ISO 14895 2016) German version EN ISO 14895 2016《小艇 液体燃料厨灶和加热器具(ISO 14895-2016) 德文版本EN ISO .pdf DIN EN ISO 14895-2016 Small craft - Liquid-fuelled galley stoves and heating appliances (ISO 14895 2016) German version EN ISO 14895 2016《小艇 液体燃料厨灶和加热器具(ISO 14895-2016) 德文版本EN ISO .pdf
  • DIN EN ISO 14896-2009 Plastics - Polyurethane raw materials - Determination of isocyanate content (ISO 14896 2009) English version of DIN EN ISO 14896 2009-07《塑料 聚氨酯原材料 异氰酸酯的测定(ISO.pdf DIN EN ISO 14896-2009 Plastics - Polyurethane raw materials - Determination of isocyanate content (ISO 14896 2009) English version of DIN EN ISO 14896 2009-07《塑料 聚氨酯原材料 异氰酸酯的测定(ISO.pdf
  • DIN EN ISO 14902-2002 Animal feeding stuffs - Determination of trypsin inhibitor activity of soya products (ISO 14902 2001) German version EN ISO 14902 2001《动物饲料 大豆制品胰蛋白酶抑制剂活性的测定 (.pdf DIN EN ISO 14902-2002 Animal feeding stuffs - Determination of trypsin inhibitor activity of soya products (ISO 14902 2001) German version EN ISO 14902 2001《动物饲料 大豆制品胰蛋白酶抑制剂活性的测定 (.pdf
  • DIN EN ISO 14906 A1-2015 Electronic fee collection - Application interface definition for dedicated short-range communication - Amendment 1 (ISO 14906 2011 Amd 1 2015) English vers.pdf DIN EN ISO 14906 A1-2015 Electronic fee collection - Application interface definition for dedicated short-range communication - Amendment 1 (ISO 14906 2011 Amd 1 2015) English vers.pdf
  • DIN EN ISO 14906 Berichtigung 1-2015 Electronic fee collection - Application interface definition for dedicated short-range communication (ISO 14906 2011) English version EN ISO 14.pdf DIN EN ISO 14906 Berichtigung 1-2015 Electronic fee collection - Application interface definition for dedicated short-range communication (ISO 14906 2011) English version EN ISO 14.pdf
  • DIN EN ISO 14906-2012 Electronic fee collection - Application interface definition for dedicated short-range communication (ISO 14906 2011) English version EN ISO 14906 2011《电子收费 专.pdf DIN EN ISO 14906-2012 Electronic fee collection - Application interface definition for dedicated short-range communication (ISO 14906 2011) English version EN ISO 14906 2011《电子收费 专.pdf
  • DIN EN ISO 14911-1999 Water quality - Determination of dissolved Li Na NH K Mn Ca Mg Sr and Ba using ion chromatography - Method for water and waste water (ISO 14911 1998) German v.pdf DIN EN ISO 14911-1999 Water quality - Determination of dissolved Li Na NH K Mn Ca Mg Sr and Ba using ion chromatography - Method for water and waste water (ISO 14911 1998) German v.pdf
  • DIN EN ISO 14912-2006 Gas analysis - Conversion of gas mixture composition data (ISO 14912 2003) English version of DIN EN ISO 14912 2006-11《气体分析 气体混合成份数据的转换(ISO 14912 2003)》.pdf DIN EN ISO 14912-2006 Gas analysis - Conversion of gas mixture composition data (ISO 14912 2003) English version of DIN EN ISO 14912 2006-11《气体分析 气体混合成份数据的转换(ISO 14912 2003)》.pdf
  • 相关搜索

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

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