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

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

1、二级 C 语言机试 95 及答案解析(总分:100.00,做题时间:90 分钟)一、B填空题/B(总题数:1,分数:30.00)1.请补充 main 函数,该函数的功能是:从键盘输入只有两个整数参与运算的一个四则运算式,然后计算出它的值。注意数字全部为正整数。 例如,输入 308*28,结果为 8624.000000。 注意:部分源程序给出如下。 请勿改动主函数 main 和其他函数中的任何内容,仅在 main 函数的横线上填入所编写的若干表达式或语句。 试题程序: # includestdio, h main ( ) int a=0, b=0, flag=l, fg=l; float res

2、ult; char *p, ch; char str10; clrscr (); printf(“/n Input a string /n“); gets (str); p=str; while (*p) if (*p=0 else if (fg) ch=*p; flag=2; fg=0; if (*p=0 p+; switch(U 【3】 /U) case +: result=a+b;break; case -: result=a-b;break; case * :result=a*b;break; case / :result= (float) a/b;break; printf (“/n

3、result=%f“, result); (分数:30.00)填空项 1:_二、B改错题/B(总题数:1,分数:30.00)2.下列给定程序中,函数 fun()的功能是:传入一个整数 m,计算如下公式的值。 t=1/2-1/3-1/m 例如,若输入 5,则应输出-0.283333。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动main 函数,不得增行或删行,也不得更改程序的结构。 试题程序: #include conio.h #include stdio.h double fun(int m) double t=l.0; int i; for (i=2; i=m; i+) /*f

4、ound*/ t=l.0-1/i; /*found*/ main ( ) int m; clrscr (); printf (“/nPlease enter 1 integer numbers : In“); scanf (“%d“, printf(“/n/nThe result is %lfln“, fun (m); (分数:30.00)填空项 1:_三、B编程题/B(总题数:1,分数:40.00)3.学生的记录由学号和成绩组成,N 名学生的数据已在主函数中放入结构体数组 s 中,请编写函数 fun(),它的功能是:函数返回指定学号的学生数据,指定的序号在主函数中输入。若没找到指定的学号,在

5、结构体变量中给学号置空串,给成绩置-1,作为函数值返回(用于字符串比较的函数是 strcmp)。 注意: 部分源程序给出如下。 请勿改动主函数 main 和其他函数中的任何内容,仅在函数 fun 的花括号中填入所编写的若干语句。 试题程序: #includestdio. h #inctudestdlib. h #define N 16 typedef struct char num10; int s; STREC; STREC fun(STREC *a, char *b) main ( ) STREC s N= “GA005“, 85, “GA003“, 76, “GA002“, 69 , “

6、GA004“, 85 , “GA001“, 91 , “GA007“, 72 , “GA008“, 64 , “GA006“, 87 , “GA015“, 85 , “GA013“, 91 , “GA012“, 64 , “GA014“, 91 , “GA011“, 77 , “GA017“, 64 , “GA018“, 64 , “GA016“, 72 ; STREC h; char re10; int i, n; FILE *out; printf (“The original data: /n“); for (i=0; iN; i+) if (i%4=0) printf (“In“);

7、/*每行输出 4 个学生记录*/ printf(“%s %3d“ ,si num, si s); printf(“/n/nEnter the number: “); gets (m); h=fun (s,m); printf (“The data: “); printf(“/n%s %4d/n“,h.num, h.s); printf (“/n“); out=fopen (“out80. dat“, “w“); h=fun (s, “GA013“); fprintf(out, “%s %4d/n“,h.num, h.s); fclose (out); (分数:40.00)_二级 C 语言机试

8、95 答案解析(总分:100.00,做题时间:90 分钟)一、B填空题/B(总题数:1,分数:30.00)1.请补充 main 函数,该函数的功能是:从键盘输入只有两个整数参与运算的一个四则运算式,然后计算出它的值。注意数字全部为正整数。 例如,输入 308*28,结果为 8624.000000。 注意:部分源程序给出如下。 请勿改动主函数 main 和其他函数中的任何内容,仅在 main 函数的横线上填入所编写的若干表达式或语句。 试题程序: # includestdio, h main ( ) int a=0, b=0, flag=l, fg=l; float result; char *

9、p, ch; char str10; clrscr (); printf(“/n Input a string /n“); gets (str); p=str; while (*p) if (*p=0 else if (fg) ch=*p; flag=2; fg=0; if (*p=0 p+; switch(U 【3】 /U) case +: result=a+b;break; case -: result=a-b;break; case * :result=a*b;break; case / :result= (float) a/b;break; printf (“/nresult=%f“,

10、 result); (分数:30.00)填空项 1:_ (正确答案:a*l0+*p-0 (2)b*10+*p-0 (3)ch)解析:解析 填空 1:变量 a 用来保存第一个整数,*p-0 得到指针 p 所指的数字字符的对应数字。填空 2:同理,变量 b 用来保存第二个整数。填空 3:字符 ch 中保存的是四则运算符,而 switch 语句中case 后面的常量表达式都是运算符,所以为了能够匹配,switch 后面括号中的表达式应该为 ch。二、B改错题/B(总题数:1,分数:30.00)2.下列给定程序中,函数 fun()的功能是:传入一个整数 m,计算如下公式的值。 t=1/2-1/3-1/

11、m 例如,若输入 5,则应输出-0.283333。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动main 函数,不得增行或删行,也不得更改程序的结构。 试题程序: #include conio.h #include stdio.h double fun(int m) double t=l.0; int i; for (i=2; i=m; i+) /*found*/ t=l.0-1/i; /*found*/ main ( ) int m; clrscr (); printf (“/nPlease enter 1 integer numbers : In“); scanf (“%d“

12、, printf(“/n/nThe result is %lfln“, fun (m); (分数:30.00)填空项 1:_ (正确答案:错误:t=10-1/i; 正确:t-=1.0/i;)解析:(2)错误: ; 正确:return t; 解析 解答类似题目的思路是我们依然先从数学思路着手,即理解数学上的规律,再分析 C 语言的流程,本题中分母依等差数列递增,最好用循环语句解决。我们先从第 1 句 1/2 的表达式来看起:当 i 从 2(必须从 2 开始)开始循环的时候,虽然 t=10-1/i;和 t-=10/i;的第 1 个值都是相同的,但随着循环的累加,我们就能发现问题所在了!三、B编程题

13、/B(总题数:1,分数:40.00)3.学生的记录由学号和成绩组成,N 名学生的数据已在主函数中放入结构体数组 s 中,请编写函数 fun(),它的功能是:函数返回指定学号的学生数据,指定的序号在主函数中输入。若没找到指定的学号,在结构体变量中给学号置空串,给成绩置-1,作为函数值返回(用于字符串比较的函数是 strcmp)。 注意: 部分源程序给出如下。 请勿改动主函数 main 和其他函数中的任何内容,仅在函数 fun 的花括号中填入所编写的若干语句。 试题程序: #includestdio. h #inctudestdlib. h #define N 16 typedef struct

14、char num10; int s; STREC; STREC fun(STREC *a, char *b) main ( ) STREC s N= “GA005“, 85, “GA003“, 76, “GA002“, 69 , “GA004“, 85 , “GA001“, 91 , “GA007“, 72 , “GA008“, 64 , “GA006“, 87 , “GA015“, 85 , “GA013“, 91 , “GA012“, 64 , “GA014“, 91 , “GA011“, 77 , “GA017“, 64 , “GA018“, 64 , “GA016“, 72 ; STR

15、EC h; char re10; int i, n; FILE *out; printf (“The original data: /n“); for (i=0; iN; i+) if (i%4=0) printf (“In“); /*每行输出 4 个学生记录*/ printf(“%s %3d“ ,si num, si s); printf(“/n/nEnter the number: “); gets (m); h=fun (s,m); printf (“The data: “); printf(“/n%s %4d/n“,h.num, h.s); printf (“/n“); out=fop

16、en (“out80. dat“, “w“); h=fun (s, “GA013“); fprintf(out, “%s %4d/n“,h.num, h.s); fclose (out); (分数:40.00)_正确答案:()解析:STREC fun(STREC *a, char *b) int i; STREC str=“/0“,-1; /*若没找到掼定的学号,在结构体变量中给学号置空串,给成绩置-1*/ for (i=0; iN; i+) if (strcmp (a i .num, b)=0) /*找到指定学号的学生数据*/ str=a i; return str; /*返回学生记录* / 解析 本程序一开始先使结构体变量 str 的学号为空串,成绩为-1。题中循环体的功能是搜索所有学生的学号并判断是否有学号与b 所指字符串相同的(即找到),若找到则给 str 重新赋值(str=ai),若没找到则 str 成员的值还是原有值(即未找到时学号返回空串,成绩返回-1)。 题中已经给出字符串的比较只能用 strcmp()函数,而不能直接进行比较,我们在改错题分析中已经详细讲述了字符串操作函数,如 strcmp(),strcat(),strcpy()和strlen()等,希望学习者能熟练掌握。

展开阅读全文
相关资源
猜你喜欢
  • EN ISO 11909-2007 en Binders for Paints and Varnishes - Polyisocyanate Resins - General Methods of Test《色漆和清漆用粘合剂 聚亚安酯树脂 通用试验方法[已取消 BSI BS EN ISO 11909 BSI BS EN ISO 11909]》.pdf EN ISO 11909-2007 en Binders for Paints and Varnishes - Polyisocyanate Resins - General Methods of Test《色漆和清漆用粘合剂 聚亚安酯树脂 通用试验方法[已取消 BSI BS EN ISO 11909 BSI BS EN ISO 11909]》.pdf
  • EN ISO 11925-2-2010 en Reaction to fire tests - Ignitability of products subjected to direct impingement of flame - Part 2 Single-flame source test (Incorporating corrigendum Janua.pdf EN ISO 11925-2-2010 en Reaction to fire tests - Ignitability of products subjected to direct impingement of flame - Part 2 Single-flame source test (Incorporating corrigendum Janua.pdf
  • EN ISO 11930-2012 en Cosmetics - Microbiology - Evaluation of the antimicrobial protection of a cosmetic product《化妆品 微生物 一款化妆品抗微生物保护作用的评定》.pdf EN ISO 11930-2012 en Cosmetics - Microbiology - Evaluation of the antimicrobial protection of a cosmetic product《化妆品 微生物 一款化妆品抗微生物保护作用的评定》.pdf
  • EN ISO 11953-2010 en Dentistry - Implants - Clinical performance of hand torque instruments《牙科 植入物 手持转矩仪器的临床性能》.pdf EN ISO 11953-2010 en Dentistry - Implants - Clinical performance of hand torque instruments《牙科 植入物 手持转矩仪器的临床性能》.pdf
  • EN ISO 11957-2009 en Acoustics - Determination of sound insulation performance of cabins - Laboratory and in situ measurements《声学 隔音间隔音性能测定 实验室和现场测量》.pdf EN ISO 11957-2009 en Acoustics - Determination of sound insulation performance of cabins - Laboratory and in situ measurements《声学 隔音间隔音性能测定 实验室和现场测量》.pdf
  • EN ISO 11960-2014 en Petroleum and natural gas industries - Steel pipes for use as casing or tubing for wells《石油天然气工业 油气井套管或油管用钢管(ISO 11960 2014)》.pdf EN ISO 11960-2014 en Petroleum and natural gas industries - Steel pipes for use as casing or tubing for wells《石油天然气工业 油气井套管或油管用钢管(ISO 11960 2014)》.pdf
  • EN ISO 11961-2008 en Petroleum and natural gas industries - Steel drill pipe《石油和天然气工业 钻采钢管》.pdf EN ISO 11961-2008 en Petroleum and natural gas industries - Steel drill pipe《石油和天然气工业 钻采钢管》.pdf
  • EN ISO 11963-2012 en Plastics - Polycarbonate sheets - Types dimensions and characteristics《塑料-聚碳酸酯表类型 尺寸和特征》.pdf EN ISO 11963-2012 en Plastics - Polycarbonate sheets - Types dimensions and characteristics《塑料-聚碳酸酯表类型 尺寸和特征》.pdf
  • EN ISO 11969-1996 en Water Quality - Determination of Arsenic - Atomic Absorption Spectrometric Method (Hydride Technique)《水质 砷的测定 原子吸收光谱法(氢化物技术)(ISO 11969-1996)》.pdf EN ISO 11969-1996 en Water Quality - Determination of Arsenic - Atomic Absorption Spectrometric Method (Hydride Technique)《水质 砷的测定 原子吸收光谱法(氢化物技术)(ISO 11969-1996)》.pdf
  • 相关搜索

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

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