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

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

1、国家二级 C语言机试(操作题)模拟试卷 85及答案与解析 一、程序填空题 1 函数 fun的功能是:逆置数组元素中的值。例如:若 a所指数组中的数据依次为: 1、 2、 3、 4、 5、 6、 7、 8、 9,则逆置后依次为: 9、 8、 7、 6、 5、 4、 3、 2、1。形参 n给出数组中数据的个数。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的 BLANK1 C中。 不得增行或删行,也不得更改程序的结构 ! #include void fun(int a, int n) int i, t; /*found*/ for(2=0;

2、 i #include #include int fun(char*p) int n; /*found*/ n=*p一 o; p+; while(*P!=0) /*found*/ n=n*8+*p一 o; p+; return n; main() char s6; int i; 2nL n; printf(“Enter a string(ocatal digits): “); gets(s); if(strlen(s)5)printf(“Error: String too longer!nn“); exit(0); ) for(i=0; si; i+) if(si7) print; f(“Er

3、ror: c not is ocatal digits!nn“, si); exit: (0); ) print; f(“The original string: “); puts(s); n=fun(s); printf(“n s is convered to integer number: dnn“, s, n); 三、程序设计题 3 学生的记录由学号和成绩组成, N名学生的数据已在主函数中放入结构体数组 s中,请编写函数 fun,它的功能是:函数返回指定学号的学生数据,指定的学号在主函数中输入。若没找到指定学号,在结构体变量中给学号置空串,给成绩置 -1,作为函数值返回。 (用于字符串比

4、较的函数是 strcmp)。 注意:部分源程序在文件 PROG1 C中。 请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。 #include #include #define N 1 6 typedef struct char num10; int s; STREC ; STREC fun(STREC*a, char*b) main() STREC sN=“GA005“, 85, “GA003“, 76, “GA002“, 69), “GA004“, 85), “GA001“, 91), “GA007“, 72), “GA008“, 64, “G

5、A006“, 87, “GA015“, 85), “GA013“, 91, “GA012“, 64), “GA014“, 91), “GA011“, 77), “GA017“, 64), “GA018“, 64), “GA016“, 72); STREC h; char m10; int i; FTLE*out; printf(“tThe original data: n“); for(i=0; iNj i+) if(i 4=0)printf(“n“); printf(“ s 3d“, si num, si s); printf(“nnEnter the number: “); gets(m)

6、; h=fun(s, m); printf(“The data: “); printf(“n s 4dn“, in num, h s); printf(“n“); out=fopen(“out; dat“, “w“); h=fun(s, “GA013“); fprintf(out, “ s 4dn“, h num, h s); fclose(out); 国家二级 C语言机试(操作题)模拟试卷 85答案与解析 一、程序填空题 1 【正确答案】 (1)n/2 (2)I (3)an i 1 【试题解析】 函数 fun的功能是将数组中的元素倒置。 第一空:由审题分析可知,总共交换 n/2次,故循环的终

7、止条件为 i等于 n/2,故第一空处应为 “n/2”。 第二空: a0和 an-1交换, a1和 an-2交换 ,因此 ai和 an-i-1交换,故第二空处应为 “i”。 第三空: “t=ai; ai: an-1-i; ”所以第三空处是把 t值赋值 an-1-i,故第三空处应为 “an-1i”。 二、程序修改题 2 【正确答案】 (1)n=*p一 0; (2)n=n*8+*p一 0; 【试题解析】 函数功能是实现八进制到十进制的转换。 (1)第一个标识下面:语句 “n=*p-o; ”中的 o不是数字零,而是字母 0,根据前面的分析因此改为: “n=*p-o; ”。 (2)第二个标识下面:语句

8、“n=n*8+*p-o”,首先进行同 (1)相同的修改,变量 P没有定义,根据题意要求这里应该是 “*p-o”,所以此句改为: “n=n*8+*p-o; ”。 三、程序设计题 3 【正确答案】 STREC c; int i; c num0=0; /*置初始空串 */ c s=一 1; /*置成绩为一 1*/ for(i=0; iN; i+) if(strcmp(ai num, b)=0)/*判断学号是否相等 */ strcpy(c num, ai num); /*相等,则对学号进行赋值 */ c s=ai s; /*相等,则对成绩进行赋值 */ break; /*退出循环体。 / return c; /*返回结构体变量 */ 【试题解析】 该程序功能是函数返回指定学号的学生数据,指定的学号在主函数中输入。解题思路是在循环过程中,使用 if判断表达式,将输入的学号与所有的学号进行比较,如果找到该学号,将其赋值到指定变量,否则将空格赋值到指定变量,表明没有查找到该学号。

展开阅读全文
相关资源
猜你喜欢
  • ANSI UL 561-2011 UL Standard for Safety Floor-Finishing Machines (Seventh Edition Reprint with Revisions Through and Including January 9 2018)《地板整理机用安全性标准》.pdf ANSI UL 561-2011 UL Standard for Safety Floor-Finishing Machines (Seventh Edition Reprint with Revisions Through and Including January 9 2018)《地板整理机用安全性标准》.pdf
  • ANSI UL 563-2009 UL Standard for Safety Ice Makers (Eighth Edition Reprint with Revisions Through and Including January 12 2017)《制冰机安全标准》.pdf ANSI UL 563-2009 UL Standard for Safety Ice Makers (Eighth Edition Reprint with Revisions Through and Including January 12 2017)《制冰机安全标准》.pdf
  • ANSI UL 565-2013 UL Standard for Safety Liquid-Level Gauges for Anhydrous Ammonia and LP-Gas (Sixth Edition Reprint with revisions through and including February 23 2018)《无水液氨和液化石油.pdf ANSI UL 565-2013 UL Standard for Safety Liquid-Level Gauges for Anhydrous Ammonia and LP-Gas (Sixth Edition Reprint with revisions through and including February 23 2018)《无水液氨和液化石油.pdf
  • ANSI UL 567-2014 UL Standard for Safety Emergency Breakaway Fittings Swivel Connectors and Pipe-Connection Fittings for Petroleum Products and LP-Gas (Tenth Edition Reprint with Re.pdf ANSI UL 567-2014 UL Standard for Safety Emergency Breakaway Fittings Swivel Connectors and Pipe-Connection Fittings for Petroleum Products and LP-Gas (Tenth Edition Reprint with Re.pdf
  • ANSI UL 567A-2015 UL Standard for Safety Emergency Breakaway Fittings Swivel Connectors and Pipe-Connection Fittings for Gasoline and Gasoline Ethanol Blends with Nominal Ethanol C.pdf ANSI UL 567A-2015 UL Standard for Safety Emergency Breakaway Fittings Swivel Connectors and Pipe-Connection Fittings for Gasoline and Gasoline Ethanol Blends with Nominal Ethanol C.pdf
  • ANSI UL 567B-2015 UL Standard for Safety Emergency Breakaway Fittings Swivel Connectors and Pipe-Connection Fittings for Diesel Fuel Biodiesel Fuel Diesel Biodiesel Blends with Nom.pdf ANSI UL 567B-2015 UL Standard for Safety Emergency Breakaway Fittings Swivel Connectors and Pipe-Connection Fittings for Diesel Fuel Biodiesel Fuel Diesel Biodiesel Blends with Nom.pdf
  • ANSI UL 568-2002 UL Standard for Safety Nonmetallic Cable Tray Systems (First Edition Reprint with revisions through and including May 30 2014).pdf ANSI UL 568-2002 UL Standard for Safety Nonmetallic Cable Tray Systems (First Edition Reprint with revisions through and including May 30 2014).pdf
  • ANSI UL 569-2013 UL Standard for Safety Pigtails and Flexible Hose Connectors for LP-Gas (Eighth Edition Reprint with Revisions Through and Including July 28 2017)《软管及软管连接器的安全性标准》.pdf ANSI UL 569-2013 UL Standard for Safety Pigtails and Flexible Hose Connectors for LP-Gas (Eighth Edition Reprint with Revisions Through and Including July 28 2017)《软管及软管连接器的安全性标准》.pdf
  • ANSI UL 574-2003 UL Standard for Safety Electric Oil Heaters (Eighth Edition Reprint with Revisions Through and Including August 13 2014).pdf ANSI UL 574-2003 UL Standard for Safety Electric Oil Heaters (Eighth Edition Reprint with Revisions Through and Including August 13 2014).pdf
  • 相关搜索

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

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