【计算机类职业资格】计算机三级数据库技术-129及答案解析.doc

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

1、计算机三级数据库技术-129 及答案解析(总分:100.00,做题时间:90 分钟)一、上机题(总题数:1,分数:100.00)1.函数 readDat()的功能是从文件 IN.DAT 中读取 20 行数据,存放到字符串数组 xx 中(每行字符串长度均小于 80)。请编写函数 jsSort(),其功能是:以行为单位对字符串按下面给定的条件进行排序,排序后的结果仍按行重新存入字符串数组 xx 中。最后调用函数 writeDat(),把结果 xx 输出到文件 OUT.DAT 中。 条件:字符串从中间一分为二,左边部分按字符的 ASCII 码值降序排序,右边部分按字符的 ASCII 码值升序排序。如

2、果原字符串长度为奇数,则最中间的字符不参加排序,仍放在原位置上。 例如, 位置 0 1 2 3 4 5 6 7 8 原字符串 a b c d h g f e 处理后 d c b a e f g h 注意:请勿改动主函数 main()、读函数 readDat()和写函数 writeDat()的内容。 【试题程序】 #include stdio.h #include string.h #include stdlib.h char xx2080; void readDat(); void writeDat(); void jsSort() void main() readDat(); jsSort(

3、); writeDat(); void readDat () FILE * in; int i =0; char * p; in = fopen (“IN. DAT“, “r“) ; while (i 20 if(p) *p=0; i+; fclose (in) ; void writeDat () FILE * out; int i ; system (“CLS“) ; out = fopen ( “OUT. DAT“, “w“ ) ; for (i =0;i 20;i + ) printf (“%sn“,xxi) ; fprintf (out, “%sn“, xxi ) ; fclose

4、out) ; (分数:100.00)_计算机三级数据库技术-129 答案解析(总分:100.00,做题时间:90 分钟)一、上机题(总题数:1,分数:100.00)1.函数 readDat()的功能是从文件 IN.DAT 中读取 20 行数据,存放到字符串数组 xx 中(每行字符串长度均小于 80)。请编写函数 jsSort(),其功能是:以行为单位对字符串按下面给定的条件进行排序,排序后的结果仍按行重新存入字符串数组 xx 中。最后调用函数 writeDat(),把结果 xx 输出到文件 OUT.DAT 中。 条件:字符串从中间一分为二,左边部分按字符的 ASCII 码值降序排序,右边部分

5、按字符的 ASCII 码值升序排序。如果原字符串长度为奇数,则最中间的字符不参加排序,仍放在原位置上。 例如, 位置 0 1 2 3 4 5 6 7 8 原字符串 a b c d h g f e 处理后 d c b a e f g h 注意:请勿改动主函数 main()、读函数 readDat()和写函数 writeDat()的内容。 【试题程序】 #include stdio.h #include string.h #include stdlib.h char xx2080; void readDat(); void writeDat(); void jsSort() void main()

6、 readDat(); jsSort(); writeDat(); void readDat () FILE * in; int i =0; char * p; in = fopen (“IN. DAT“, “r“) ; while (i 20 if(p) *p=0; i+; fclose (in) ; void writeDat () FILE * out; int i ; system (“CLS“) ; out = fopen ( “OUT. DAT“, “w“ ) ; for (i =0;i 20;i + ) printf (“%sn“,xxi) ; fprintf (out, “%s

7、n“, xxi ) ; fclose (out) ; (分数:100.00)_正确答案:()解析:void jsSort() int i,j,k; /*定义循环控制变量*/ int str,half; /*定义存储字符串长度的变量*/ char temp; /*定义数据交换时的暂存变量*/ for(i=0;i20;i+) /*逐行对数据进行处理*/ str=strlen(xxi); /*求各行字符串的总长度*/ half=str/2; /*求总长度的一半*/ for(j=0;jhalf-1;j+) /*左边部分按字符的 ASCII 值降序排序*/ for(k=j+1;khalf;k+) if(

8、xxijxxik) temp=xxij; xxij=xxik; xxik=temp; if(str%2=1) /*如果原字符串长度为奇数,则跳过最中间的字符,使之不参加排序*/ half+; for(j=half;jstr-1;j+) /*右边部分按字符的 ASCII 值升序排序*/ for(k=j+1;kstr;k+) if(xxijxxik) temp=xxij; xxij=xxik; xxik=temp; 考点 本题是对字符的排序问题。考查的知识点主要包括:字符串元素的遍历访问,逻辑表达式,数组排序算法。 解析 此题属于字符排序题型;分析题干要求需主要解决 2 个问题:问题 1 如何实现从字符串中间一分为二,并将左边部分按字符的 ASCII 值降序排序;问题 2 如何按照要求将字符串的右边部分按照升序排列。接着分析具体的解决方法,首先用字符串处理函数 strlen 获得字符串的长度,进而求得该长度的二分之一,并由其实现对字符串左右两半部分元素的访问,排序可以使用起泡法实现。

展开阅读全文
相关资源
猜你喜欢
  • ETSI TS 102 464-2015 Satellite Earth Stations and Systems (SES) Broadband Satellite Multimedia (BSM) Interworking with DiffServ QoS (V1 2 1)《卫星地球站和系统(SES) 宽带卫星多媒体(BSM) 与DiffServ Qo.pdf ETSI TS 102 464-2015 Satellite Earth Stations and Systems (SES) Broadband Satellite Multimedia (BSM) Interworking with DiffServ QoS (V1 2 1)《卫星地球站和系统(SES) 宽带卫星多媒体(BSM) 与DiffServ Qo.pdf
  • ETSI TS 102 464-2015 Satellite Earth Stations and Systems (SES) Broadband Satellite Multimedia (BSM) Interworking with DiffServ QoS (V1 2 1)《卫星地球站和系统(SES) 宽带卫星多媒体(BSM) 与DiffServ Qo_1.pdf ETSI TS 102 464-2015 Satellite Earth Stations and Systems (SES) Broadband Satellite Multimedia (BSM) Interworking with DiffServ QoS (V1 2 1)《卫星地球站和系统(SES) 宽带卫星多媒体(BSM) 与DiffServ Qo_1.pdf
  • ETSI TS 102 465-2006 Satellite Earth Stations and Systems (SES) Broadband Satellite Multimedia (BSM) General Security Architecture (V1 1 1)《卫星地面站和系统(SES) 宽带卫星多媒体(BSM) 一般安全架构(版本1 1 .pdf ETSI TS 102 465-2006 Satellite Earth Stations and Systems (SES) Broadband Satellite Multimedia (BSM) General Security Architecture (V1 1 1)《卫星地面站和系统(SES) 宽带卫星多媒体(BSM) 一般安全架构(版本1 1 .pdf
  • ETSI TS 102 466-2007 Satellite Earth Stations and systems (SES) Broadband Satellite Multimedia (BSM) Multicast Security Architecture (V1 1 1)《卫星地面站和系统 (SES) 卫星宽带多媒体 (BSM) 多点传送安全架构 .pdf ETSI TS 102 466-2007 Satellite Earth Stations and systems (SES) Broadband Satellite Multimedia (BSM) Multicast Security Architecture (V1 1 1)《卫星地面站和系统 (SES) 卫星宽带多媒体 (BSM) 多点传送安全架构 .pdf
  • ETSI TS 102 466-2007 Satellite Earth Stations and systems (SES) Broadband Satellite Multimedia (BSM) Multicast Security Architecture (V1 1 1)《卫星地面站和系统 (SES) 卫星宽带多媒体 (BSM) 多点传送安全架构 _1.pdf ETSI TS 102 466-2007 Satellite Earth Stations and systems (SES) Broadband Satellite Multimedia (BSM) Multicast Security Architecture (V1 1 1)《卫星地面站和系统 (SES) 卫星宽带多媒体 (BSM) 多点传送安全架构 _1.pdf
  • ETSI TS 102 468-2007 Digital Video Broadcasting (DVB) IP Datacast over DVB-H Set of Specifications for Phase 1 (V1 1 1)《数字视频广播(DVB) DVB-H上的IP数据广播 第1阶段的规范组(版本1 1 1)》.pdf ETSI TS 102 468-2007 Digital Video Broadcasting (DVB) IP Datacast over DVB-H Set of Specifications for Phase 1 (V1 1 1)《数字视频广播(DVB) DVB-H上的IP数据广播 第1阶段的规范组(版本1 1 1)》.pdf
  • ETSI TS 102 470-1-2009 Digital Video Broadcasting (DVB) IP Datacast Program Specific Information (PSI) Service Information (SI) Part 1 IP Datacast over DVB-H (V1 2 1)《数字视频广播(DVB) I.pdf ETSI TS 102 470-1-2009 Digital Video Broadcasting (DVB) IP Datacast Program Specific Information (PSI) Service Information (SI) Part 1 IP Datacast over DVB-H (V1 2 1)《数字视频广播(DVB) I.pdf
  • ETSI TS 102 470-1-2009 Digital Video Broadcasting (DVB) IP Datacast Program Specific Information (PSI) Service Information (SI) Part 1 IP Datacast over DVB-H (V1 2 1)《数字视频广播(DVB) I_1.pdf ETSI TS 102 470-1-2009 Digital Video Broadcasting (DVB) IP Datacast Program Specific Information (PSI) Service Information (SI) Part 1 IP Datacast over DVB-H (V1 2 1)《数字视频广播(DVB) I_1.pdf
  • ETSI TS 102 470-2-2009 Digital Video Broadcasting (DVB) IP Datacast Program Specific Information (PSI) Service Information (SI) Part 2 IP Datacast over DVB-SH (V1 1 1)《数字视频广播(DVB) .pdf ETSI TS 102 470-2-2009 Digital Video Broadcasting (DVB) IP Datacast Program Specific Information (PSI) Service Information (SI) Part 2 IP Datacast over DVB-SH (V1 1 1)《数字视频广播(DVB) .pdf
  • 相关搜索

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

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