[计算机类试卷]国家二级C语言机试(操作题)模拟试卷437及答案与解析.doc

上传人:terrorscript155 文档编号:498387 上传时间:2018-11-28 格式:DOC 页数:7 大小:33.50KB
下载 相关 举报
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷437及答案与解析.doc_第1页
第1页 / 共7页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷437及答案与解析.doc_第2页
第2页 / 共7页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷437及答案与解析.doc_第3页
第3页 / 共7页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷437及答案与解析.doc_第4页
第4页 / 共7页
[计算机类试卷]国家二级C语言机试(操作题)模拟试卷437及答案与解析.doc_第5页
第5页 / 共7页
点击查看更多>>
资源描述

1、国家二级 C语言机试(操作题)模拟试卷 437及答案与解析 一、程序填空题 1 程序通过定义学生结构体变量,存储了学生的学号、姓名和三门课的成绩。所有学生数据均以二进制方式输出到文件中。函数 fun的功能是从形参 filename所指的文件中读入学生数据,并按照学号从小到大排序后,再用二进制方式把排序后的学生数据输出到 filename所指的文件中,覆盖原来的文件内容。 请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。 注意:部分源程序在文件 BLANK1 C中。 不 得增行或删行,也不得更改程序的结构! 试题程序: #include stdio h #define N

2、5 typedef struct student long sno; char name 10 ; float score3 ; STU; void fun (char * filename) FILE *fp; int i, j; STU sN, t; /*found*/ fp = fopen (filename,【 1】 ) ; fread (s, sizeof (STU) , Nf fp) ; fclose ( fp) ; for (i=0; i N 一 1; 1+) for (j 一 i+l; j N; j +) /*found*/ if (si sno 【 2】 sj sno) fp

3、 = fopen(filename, “wb“); /*found*/ 【 3】 (s, sizeof (STU) , N, fp) ; fclose ( fp) ; main () STU t N = 10005,“ ZhangSan“,95, 80, 88 , 10003,“LiSi“, 85, 70,78 , 10002, “CaoKai“,75, 60, 88 , 10004 f “FangFang“, 90, 82, 87 J,10001,“MaChao“, 91, 92, 77 , ssN; int i,j; FILE * fp; fp = fopen (“student dat“

4、 “wb“) ; fwrite (t, sizeof (STU) , 5, fp) ; fclose ( fp) ; printf (“nnThe original data :nn“); printf (“nNo: ld Name: 一 8sscores: “,tj sno, tj name); for(i=0; i 3 ; i+) printf (“ 6 2f “, tj scorei ) ; printf (“n“) ; fun (“student dat“) ; printf ( “ n nThe data after sorting :nn“) ; fp = fopen(“stud

5、ent dat“, “rb“); fread (ss, sizeof (STU) , 5, fp) ; fclose ( fp) ; for(j=0; j N; j+) printf (“nNo: ld Name: 一 8s Scores : “,ssj sno, ssj name) ; for( i=0; i 3, i+) printf (“ 6 2f “, ssj scorei ) ; printf (“n“) : 二、程序修改题 2 下列给定程序中函数 fun的功能是:在字符串的最前端加入 n个 *号,形成新串,并且覆盖原串。 字 符串的长度最长允许为 79。 请改正程序中的错误,使它能

6、得出正确的结果。 注意:部分源程序在文件 MODI1 C中,不要改动 main函数,不得增行或删行,也不得更改程序的结构! 试题程序: #include stdio h #include string h void fun ( char s, int n ) char a80, *p; int i; /*found*/ s=p; for(i=0; i n; i+)ai=*; do ai=*p; i + ; /*found*/ while ( *p + ) strcpy (s,a) ; main () int n; char s80; printf (“nEnter a string : “)

7、 gets (s) ; printf (“nThe string “ sVn“,s) ; printf (“nEnter n (number of*):“); fun (s,n) ; printf (“nThe string after insert: “ s“n“, s); 三、程序设计题 3 请编写函数 fun,该函数的功能是: 统计各年龄段的人数。 N个年龄通过调用随机函数获得,并放入主函数的 age数组中。要求函数把 0一 9岁年龄段的人数放在 d0中,把 10 N19岁年龄段的人数放在 d1中,把 20一 29岁年龄段的人数放在 d2中,依此类推,把 100岁(含 100岁)以上年

8、龄的人数都放在 d10中。结果在主函数中输出。 注意:部分源程序在文件 PROG1 C中。 请勿改动 main函数和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。 试题程序: #include stdio h # define N 50 # de fine,M 11 void fun (int *a, int *b) double rnd () static t =29,c =217,m =1024,r =0; return (double) r/m) ,* void main ( ) FILE * wf, int ageN, i,dM ; int bN = 32,45

9、15,12,86,49, 97,3,44,52,17,95,63 ; agei = (int) (115 * rnd (); printf (“The original data :n“) ; 4d“,agei) ; / *每行输出 10个数 */ printf ( “nn“) ; fun (age,d) ; for (1 =0; i 10; 1+) printf (“ 4d 一一一 4d : 4dn“, i*l0, 1*10 +9,di) ; printf (“Over 100 : 4dn“,d10); /*/ wf = fopen (“out dat“,“w“) ; fun (b,d)

10、 for (i=0; 1 10; 1+) fprintf (wf,“ 4d o04d : 4dn“, i fprintf (wf,“Over 100 : 4d“,d10 ) ; fclose (wf) ; /*/ 国家二级 C语言机试(操作题)模拟试卷 437答案与解析 一、程序填空题 1 【正确答案】 (1)“rb“ (2) (3)fwrite 【试题解析】 填空 1:题目中要求从形参 filename所指的文件中读入学生的数据,以此可以看出本空应该填写 ”rb”。 填空 2:此处的 if语句是比较学号的大小,如果学号大就和学号小的换位,以此本空填写 。 填空 3:题目要求所有的学生数据均

11、以二进制方式输出到文件中,因此本空填写fwrite。 二、程序修改题 2 【正确答案】 (1)p=s; (2)while( *p+); 【试题解析】 (1)指针 p应指向 s,所以应改为 p=s;。 (2)循环等待,当 while循环执行一次,临时变量 p应该指向字符串的下一位置,所以应改为 while(*p+);。 三、程序设计题 3 【正 确答案】 void fun (int* a, int *b) int i, j; for(j=0; j M; j+) bj=0; /*数组 b初始化为 0*/ for(i=0; i N; i+) if (ai =100) b1 0+; /*如果年龄大于等

12、于 100,b10自增 1*/ else bai/10+; /*如果年龄小于 100,则将其分别统计到 bai/ 10中 */ 【试题解析】 本题是一个分段函数的问题,用两个循环来完成。第 1个循环的作用是使 b中的所有元 素值都为 0。这个循环不能省略,因为若未对 b中的元素赋初值,则它们的值是不可预测的。第 2个循环的作用是分别统计 a中各年龄段的人数。当 ai100时,按题意要将其统计到 b10中。 else的作用是如果年龄小于100,则将其分别统计到 bai/10中。 由运算优先级可知先进行 ai/10的运算,所得结果作为 b的下标。若 ai为 0 9时, ai/10的值为 0,且 0 9岁的人数正好要存入 b0中。若 ai为 10一 19时,ai/10的值为 1,且 10一 19岁的人数正好要存入 b1中,依此类推。

展开阅读全文
相关资源
猜你喜欢
  • BS PD IEC TS 62763-2013_5284 Pilot function through a control pilot circuit using PWM (pulse width modulation) and a control pilot wire《通过控制导向线使用PWM (脉冲宽度调制) 的导向功能和控制导向线》.pdf BS PD IEC TS 62763-2013_5284 Pilot function through a control pilot circuit using PWM (pulse width modulation) and a control pilot wire《通过控制导向线使用PWM (脉冲宽度调制) 的导向功能和控制导向线》.pdf
  • BS ISO 8070-2007 Milk and milk products - Determination of calcium sodium potassium and magnesium contents - Atomic absorption spectrometric method《牛奶和奶制品 钙、钠、钾和镁含量的测定 原子吸.pdf BS ISO 8070-2007 Milk and milk products - Determination of calcium sodium potassium and magnesium contents - Atomic absorption spectrometric method《牛奶和奶制品 钙、钠、钾和镁含量的测定 原子吸.pdf
  • BS ISO 8082-1-2009 Self-propelled machinery for forestry - Laboratory tests and performance requirements for roll-over protective structures - General machines《林业用自推进机械 防倾.pdf BS ISO 8082-1-2009 Self-propelled machinery for forestry - Laboratory tests and performance requirements for roll-over protective structures - General machines《林业用自推进机械 防倾.pdf
  • BS ISO 8082-2-2011 Self-propelled machinery for forestry Laboratory tests and performance requirements for roll-over protective structures Machines having a rotating platf.pdf BS ISO 8082-2-2011 Self-propelled machinery for forestry Laboratory tests and performance requirements for roll-over protective structures Machines having a rotating platf.pdf
  • BS ISO 8083-2006 Machinery for forestry - Falling-object protective structures (FOPS) - Laboratory tests and performance requirements《林业机械 落体防护装置(FOPS) 实验室试验和性能要求》.pdf BS ISO 8083-2006 Machinery for forestry - Falling-object protective structures (FOPS) - Laboratory tests and performance requirements《林业机械 落体防护装置(FOPS) 实验室试验和性能要求》.pdf
  • BS ISO 8086-2004 Dairy plant - Hygiene conditions - General guidance on inspection and sampling procedures《乳品厂 卫生条件 检验和取样程序通用指南》.pdf BS ISO 8086-2004 Dairy plant - Hygiene conditions - General guidance on inspection and sampling procedures《乳品厂 卫生条件 检验和取样程序通用指南》.pdf
  • BS ISO 8096-2005 Rubber- or plastics-coated fabrics for water resistant clothing - Specification《雨衣用橡胶或塑料涂覆织物 规范》.pdf BS ISO 8096-2005 Rubber- or plastics-coated fabrics for water resistant clothing - Specification《雨衣用橡胶或塑料涂覆织物 规范》.pdf
  • BS ISO 8097-2001 Aircraft Minimum airworthiness requirements and test conditions for certified air cargo unit load devices《航空器 经认证的航空货运集装单元装置最低适航性要求和试验条件》.pdf BS ISO 8097-2001 Aircraft Minimum airworthiness requirements and test conditions for certified air cargo unit load devices《航空器 经认证的航空货运集装单元装置最低适航性要求和试验条件》.pdf
  • BS ISO 8114-1993 Textile machinery and accessories - Spindles for ring-spinning and doubling machines - List of equivalent terms《纺织机械和附件 环锭纺纱机和并线机用锭子 同义术语表》.pdf BS ISO 8114-1993 Textile machinery and accessories - Spindles for ring-spinning and doubling machines - List of equivalent terms《纺织机械和附件 环锭纺纱机和并线机用锭子 同义术语表》.pdf
  • 相关搜索

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

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