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

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

1、国家二级( C语言)机试模拟试卷 257及答案与解析 一、程序填空题( 30分) 1 程序通过定义学生结构体数组,存储了若干名学生的学号、姓名和 3门课的成绩。函数 fun的功能是将存放学生数据的结构体数组,按照姓名的字典序 (从小到大 )排序。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的 BLANKl C中。 不得增行或删行,也不得更改程序的结构 ! #include #include struct student long sno; char name10; float score3; ; void fun(struct stu

2、dent a, int n) /*found*/ 【 1】 t; int i, j; /*found*/ for (i=0; i 0) t = ai; ai = aj; aj = t; main() struct student s4=10001,“ZhangSan“, 95, 80, 88,10002,“LiSi“, 85, 70, 78,10003,“CaoKai“, 75, 60, 88, 10004,“FangFang“, 90, 82, 87; int i, j; printf(“nnThe original data :nn“); for (j=0; j #include #inc

3、lude #include /*found* int proc(char * str, char * t1, char * t2, char * w) char * p, *r, *a; strcpy(w, str); while(*w) p=w; r=t1; /*found*。 while(r) if(*r=*p)r+; p+; else break; if(*r=0) =w; r=t2; /*found* while(*r)*a=*r; a+; r+ w+=strlen(t2); else w+; void main() char str100, tl100, t2E100, w100;

4、system(”CLS”); printf(” nPlease enter string str: ”); scanf(” S”, str); printf(” nPlease enter substring tl: ”); scanf(” S”, t1); printf(” nPlease enter substring t2: ”); scanf(”9 6S”, t2); if(strlen(t1)=一 strlen(t2) proc(str, tl, t2, w); printf(“ nThe result is: s n”, w); else printf(Error: strlen(

5、t2) n“); 三、程序设计题( 40分) 3 函数 fum的功能是:将 s所指字符串中 ASC 值为偶数的字符删除,串中剩余字符形成一个新串放在 t所指的数组中。 例如,若 s所指字符串中的内容为: ”ABCDEFGl2345“,其中字符 B的 ASC 码值为偶数、 、字符 2的 ASC 码值为偶数、 都应当删除,其他依此类推。最后 t所指的数组中的内容应是: ”ACEGl35”。 注意:部分源程序存在文件 PROGl C中。 请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。 #include #include void fun(char *

6、s, char t) main() char s100, t100; printf(“nPlease enter string S:“); scanf(“%s“, s); fun(s, t); printf(“nThe result is: %sn“, t); NONO(); NONO () /* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */ char s100, t100 ; FILE *rf, *wf ; int i ; rf = fopen(“in.dat“,“r“); wf = fopen(“out.dat“,“w“); for(i = 0 ; i 0)”是比较两

7、个姓名的大小,由审题分析可知,如果ai.name大于 aj.name,那么需要交换,故第三空处为 “ai.name,aj.name”。 二、程序修改题( 30分) 2 【正确答案】 (1)错误: int proc(char * str, char * t1, char * t2, char * w) 正确: void proc(char * str, char * t1, char * t2, char * w) (2)错误: while(r) 正确: while(* r) (3)错误: r+ 正确: r+; 【试题解析】 由主函数中 proe()函数的调用以及 proc()函数的定义,可知该

8、函数没有返回值,因此把 proc()前的 “int”改为 “void”;由 proc()函数可知,变量 r指向的是字符串 t1地址, while循 环要判断的是字符串 t1是否结束,因此, “while(r)”应改为 while(*r); C语言中,每一条语句都以分号结束,因此, r+后要加上分号。 三、程序设计题( 40分) 3 【正确答案】 int i, j=0; for(i=0; istrlen(s); i+) if(si%2) tj+=si; tj=0; 【试题解析】 ( 1)判断一个字符串中的某一字符 ASCII值是否为奇数,可用“stri%2!=0” 来判断。 ( 2)对串 s中各个字符逐个进行考查, ASCII值为奇数的字符就顺序放在新串 t中,否则就不存放。 ( 3)所有字符处理完后,记得在新串 s的末尾加上结束符 “0”。

展开阅读全文
相关资源
猜你喜欢
  • 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