【计算机类职业资格】国家二级C语言机试(操作题)模拟试卷336及答案解析.doc

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

1、国家二级 C语言机试(操作题)模拟试卷 336及答案解析(总分:6.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:2.00)1.给定程序的功能是:从键盘输入若干行文本(每行不超过 80个字符),写到文件 myfile4txt 中,用1 作为字符串输入结束的标志。然后将文件的内容读出显示在屏幕上。文件的读写分别由自定义函数ReadText和 WriteText实现。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的 BLANK1C 中。 不得增行或删行,也不得更改程序的结构! #include #include #inclu

2、de void WriteText (FILE *) ; void ReadText (FILE *) ; main () FILE *fp; if (fp=fopen ( “myfile4 txt“,“w“) =NULL) printf(“ open fail! !/n“); exit (0) ; WriteText (fp) ; fclose ( fp) ; if (fp=fopen ( “myfile4 txt“, printf (“ open fail ! ! /n“) ; exit (0) ; ReadText ( fp) : fclose ( fp) ; void WriteTex

3、t(FILE _1_) char strl81l; printf(“/nEnter string with 1 to end :/n“); gets (str) ; while (strcmp (str,“1“) ! =0) fputs (_2_,fw) ; fputs (“/n“,fw) ; gets (str) ; voicl ReadText (FILE *fr) char str 81 ; printf(“/nRead file and output to screen :/n“) ; fgets (str,81,fr) ; while ( ! feof (fr) printf(“s“

4、3_ ); fgets (str,81,fr) ; (分数:2.00)_二、程序修改题(总题数:1,分数:2.00)2.给定程序 MODI1C 中函数 fun的功能是:从低位开始取出长整型变量 s中奇数位上的数,依次构成一个新数放在 t中。高位仍在高位,低位仍在低位。 例如,当 s中的数为:7654321 时,t 中的数为:7531。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 mam函数,不得增行或删行,也不得更改程序的结构! #include void fun (long s long t) long s1=10; *t= s 10; while (s 0) s= s/

5、100; *t= s10 * s1 + *t; s1= s1*100; main () long s,t; printf(“/nPlease enter s:“) f scanf (“1d“,&S) ; printf (“The result is: ld/n“,t) ; (分数:2.00)_三、程序设计题(总题数:1,分数:2.00)3.学生的记录由学号和成绩组成,N 名学生的数据已在主函数中放入结构体数组 s中,请编写函数 fun,它的功能是: 把分数最低的学生数据放在 b所指的数组中。 注意:分数最低的学生可能不止一个,函数返回分数最低的学生的人数。 注意:部分源程序在文件 PROG1C

6、 文件中。 请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。 #include #define N 16 typedef struct char num 10 ; int s; STREC; int fun(STREC *a,STREC *b) main () STREC s N = “GA05“,85, “GA03“,76, “GA02“,69, “GA04“,85, “GA01“,91 , “GA07“,72 , “GA08“,64 , “GA06rr,87 , “GA015“,85, “GA013“,91 , “GA012“,64 , “G

7、A014“,91 , “GA011“,91 , “GA017“,64 , “GA018“,64,“GA016“,72; STREC h N ; int i,n;FILE ;*out ; n=fun (s,h) ; printf (“The d lowest score: /n“,n) ; printf “s 4d/n“,h i num,h i s) ; out=fopen (“outdat“,“w“) ; fprintf (out, “d/n“,n) ; fprintf (out, “4d/n“,hi s) ; fclose (out) ; (分数:2.00)_国家二级 C语言机试(操作题)模

8、拟试卷 336答案解析(总分:6.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:2.00)1.给定程序的功能是:从键盘输入若干行文本(每行不超过 80个字符),写到文件 myfile4txt 中,用1 作为字符串输入结束的标志。然后将文件的内容读出显示在屏幕上。文件的读写分别由自定义函数ReadText和 WriteText实现。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的 BLANK1C 中。 不得增行或删行,也不得更改程序的结构! #include #include #include void WriteText

9、 (FILE *) ; void ReadText (FILE *) ; main () FILE *fp; if (fp=fopen ( “myfile4 txt“,“w“) =NULL) printf(“ open fail! !/n“); exit (0) ; WriteText (fp) ; fclose ( fp) ; if (fp=fopen ( “myfile4 txt“, printf (“ open fail ! ! /n“) ; exit (0) ; ReadText ( fp) : fclose ( fp) ; void WriteText(FILE _1_) char

10、strl81l; printf(“/nEnter string with 1 to end :/n“); gets (str) ; while (strcmp (str,“1“) ! =0) fputs (_2_,fw) ; fputs (“/n“,fw) ; gets (str) ; voicl ReadText (FILE *fr) char str 81 ; printf(“/nRead file and output to screen :/n“) ; fgets (str,81,fr) ; while ( ! feof (fr) printf(“s“,_3_ ); fgets (st

11、r,81,fr) ; (分数:2.00)_正确答案:(正确答案:(1) * fw (2) str (3) str)解析:解析:本题要求是把一段文本写到文件 myfile4txt 中,用1 作为字符串输入结束的标志。然后将文件的内容读出显示在屏幕上。主要考查文件操作以及 uts和 fgets函数的使用。 第一空:此处是补充函数参数名,参数类型已知是 FILE文件指针,“fputs(“/n“,fw)”是将字符“/n”写入文件,可知fw是文件指针名,因此第一空处应该是“voidWriteText(FILE *fw)“。 第二空:“while(strcmp(str,“1“)!=0)”循环的结束标志是

12、str字符串等于“1”时循环退出,如果 str不等于“1”,执行循环体内容:用 futs函数将 str字符串写入文件。futs 函数的调用形式是:“fputs(s,fp)”,其中 s是指向字符串的指针或字符串数组名,fp 是指向将要被写入的文件的文件指针,因此第二处应该是“futs(str,fw)”。 第三空:“while(! feof(fr)”循环的作用是不断读取文件直到到达文件尾,每次最多读 81个,将读到的数据放在 str字符串里,并用 printf输出到屏幕,因此第三处应该是“printf(“s“,str)”。二、程序修改题(总题数:1,分数:2.00)2.给定程序 MODI1C 中函

13、数 fun的功能是:从低位开始取出长整型变量 s中奇数位上的数,依次构成一个新数放在 t中。高位仍在高位,低位仍在低位。 例如,当 s中的数为:7654321 时,t 中的数为:7531。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动 mam函数,不得增行或删行,也不得更改程序的结构! #include void fun (long s long t) long s1=10; *t= s 10; while (s 0) s= s/100; *t= s10 * s1 + *t; s1= s1*100; main () long s,t; printf(“/nPlease enter

14、 s:“) f scanf (“1d“,&S) ; printf (“The result is: ld/n“,t) ; (分数:2.00)_正确答案:(正确答案:(1) void fun (long s,long *t) (2) s1=sl*10;)解析:解析:本题中函数的功能是依次取出奇数位上的数。该题的解题思路主要是找出数字中的奇数位上的数。 (1)根据“*t=s10”判断,t 应该是个指针变量,所以“void fun (long s,long t)”语句中的 t只需改为“void fun (long s,long *t)”。 (2)分析函数内的循环过程可知 sl的用途是每次将*t扩大,

15、记录每次得到的奇数位的数字的权值,sl 的权值每次增加 1位,因此第二个标识下应该是“sl=sl*10; ”。三、程序设计题(总题数:1,分数:2.00)3.学生的记录由学号和成绩组成,N 名学生的数据已在主函数中放入结构体数组 s中,请编写函数 fun,它的功能是: 把分数最低的学生数据放在 b所指的数组中。 注意:分数最低的学生可能不止一个,函数返回分数最低的学生的人数。 注意:部分源程序在文件 PROG1C 文件中。 请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。 #include #define N 16 typedef struct

16、char num 10 ; int s; STREC; int fun(STREC *a,STREC *b) main () STREC s N = “GA05“,85, “GA03“,76, “GA02“,69, “GA04“,85, “GA01“,91 , “GA07“,72 , “GA08“,64 , “GA06rr,87 , “GA015“,85, “GA013“,91 , “GA012“,64 , “GA014“,91 , “GA011“,91 , “GA017“,64 , “GA018“,64,“GA016“,72; STREC h N ; int i,n;FILE ;*out ;

17、 n=fun (s,h) ; printf (“The d lowest score: /n“,n) ; printf “s 4d/n“,h i num,h i s) ; out=fopen (“outdat“,“w“) ; fprintf (out, “d/n“,n) ; fprintf (out, “4d/n“,hi s) ; fclose (out) ; (分数:2.00)_正确答案:(正确答案:1 int i, j=0, min=a 0 s; 2 for(i=0; iai,s) 4 j=0; bj+=ai;min=ais; 5 6 lelse if (min=a i s) 7 bj+2ai; 8 9 return j;)解析:解析:该程序功能是把分数最低的学生数据放在 b所指的数组中。本题是关于求解结构体中某些成员的最小值,首先将第一个值设定为最小值,并在循环中将其他所有值与该值进行比较,求得最小值。然后将最小值与所有值进行比较,求得所有的最小值。 (1)要把最低分数的学生数据放在数组中,首先求出最低分数,再使用一个 for循环把所有的成绩进行比较,找出最低的分数来。 (2)找出所有与最低分数相等的学生,并将最低分数的人数累加。

展开阅读全文
相关资源
猜你喜欢
  • BS 3424-34-1992 Testing coated fabrics - Method 37 - Method for determination of water vapour permeability index (WVPI)《涂覆织物试验方法 第34部分 方法37 水蒸气渗透系数 (WVPI)测定方法》.pdf BS 3424-34-1992 Testing coated fabrics - Method 37 - Method for determination of water vapour permeability index (WVPI)《涂覆织物试验方法 第34部分 方法37 水蒸气渗透系数 (WVPI)测定方法》.pdf
  • BS 3424-36-1993 Testing coated fabrics - Method 39 - Method for determination of the dimensional stability of coated fabrics to domestic washing《涂覆织物试验 第36部分 方法39 家用涂覆织物耐洗涤尺寸稳定性测定方.pdf BS 3424-36-1993 Testing coated fabrics - Method 39 - Method for determination of the dimensional stability of coated fabrics to domestic washing《涂覆织物试验 第36部分 方法39 家用涂覆织物耐洗涤尺寸稳定性测定方.pdf
  • BS 3424-38-1998 Testing coated fabrics - Determination of wounded burst strength《涂覆织物试验 第38部分 破损碎裂强度测定》.pdf BS 3424-38-1998 Testing coated fabrics - Determination of wounded burst strength《涂覆织物试验 第38部分 破损碎裂强度测定》.pdf
  • BS 3445-1-1992 Agricultural water troughs and water fittings - Specification for water trough bodies service boxes and water supply system《牲畜饮水槽和配件 第1部分 水槽体 水箱和供水系统规范》.pdf BS 3445-1-1992 Agricultural water troughs and water fittings - Specification for water trough bodies service boxes and water supply system《牲畜饮水槽和配件 第1部分 水槽体 水箱和供水系统规范》.pdf
  • BS 3445-2-1992 Agricultural water troughs and water fittings - Code of practice for installation and operation《牲畜饮水槽和配件 第2部分 成套设备和操作惯例》.pdf BS 3445-2-1992 Agricultural water troughs and water fittings - Code of practice for installation and operation《牲畜饮水槽和配件 第2部分 成套设备和操作惯例》.pdf
  • BS 3446-1-1990 Glossary of terms associated with refractory materials - General and manufacturing《耐火材料术语 第1部分 通用和生产制造》.pdf BS 3446-1-1990 Glossary of terms associated with refractory materials - General and manufacturing《耐火材料术语 第1部分 通用和生产制造》.pdf
  • BS 3446-2-1990 Glossary of terms associated with refractory materials - Applications in the coke glass cement and other non-metallurgical industries《耐火材料术语 第2部分 焦碳、玻璃、 水泥和其它非冶金工业第2.pdf BS 3446-2-1990 Glossary of terms associated with refractory materials - Applications in the coke glass cement and other non-metallurgical industries《耐火材料术语 第2部分 焦碳、玻璃、 水泥和其它非冶金工业第2.pdf
  • BS 3446-3-1990 Glossary of terms associated with refractory materials - Applications in the metallurgical industries《耐火材料术语 第3部分 冶金工业用术语》.pdf BS 3446-3-1990 Glossary of terms associated with refractory materials - Applications in the metallurgical industries《耐火材料术语 第3部分 冶金工业用术语》.pdf
  • BS 3447-1962 Glossary of terms used in the glass industry《玻璃工业用术语词汇》.pdf BS 3447-1962 Glossary of terms used in the glass industry《玻璃工业用术语词汇》.pdf
  • 相关搜索

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

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