【计算机类职业资格】二级C语言-193 (1)及答案解析.doc

上传人:postpastor181 文档编号:1324984 上传时间:2019-10-17 格式:DOC 页数:7 大小:34KB
下载 相关 举报
【计算机类职业资格】二级C语言-193 (1)及答案解析.doc_第1页
第1页 / 共7页
【计算机类职业资格】二级C语言-193 (1)及答案解析.doc_第2页
第2页 / 共7页
【计算机类职业资格】二级C语言-193 (1)及答案解析.doc_第3页
第3页 / 共7页
【计算机类职业资格】二级C语言-193 (1)及答案解析.doc_第4页
第4页 / 共7页
【计算机类职业资格】二级C语言-193 (1)及答案解析.doc_第5页
第5页 / 共7页
点击查看更多>>
资源描述

1、二级 C 语言-193 (1)及答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.请补充 main()函数,该函数的功能是:把文本文件 text2 中的内容追加到文本文件 text1 的内容之后。例如,文件 text2 的内容为“I“m very happy!”,文件 text1 的内容为“I“m a girl,”,追加之后文件 text1 的内容为“I“m a girl, I“m very happy”。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 main()的横线上填入所编写的若干表达式或语句

2、 试题程序: #includestdlib.h #includestdio.h #includeconio.h #define M 80 void main() FILE*fp, *fp1, *fp2; int i; char cM, ch; system(“CLS“); if(fp=fopen(“text1.dat“, “r“)=NULL) printf(“file text1 cannot be opened/n“); exit(0); printf(“/n text1 contents are: /n/n“); for(i=0; (ch=fgetc(fp)!=EOF; i+) ci=c

3、h; putchar(ci); fclose(fp); if(fp=fopen(“text2.dat“, “r“)=NULL) printf(“file text2 cannot be opened/n“); exit(0); printf(“/n/n/nB contents are: /n/n“); for(i=0; (ch=fgetc(fp)!=EOF; i+) di=ch; putchar(ci); fclose(fp); if(fp1=fopen(“text1.dat“, “a“) 1 (fp2=fopen(“text2.dat“, “r“) while(ch=fgetc(fp2)!=

4、EOF) 2; else printf(“Can not open text1 text2!/n“); fclose(fp2); fclose(fp1); printf(“/n*new text1 contents*/n/n“); if(fp=fopen(“text1.dat“, “r“)=NULL) printf(“file text1 cannot be opened/n“): exit(0); for(i=0; (ch=fgetc(fp)!=EOF; i+) ci=ch; putchar(ci); 3; (分数:30.00)二、程序改错题(总题数:1,分数:40.00)2.下列给定程序中

5、函数 proc()的功能是:利用插入排序法对字符串中的字符按从大到小的顺序进行排序。插入法的基本方法是:先对字符串中的头两个元素进行排序,然后把第 3 个字符插入前 2 个字符中,插入后前 3 个字符依然有序,再把第 4 个字符插入前 3 个字符中,待排序的字符串已在主函数中赋予。例如,原始字符串为“goodluck”,则排序后的字符串为“uoolkgdc”。 请修改程序中的错误,使它能得到正确结果。 注意:不要改动 main()函数,不得增行或删行,也不得更改程序的结构。 试题程序: #includestring.h #includestdio.h #define M 80 void pr

6、oc(char*aa) int i, j, n; char ch; n=strlen(aa); for(i=1; in; i+) ch=aai; j=i-1; /*found* while(j=0)|(chaaj) aaj+1=aaj; j-; /*found* aaj=ch; void main() char strM=“goodluck“; printf(“The original string: %s/n“, str); proc(str); printf(“The string after sorting: %s/n/n“, str); (分数:40.00)_三、程序设计题(总题数:1

7、分数:30.00)3.假定输入的字符串中只包含字母和*号。请编写函数 proc(),它的功能是:使字符串中前部的*号不得多余 m 个;若多余 m 个,则删除多余的*号;若少于或等于 m 个,则什么也不做,字符串中间和尾部的*号不删除。 例如,字符串中的内容为*A*BC*DEF*G*,若 m 的值为 2,删除后,字符串中的内容则应当是*A*BC*DEF*G*;若 m 的值为 4,则字符串中的内容仍为*A*BC*DEF*G*。n 的值在主函数中输入。在编写函数时,不得使用 C 语言提供的字符串函数。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 proc

8、)的花括号中填入所编写的若干语句。 试题程序: #includestdio.h #includeconio.h void proc(char*a, int n) void main() char str81; int m; printf(“Enter a string: /n“); gets(str); printf(“Enter m: “); scanf(“%d“, proc(str, m); printf(“The string after deleted: /n“); puts(str); (分数:30.00)_二级 C 语言-193 (1)答案解析(总分:100.00,做题时间:90

9、 分钟)一、程序填空题(总题数:1,分数:30.00)1.请补充 main()函数,该函数的功能是:把文本文件 text2 中的内容追加到文本文件 text1 的内容之后。例如,文件 text2 的内容为“I“m very happy!”,文件 text1 的内容为“I“m a girl,”,追加之后文件 text1 的内容为“I“m a girl, I“m very happy”。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 main()的横线上填入所编写的若干表达式或语句。 试题程序: #includestdlib.h #includestdio

10、h #includeconio.h #define M 80 void main() FILE*fp, *fp1, *fp2; int i; char cM, ch; system(“CLS“); if(fp=fopen(“text1.dat“, “r“)=NULL) printf(“file text1 cannot be opened/n“); exit(0); printf(“/n text1 contents are: /n/n“); for(i=0; (ch=fgetc(fp)!=EOF; i+) ci=ch; putchar(ci); fclose(fp); if(fp=fope

11、n(“text2.dat“, “r“)=NULL) printf(“file text2 cannot be opened/n“); exit(0); printf(“/n/n/nB contents are: /n/n“); for(i=0; (ch=fgetc(fp)!=EOF; i+) di=ch; putchar(ci); fclose(fp); if(fp1=fopen(“text1.dat“, “a“) 1 (fp2=fopen(“text2.dat“, “r“) while(ch=fgetc(fp2)!=EOF) 2; else printf(“Can not open text

12、1 text2!/n“); fclose(fp2); fclose(fp1); printf(“/n*new text1 contents*/n/n“); if(fp=fopen(“text1.dat“, “r“)=NULL) printf(“file text1 cannot be opened/n“): exit(0); for(i=0; (ch=fgetc(fp)!=EOF; i+) ci=ch; putchar(ci); 3; (分数:30.00)解析: char ch; n=strlen(aa); for(i=1; in; i+) ch=aai; j=i-1; /*found* wh

13、ile(j=0)|(chaaj) aaj+1=aaj; j-; /*found* aaj=ch; void main() char strM=“goodluck“; printf(“The original string: %s/n“, str); proc(str); printf(“The string after sorting: %s/n/n“, str); (分数:40.00)_正确答案:()解析:(1)错误:while(j=0)|(chaaj) 正确:while(j=0) 正确:aaj+1=ch; 解析 题目要求按从大到小的顺序排列,而且数组的下标都是从 0 开始的,这两个条件都要

14、符合,因此“while(j=0)|(chaaj)”应改为“while(j=0)”改为“aaj+1=ch;”。三、程序设计题(总题数:1,分数:30.00)3.假定输入的字符串中只包含字母和*号。请编写函数 proc(),它的功能是:使字符串中前部的*号不得多余 m 个;若多余 m 个,则删除多余的*号;若少于或等于 m 个,则什么也不做,字符串中间和尾部的*号不删除。 例如,字符串中的内容为*A*BC*DEF*G*,若 m 的值为 2,删除后,字符串中的内容则应当是*A*BC*DEF*G*;若 m 的值为 4,则字符串中的内容仍为*A*BC*DEF*G*。n 的值在主函数中输入。在编写函数时,

15、不得使用 C 语言提供的字符串函数。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 proc()的花括号中填入所编写的若干语句。 试题程序: #includestdio.h #includeconio.h void proc(char*a, int n) void main() char str81; int m; printf(“Enter a string: /n“); gets(str); printf(“Enter m: “); scanf(“%d“, proc(str, m); printf(“The string after deleted

16、 /n“); puts(str); (分数:30.00)_正确答案:()解析:void proc(char*a, int n) int i=0, k=0; char*p, *t; p=t=a; while(*t=“*“) /通过 t 的移动来数前面*号的个数 k k+; 1+; if(kn) /当前个数 k 大于 n 时,则删除多余的 while(*p) ai=*(p+k-n); /通过 p 的移动来实现 i+; p+; ai=“/0“; /最后用“/0“作为字符串结束标志 解析 题目中要求字符串前部的*不得多于 m,首先要计算出字符串前部的*号的个数,与变量 m 进行比较。当字符串前部的*多于 m 个时,删除多余的*。规定不能用字符串函数处理,可以通过移动字符串的首指针来实现。

展开阅读全文
相关资源
猜你喜欢
  • EN 13410-2001 en Gas-Fired Overhead Radiant Heaters - Ventilation Requirements for Non-Domestic Premises (Incorporating Corrigendum July 2002)《燃气顶部辐射加热器 非家用房屋的通风要求 合并勘误表-2002年7月》.pdf EN 13410-2001 en Gas-Fired Overhead Radiant Heaters - Ventilation Requirements for Non-Domestic Premises (Incorporating Corrigendum July 2002)《燃气顶部辐射加热器 非家用房屋的通风要求 合并勘误表-2002年7月》.pdf
  • EN 13411-1-2002 en Terminations for steel wire ropes - Safety - Part 1 Thimbles for steel wire rope slings (Incorporates Amendment A1 2008)《钢丝绳终端设备的安全性 第1部分 钢丝绳吊索用穿线环 合并勘误表A1-2008》.pdf EN 13411-1-2002 en Terminations for steel wire ropes - Safety - Part 1 Thimbles for steel wire rope slings (Incorporates Amendment A1 2008)《钢丝绳终端设备的安全性 第1部分 钢丝绳吊索用穿线环 合并勘误表A1-2008》.pdf
  • EN 13411-2-2001 en Terminations for steel wire ropes - Safety - Part 2 Splicing of eyes for wire rope slings (Incorporates Amendment A1 2008)《钢丝绳接线端的安全性 第2部分 钢丝绳吊索眼拼接 包含修改件A1-2008》.pdf EN 13411-2-2001 en Terminations for steel wire ropes - Safety - Part 2 Splicing of eyes for wire rope slings (Incorporates Amendment A1 2008)《钢丝绳接线端的安全性 第2部分 钢丝绳吊索眼拼接 包含修改件A1-2008》.pdf
  • EN 13411-3-2004 en Terminations for steel wire ropes - Safety - Part 3 Ferrules and ferrule-securing (Incorporates Amendment A1 2008)《钢丝绳终端设备的安全性 第3部分 金属箍加固环 包含修改件A1-2008》.pdf EN 13411-3-2004 en Terminations for steel wire ropes - Safety - Part 3 Ferrules and ferrule-securing (Incorporates Amendment A1 2008)《钢丝绳终端设备的安全性 第3部分 金属箍加固环 包含修改件A1-2008》.pdf
  • EN 13411-4-2011 en Terminations for steel wire ropes - Safety - Part 4 Metal and resin socketing《钢丝绳接线端 安全性 第4部分 金属和树脂套接》.pdf EN 13411-4-2011 en Terminations for steel wire ropes - Safety - Part 4 Metal and resin socketing《钢丝绳接线端 安全性 第4部分 金属和树脂套接》.pdf
  • EN 13411-5-2003 en Terminations for steel wire ropes - Safety - Part 5 U-bolt wire rope grips (Incorporates Amendment A1 2008)《钢丝绳接线端的安全性 第5部分 U形钢丝绳夹 包含修改件 A1-2008》.pdf EN 13411-5-2003 en Terminations for steel wire ropes - Safety - Part 5 U-bolt wire rope grips (Incorporates Amendment A1 2008)《钢丝绳接线端的安全性 第5部分 U形钢丝绳夹 包含修改件 A1-2008》.pdf
  • EN 13411-6-2004 en Terminations for steel wire ropes - Safety - Part 6 Asymmetric wedge socket (Incorporates Amendment A1 2008)《钢丝绳接线端 安全 第6部分 非对称楔形连接套筒 包含修改件A1-2008》.pdf EN 13411-6-2004 en Terminations for steel wire ropes - Safety - Part 6 Asymmetric wedge socket (Incorporates Amendment A1 2008)《钢丝绳接线端 安全 第6部分 非对称楔形连接套筒 包含修改件A1-2008》.pdf
  • EN 13411-7-2006 en Terminations for steel wire ropes - Safety - Part 7 Symmetric wedge socket (Incorporates Amendment A1 2008)《钢丝绳终端设备的安全性 第7部分 对称楔形连接套筒 包含修改件A1-2008》.pdf EN 13411-7-2006 en Terminations for steel wire ropes - Safety - Part 7 Symmetric wedge socket (Incorporates Amendment A1 2008)《钢丝绳终端设备的安全性 第7部分 对称楔形连接套筒 包含修改件A1-2008》.pdf
  • EN 13411-8-2011 en Terminations for steel wire ropes - Safety - Part 8 Swage terminals and swaging《钢丝绳索的终端 安全 第8部分 铁模终端和模锻》.pdf EN 13411-8-2011 en Terminations for steel wire ropes - Safety - Part 8 Swage terminals and swaging《钢丝绳索的终端 安全 第8部分 铁模终端和模锻》.pdf
  • 相关搜索

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

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