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

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

1、二级 C 语言-301 (1)及答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.请补充函数 proc(),该函数的功能是:把从主函数中输入的字符串 str2 倒置后接在字符串 str1 后面。例如,str1=“How do you”,str2=“?od”,结果输出:“How do you do?” 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 proc()的横线上填入所编写的若干表达式或语句。 试题程序: #includestdlib.h #includestdio.h #includeconio.

2、h #define M 40 void proc(char*str1, char*str2) int i=0, j=0, k=0, n; char ch; char *p1=str1; char *p2=str2; while(*(pl+i) i+; while(*(p2+j) j+; n= 1; for(; k=j/2; k+, j-) ch=*(p2+k); *(p2+k)=*(p2+j); *(p2+j)=ch; 2; for(; 3; i+) *(p1+i)=*p2+; *(p1+i)=“/0“; void main() char str1M, str2M; system(“CLS“)

3、 printf(“*Input the string str1 prind(“/nstr1:“); gets(str1); printf(“/nstr2:“); gets(str2); printf(“*The string str1 puts(str1); puts(str2); proc(str1, str2); printf(“*The new string*/n“); puts(str1); (分数:30.00)二、程序改错题(总题数:1,分数:40.00)2.下列给定程序中,函数 proc()的功能是:求出以下分数序列的前 m 项之和。 2/1,3/2,5/3,8/5,13/8,2

4、1/13, 和值通过函数值返回 main()函数。例如,若 m=6,则应输出 10.007051。 请修改程序中的错误,使它能得出正确的结果。 注意:不要改动 main()函数,不得增行或删行,也不得更改程序的结构。 试题程序: #includestdlib.h #includeconio.h #includestdio.h /*found* proc(int n) int a=2, b=1, c, k; double s=0.0; for(k=1; k=n; k+) s=s+1.0*a/b; /*found* c=a; a+=b; b+=c; return(s); void main() i

5、nt m=5; system(“CLS“); printf(“/nThe value of function is: %1f/n“, proc(m); (分数:40.00)_三、程序设计题(总题数:1,分数:30.00)3.M 名学生的成绩已在主函数中放入一个带头结点的链表结构中,h 指向链表的带头结点。请编写函数proc(),它的功能是:找出学生的最高分,由函数值返回。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 proc()的花括号中填入所编写的若干语句。 试题程序: #includestdio.h #includestdlib.h #defin

6、e M 8 struct slist double s; struct slist *next; ; typedef struct slist STREC; double proc(STREC *h) STREC*creat(double*s) STREC *h, *p, *q; int i=0; h=p=(STREC*)malloc(sizeof(STREC); p-s=0; while(iM) /产生 8 个结点的链表,各分数存入链表中 q=(STREC*)malloc(sizeof(STREC); p-s=si; i+; p-next=q; p=q; p-next=NULL; retur

7、n h; /返回链表的首地址 void outlist(STREC *h) STREC *p; p=h; printf(“head“); do printf(“-%2.0f“, p-s); p=p-next; /输出各分数 while(p-next!=NULL); printf(“/n/n“); void main() double stuM=56, 89, 76, 95, 91, 68, 75, 85, max; STREC*h; h=creat(stu); outlist(h); max=proc(h); printf(“max=%6.1f/n“, max); (分数:30.00)_二级

8、C 语言-301 (1)答案解析(总分:100.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:30.00)1.请补充函数 proc(),该函数的功能是:把从主函数中输入的字符串 str2 倒置后接在字符串 str1 后面。例如,str1=“How do you”,str2=“?od”,结果输出:“How do you do?” 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 proc()的横线上填入所编写的若干表达式或语句。 试题程序: #includestdlib.h #includestdio.h #includeconio.h #d

9、efine M 40 void proc(char*str1, char*str2) int i=0, j=0, k=0, n; char ch; char *p1=str1; char *p2=str2; while(*(pl+i) i+; while(*(p2+j) j+; n= 1; for(; k=j/2; k+, j-) ch=*(p2+k); *(p2+k)=*(p2+j); *(p2+j)=ch; 2; for(; 3; i+) *(p1+i)=*p2+; *(p1+i)=“/0“; void main() char str1M, str2M; system(“CLS“); pr

10、intf(“*Input the string str1 prind(“/nstr1:“); gets(str1); printf(“/nstr2:“); gets(str2); printf(“*The string str1 puts(str1); puts(str2); proc(str1, str2); printf(“*The new string*/n“); puts(str1); (分数:30.00)解析:j- *(p2+n)=“/0“ *p2解析 由函数 proc()可知,变量 n 存放的是字符串 p2 的长度,因此,第一处填“j-”;根据题目中要求要将 str2 逆置,逆置完

11、成后要为该字符串重新添加结束符,因此,第二处填“*(p2+n)=“/0“”;将逆置后的 str2 接到 str1 后面,直到 str2 的最后一个字符,因此,第三处填“*p2”。二、程序改错题(总题数:1,分数:40.00)2.下列给定程序中,函数 proc()的功能是:求出以下分数序列的前 m 项之和。 2/1,3/2,5/3,8/5,13/8,21/13, 和值通过函数值返回 main()函数。例如,若 m=6,则应输出 10.007051。 请修改程序中的错误,使它能得出正确的结果。 注意:不要改动 main()函数,不得增行或删行,也不得更改程序的结构。 试题程序: #includes

12、tdlib.h #includeconio.h #includestdio.h /*found* proc(int n) int a=2, b=1, c, k; double s=0.0; for(k=1; k=n; k+) s=s+1.0*a/b; /*found* c=a; a+=b; b+=c; return(s); void main() int m=5; system(“CLS“); printf(“/nThe value of function is: %1f/n“, proc(m); (分数:40.00)_正确答案:()解析:(1)错误:proc(int n) 正确:double

13、 proc(int n) (2)错误:c=a; a+=b; b+=c; 正确:c=a; a+=b; b=c; 解析 由 main()函数中的 proc()函数调用可知,函数 proc()的返回值为double 型数据。因此,“proc(int n)”应改为“double proc(int n)”。根据数列的特点可知,下一项的分子是上一项的分子和分母之和,下一项的分母为上一项的分子。根据数列的这个特点,“c=a;a+=b;b+=c;”应改为“c=a;a+=b;b=c;”。三、程序设计题(总题数:1,分数:30.00)3.M 名学生的成绩已在主函数中放入一个带头结点的链表结构中,h 指向链表的带头

14、结点。请编写函数proc(),它的功能是:找出学生的最高分,由函数值返回。 注意:部分源程序给出如下。 请勿改动 main()函数和其他函数中的任何内容,仅在函数 proc()的花括号中填入所编写的若干语句。 试题程序: #includestdio.h #includestdlib.h #define M 8 struct slist double s; struct slist *next; ; typedef struct slist STREC; double proc(STREC *h) STREC*creat(double*s) STREC *h, *p, *q; int i=0;

15、h=p=(STREC*)malloc(sizeof(STREC); p-s=0; while(iM) /产生 8 个结点的链表,各分数存入链表中 q=(STREC*)malloc(sizeof(STREC); p-s=si; i+; p-next=q; p=q; p-next=NULL; return h; /返回链表的首地址 void outlist(STREC *h) STREC *p; p=h; printf(“head“); do printf(“-%2.0f“, p-s); p=p-next; /输出各分数 while(p-next!=NULL); printf(“/n/n“); v

16、oid main() double stuM=56, 89, 76, 95, 91, 68, 75, 85, max; STREC*h; h=creat(stu); outlist(h); max=proc(h); printf(“max=%6.1f/n“, max); (分数:30.00)_正确答案:()解析:double proc(STREC*h) double max=h-s; /定义 max 放其最高分 while(h-next!=NULL) /根据链表一个一个地访问学生的分数 if(maxh-s) max=h-s; h=h-next; /让 h 指向下一个结点,为下一次循环做准备 return max; /把最大的数返回到主函数中 解析 要得到学生的最高分,需要将每一个学生的成绩进行比较。学生的成绩存储在链表中,其结束标志为最后一个结点的 next 指针即 NULL。比较每一个学生的成绩,将最高分返回给主函数。

展开阅读全文
相关资源
猜你喜欢
  • JUS I M1 203-1991 Microprocessor system BUS I 8-bit and 16-bit data Part 3 Mechanical and pin descriptions for the Eurocard configuration with pin and socket (indirect) connectors《.pdf JUS I M1 203-1991 Microprocessor system BUS I 8-bit and 16-bit data Part 3 Mechanical and pin descriptions for the Eurocard configuration with pin and socket (indirect) connectors《.pdf
  • JUS I N0 010-1987 Numerical control of machines Graphical symbols《数控机械 图形符号》.pdf JUS I N0 010-1987 Numerical control of machines Graphical symbols《数控机械 图形符号》.pdf
  • JUS IEC 1039-1994 General classification of insulating liquids《绝缘液体的一般分类》.pdf JUS IEC 1039-1994 General classification of insulating liquids《绝缘液体的一般分类》.pdf
  • JUS IEC 1100-1994 Classification of insulating liquids according to fire-point and net calorific value《根据燃点和净热值对绝缘液体的分类》.pdf JUS IEC 1100-1994 Classification of insulating liquids according to fire-point and net calorific value《根据燃点和净热值对绝缘液体的分类》.pdf
  • JUS IEC 34-8-1994 Rotating electrical machines - Part 8 Terminal marking and direction of rotating machines《旋转电机 第8部分:终端标志和方向》.pdf JUS IEC 34-8-1994 Rotating electrical machines - Part 8 Terminal marking and direction of rotating machines《旋转电机 第8部分:终端标志和方向》.pdf
  • JUS IEC 599-1994 Interpretation of the analysis of gases in transformers and other oil-filled electrical equipment in service《变压器和其它正在使用的油浸电子设备的气体分析的解释》.pdf JUS IEC 599-1994 Interpretation of the analysis of gases in transformers and other oil-filled electrical equipment in service《变压器和其它正在使用的油浸电子设备的气体分析的解释》.pdf
  • JUS IEC 68-2-10-1991 Basic environmental testing procedures Part 2 Test Test J and guidance Mould growth《基本环境试验程序 第二部分:试验方法 J试验和导则:霉菌生长》.pdf JUS IEC 68-2-10-1991 Basic environmental testing procedures Part 2 Test Test J and guidance Mould growth《基本环境试验程序 第二部分:试验方法 J试验和导则:霉菌生长》.pdf
  • JUS IEC 796-2-1991 Microprocessor system bus 8-bit and 16-bit data (MULTIBUS I) Part 2 Mechanical and pin descriptions for the system bus configuration with edge connectors (direct.pdf JUS IEC 796-2-1991 Microprocessor system bus 8-bit and 16-bit data (MULTIBUS I) Part 2 Mechanical and pin descriptions for the system bus configuration with edge connectors (direct.pdf
  • JUS IEC 842-1994 Rotating electrical machines - Guide for application and of turbine-type synchronous machines using hydrogen《旋转电机 旋转电机 用氢作冷却剂的同步涡轮发电机的安装及运行指南 n》.pdf JUS IEC 842-1994 Rotating electrical machines - Guide for application and of turbine-type synchronous machines using hydrogen《旋转电机 旋转电机 用氢作冷却剂的同步涡轮发电机的安装及运行指南 n》.pdf
  • 相关搜索

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

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