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

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

1、二级 C 语言-201 及答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.下列给定程序中,函数 fun 的功能是将带头结点的单向链表逆置,即若原链表中从头至尾结点数据域依次为 2、4、6、8、10,逆置后,从头至尾结点数据域依次为 10、8、6、4、2。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意 :部分源程序给出如下。 不得增行或删行,也不得更改程序的结构! 试题程序: #includestdio.h #includestdlib.h #define N 5 typedef struct node int

2、 data; struct node *next; NODE; void fun(NODE *h) NODE *p,*q,*r; /*found*/ p=h- 1; /*found*/ if(p= 2)return; q=p-next; p-next=NULL; while(q) r=q-next;q-next=p; /*found*/ p=q;q= 3; h-next=p; NODE *creatlist(int a) NODE *h,*p,*q;int i; h=(NODE*)malloc(sizeof(NODE); h-next=NULL; for(i=0;iN;i+) q=(NODE*

3、)malloc(sizeof(NODE); q-data=ai; q-next=NULL; if(h-next=NULL) h-next=p=q; elsep-next=q;p=q; return h; void outlist(NODE *h) NODE *p;p=h-next; if(p=NULL) printf(“The list is NULL!/n“); else printf(“/nHead“); do printf(“-%d“,p-data); p=p-next; while(p!=NULL); printf(“-End/n“); main() NODE *head; int a

4、N=2,4,6,8,10; head=creatlist(a); printf(“/nThe original list/n“); outlist(head); fun(head); printf(“/nThe list after inverting:/n“); outlist(head); (分数:30.00)二、程序改错题(总题数:1,分数:30.00)2.下列给定程序中,函数 fun 的功能是:计算 s 所指字符串中含有 t 所指字符串的数目,并作为函数值返回。 请改正程序中的错误或在下划线处填上正确的内容并把下划线删除,使它能得出正确的结果。 注意 :不要改动 main 函数,不得增

5、行或删行,也不得更改程序的结构! 试题程序: #includeconio.h #includestdio.h #includestring.h #define N 80 int fun(char *s,char *t) int n; char *p,*r; n=0; p= /*found*/ *r=t; while(*p) if(*r=*p) r+; if*r=“/0“) n+; /*found*/ 1 p+; return n; void main() char aN,bN; int m; printf(“/nPlease enter string a:“); gets(a); printf

6、/nPlease enter substring b:“); gets(b); m=fun(a,b); printf(“/nThe result is:m=%d/n“,m); (分数:30.00)三、程序设计题(总题数:1,分数:40.00)3.请编写函数 fun,其功能是:将放在字符串数组中的 M 个字符串(每串的长度不超过 N),按顺序合并组成一个新的字符串。 例如,若字符串数组中的 M 个字符串为“AAAA“, “BBBBBBB“, “CC“,则合并后的字符串内容应该是“AAAABBBBBBBCC”。 注意 :部分源程序给出如下。 请勿改动主函数 main 和其他函数中的任何内容,仅

7、在函数 fun 的花括号中填入你编写的若干语句。 试题程序: #includestdio.h #includeconio.h #define M 3 #define N 20 void fun(char aMN,char *b) void main() char wMN=“AAAA“,“BBBBBBB“,“CC“,i; char a100=“#“; printf(“The string:/n“); for(i=0;iM;i+) puts(wi); printf(“/n“); fun(w,a); printf(“The A string:/n“); printf(“%s“,a); printf(

8、/n/n“); (分数:40.00)_二级 C 语言-201 答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.下列给定程序中,函数 fun 的功能是将带头结点的单向链表逆置,即若原链表中从头至尾结点数据域依次为 2、4、6、8、10,逆置后,从头至尾结点数据域依次为 10、8、6、4、2。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意 :部分源程序给出如下。 不得增行或删行,也不得更改程序的结构! 试题程序: #includestdio.h #includestdlib.h #define N 5 type

9、def struct node int data; struct node *next; NODE; void fun(NODE *h) NODE *p,*q,*r; /*found*/ p=h- 1; /*found*/ if(p= 2)return; q=p-next; p-next=NULL; while(q) r=q-next;q-next=p; /*found*/ p=q;q= 3; h-next=p; NODE *creatlist(int a) NODE *h,*p,*q;int i; h=(NODE*)malloc(sizeof(NODE); h-next=NULL; for(

10、i=0;iN;i+) q=(NODE*)malloc(sizeof(NODE); q-data=ai; q-next=NULL; if(h-next=NULL) h-next=p=q; elsep-next=q;p=q; return h; void outlist(NODE *h) NODE *p;p=h-next; if(p=NULL) printf(“The list is NULL!/n“); else printf(“/nHead“); do printf(“-%d“,p-data); p=p-next; while(p!=NULL); printf(“-End/n“); main(

11、) NODE *head; int aN=2,4,6,8,10; head=creatlist(a); printf(“/nThe original list/n“); outlist(head); fun(head); printf(“/nThe list after inverting:/n“); outlist(head); (分数:30.00)解析:next NULL r 解析 填空 1:本空考查了为 p 赋初值,根据题目的要求是将带头结点的单向链表逆置可知,p 的初值应该为 h-next。 填空 2:if 判断语句表明当 p 等于什么时就要返回,因此只能当 p 等于 NULL 时返回

12、不用做后面的链表的逆置了。 填空 3:把 q 的指针向后移动,才能实现将带头结点的单向链表逆置。因此本空填写 r。二、程序改错题(总题数:1,分数:30.00)2.下列给定程序中,函数 fun 的功能是:计算 s 所指字符串中含有 t 所指字符串的数目,并作为函数值返回。 请改正程序中的错误或在下划线处填上正确的内容并把下划线删除,使它能得出正确的结果。 注意 :不要改动 main 函数,不得增行或删行,也不得更改程序的结构! 试题程序: #includeconio.h #includestdio.h #includestring.h #define N 80 int fun(char *s

13、char *t) int n; char *p,*r; n=0; p= /*found*/ *r=t; while(*p) if(*r=*p) r+; if*r=“/0“) n+; /*found*/ 1 p+; return n; void main() char aN,bN; int m; printf(“/nPlease enter string a:“); gets(a); printf(“/nPlease enter substring b:“); gets(b); m=fun(a,b); printf(“/nThe result is:m=%d/n“,m); (分数:30.00)

14、解析:应填:r=t;或 r=解析 从字符串 s 中找出子字符串的方法是:从第一个字符开始,对字符串进行遍历,若 s 串的当前字符等于 t 串的第一个字符,两字符串的指针自动加 1,继续比较下一个字符;若比较至字符串 t 的末尾,则跳出循环;若 s 串的字符与 t 串的字符不对应相同,则继续对 s 串的下一个字符进行处理。三、程序设计题(总题数:1,分数:40.00)3.请编写函数 fun,其功能是:将放在字符串数组中的 M 个字符串(每串的长度不超过 N),按顺序合并组成一个新的字符串。 例如,若字符串数组中的 M 个字符串为“AAAA“, “BBBBBBB“, “CC“,则合并后的字符串内容

15、应该是“AAAABBBBBBBCC”。 注意 :部分源程序给出如下。 请勿改动主函数 main 和其他函数中的任何内容,仅在函数 fun 的花括号中填入你编写的若干语句。 试题程序: #includestdio.h #includeconio.h #define M 3 #define N 20 void fun(char aMN,char *b) void main() char wMN=“AAAA“,“BBBBBBB“,“CC“,i; char a100=“#“; printf(“The string:/n“); for(i=0;iM;i+) puts(wi); printf(“/n“); fun(w,a); printf(“The A string:/n“); printf(“%s“,a); printf(“/n/n“); (分数:40.00)_正确答案:()解析:void fun(char aMN,char *b) int i,j,k=0; for(i=0;i for(j=0;aij!=“/0“;j+) bk+=aij; bk=“/0“; /*在字符串最后加上字符串结束标记符*/ 解析 本题考查:字符串连接操作。本程序中第 1 个 for 循环的作用是对二维数组行的控制,第 2 个循环的作用是从同一行中取出字符并存放到一维数组 b 中,语句是 bk+=aij;。

展开阅读全文
相关资源
猜你喜欢
  • DIN 30716-2003 Roller brushes for machines for road surface cleaning and highway maintenance machines - Dimensions《路面清扫设备和公路养护设备用滚筒路刷 尺寸》.pdf DIN 30716-2003 Roller brushes for machines for road surface cleaning and highway maintenance machines - Dimensions《路面清扫设备和公路养护设备用滚筒路刷 尺寸》.pdf
  • DIN 30720-1-2016 Containers for skip loader vehicles - Part 1 Standard containers with a nominal volume of 5 m3 to 10 m3《箕斗装载机车辆集装箱 第1部分 标称容量为5 m3-10 m3的标准集装箱》.pdf DIN 30720-1-2016 Containers for skip loader vehicles - Part 1 Standard containers with a nominal volume of 5 m3 to 10 m3《箕斗装载机车辆集装箱 第1部分 标称容量为5 m3-10 m3的标准集装箱》.pdf
  • DIN 30720-2-2016 Containers for multi-bucket system vehicles - Part 2 Standard containers with a nominal volume of 15 m3 and 20 m3《多斗系统车辆集装箱 第2部分 标称容量为15 m3和20 m3的标准集装箱》.pdf DIN 30720-2-2016 Containers for multi-bucket system vehicles - Part 2 Standard containers with a nominal volume of 15 m3 and 20 m3《多斗系统车辆集装箱 第2部分 标称容量为15 m3和20 m3的标准集装箱》.pdf
  • DIN 30722-1-2015 Roller contact tipper vehicles roller containers - Part 1 Roller contact tipper vehicles up to 26 t roller containers type 1570 made from steel《滚筒接触自动卸货车 第1部分 带钢制1.pdf DIN 30722-1-2015 Roller contact tipper vehicles roller containers - Part 1 Roller contact tipper vehicles up to 26 t roller containers type 1570 made from steel《滚筒接触自动卸货车 第1部分 带钢制1.pdf
  • DIN 30722-2-2015 Roller contact tipper vehicles roller containers - Part 2 Roller contact tipper vehicles up to 32 t roller containers type 1570 made from steel《滚筒接触自动卸货车 第2部分 带钢制1.pdf DIN 30722-2-2015 Roller contact tipper vehicles roller containers - Part 2 Roller contact tipper vehicles up to 32 t roller containers type 1570 made from steel《滚筒接触自动卸货车 第2部分 带钢制1.pdf
  • DIN 30722-3-2015 Roller contact tipper vehicles roller containers - Part 3 Roller contact tipper vehicles up to 12 t roller containers type 900 made from steel《带滚筒箱的滚筒接触自动卸货车 第3部分 .pdf DIN 30722-3-2015 Roller contact tipper vehicles roller containers - Part 3 Roller contact tipper vehicles up to 12 t roller containers type 900 made from steel《带滚筒箱的滚筒接触自动卸货车 第3部分 .pdf
  • DIN 30722-4-1994 Roller containers for the transport on road and rail《第4部分 公路和轨道运输用滚筒式集装箱》.pdf DIN 30722-4-1994 Roller containers for the transport on road and rail《第4部分 公路和轨道运输用滚筒式集装箱》.pdf
  • DIN 30723-1-2016 Multi-bucket system vehicles swivelling devices - Part 1 For standard containers with a nominal volume of 5 5 m3 to 20 m3《多斗系统车辆 可旋转装置 第1部分 标称容量为5 5 m3至20 m3的标准集装箱.pdf DIN 30723-1-2016 Multi-bucket system vehicles swivelling devices - Part 1 For standard containers with a nominal volume of 5 5 m3 to 20 m3《多斗系统车辆 可旋转装置 第1部分 标称容量为5 5 m3至20 m3的标准集装箱.pdf
  • DIN 30723-2-2016 Multi-bucket system vehicles swivelling devices - Part 2 For standard containers with a nominal volume of 2 0 m3 to 5 0 m3《多斗系统车辆 可旋转装置 第2部分 标称容量为2 0 m3至5 0 m3的标准集.pdf DIN 30723-2-2016 Multi-bucket system vehicles swivelling devices - Part 2 For standard containers with a nominal volume of 2 0 m3 to 5 0 m3《多斗系统车辆 可旋转装置 第2部分 标称容量为2 0 m3至5 0 m3的标准集.pdf
  • 相关搜索

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

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