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

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

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

2、ound* / for (i=0; i_二、程序修改题(总题数:1,分数:2.00)2.给定函数 MODI1C 中函数 fun的功能是:将一个由八进制数字字符组成的字符串转换为与其面值相等的十进制整数。规定输入的字符串最多只能包含 5位八进制数字字符。 例如,若输入:77777,则输出将是:32767。 请改正程序中的错误,使它能得出正确结果。 注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构。 #include #include #include int fun(char *p) int n; /* found*/ n= *p-o; P+; while(*p!=0) /*

3、found*/ n=n*8+*P-o; P+; return n; main () char s6; int i; int n; printf(“Enter a string (Ocatal digits): “); gets(s); if(strlen(s)5)printf(“Error: String too longer!/n/n“); exit(0); for(i=0; si; i+) if (si7) printf(“Error: %c not is ocatal digits!/n/n“,si);exit(0); printf (“The original string: “) ;

4、 puts (s); n=fun (s); printf(“/n%s is convered to integer number: %d/n/n“,s,n); (分数:2.00)_三、程序设计题(总题数:1,分数:2.00)3.学生的记录由学号和成绩组成,N 名学生的数据已在主函数中放入结构体数组 s中,请编写函数 fun,它的功能是:函数返回指定学号的学生数据,指定的学号在主函数中输入。若没找到指定学号,在结构体变量中给学号置空串,给成绩置-1,作为函数值返回。(用于字符串比较的函数是 strcmp)。 注意:部分源程序在文件 PROG1C 中。 请勿改动主函数 main和其他函数中的任何内

5、容,仅在函数 fun的花括号中填入你编写的若干语句。 #include #include #define N 16 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, “GA006“,87,“GA015“,85, “GA013“,91,“GA012“, 64, “GA014“,91,“GA011“,77, “G

6、A017“,64, “GA018“,64, “GA016“,72; STREC h; char m10; int i;FILE *out ; printf(“The original data:/n“); for(i=0; i_国家二级 C语言机试(操作题)模拟试卷 526答案解析(总分:6.00,做题时间:90 分钟)一、程序填空题(总题数:1,分数:2.00)1.函数 fun的功能是:逆置数组元素中的值。例如:若 a所指数组中的数据依次为:1、2、3、4、5、6、7、8、9,则逆置后依次为:9、8、7、6、5、4、3、2、1。形参 n给出数组中数据的个数。 请在程序的下划线处填入正确的内容

7、并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的 BLANK1C 中。 不得增行或删行,也不得更改程序的结构! #include void fun(int a, int n) int i,t; /* found* / for (i=0; i_正确答案:(正确答案:(1)n2 (2)i (3)ani 一 1)解析:解析:函数 fun的功能是将数组中的元素倒置。 第一空:由审题分析可知,总共交换 n2 次,故循环的终止条件为 i等于 n2,故第一空处应为“n2”。 第二空:a0和 an一 1交换,a1和an-2交换,因此,ai和 an-i一 1交换,故第二空处应为“i”。

8、第三空:“t=ai;ai=an-1-i;”所以第三空处是把 t值赋值 an-1-i,故第三空处应为“an-1-i”。二、程序修改题(总题数:1,分数:2.00)2.给定函数 MODI1C 中函数 fun的功能是:将一个由八进制数字字符组成的字符串转换为与其面值相等的十进制整数。规定输入的字符串最多只能包含 5位八进制数字字符。 例如,若输入:77777,则输出将是:32767。 请改正程序中的错误,使它能得出正确结果。 注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构。 #include #include #include int fun(char *p) int n; /*

9、 found*/ n= *p-o; P+; while(*p!=0) /* found*/ n=n*8+*P-o; P+; return n; main () char s6; int i; int n; printf(“Enter a string (Ocatal digits): “); gets(s); if(strlen(s)5)printf(“Error: String too longer!/n/n“); exit(0); for(i=0; si; i+) if (si7) printf(“Error: %c not is ocatal digits!/n/n“,si);exit(

10、0); printf (“The original string: “) ; puts (s); n=fun (s); printf(“/n%s is convered to integer number: %d/n/n“,s,n); (分数:2.00)_正确答案:(正确答案:(1)n=*p 一0; (2)n=n*8+*p 一0;)解析:解析:函数功能是实现八进制到十进制的转换。 (1)第一个标识下面:语句“n=*p-o;”中的o不是数字零,而是字母o,根据前面的分析,因此改为:“n=*p-0;”。 (2)第二个标识下面:语句“n=n*8+*P-o”,首先进行同(1)相同的修改,变量 P没有定

11、义,根据题意要求这里应该是“*p-0”,所以此句改为:“n=n*8+*p-0;”。三、程序设计题(总题数:1,分数:2.00)3.学生的记录由学号和成绩组成,N 名学生的数据已在主函数中放入结构体数组 s中,请编写函数 fun,它的功能是:函数返回指定学号的学生数据,指定的学号在主函数中输入。若没找到指定学号,在结构体变量中给学号置空串,给成绩置-1,作为函数值返回。(用于字符串比较的函数是 strcmp)。 注意:部分源程序在文件 PROG1C 中。 请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。 #include #include #def

12、ine N 16 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, “GA006“,87,“GA015“,85, “GA013“,91,“GA012“, 64, “GA014“,91,“GA011“,77, “GA017“,64, “GA018“,64, “GA016“,72; STREC h; char m

13、10; int i;FILE *out ; printf(“The original data:/n“); for(i=0; i_正确答案:(正确答案:STREC c; int i; cnum0=0;*置初始空串* cs=一 1; *置成绩为一 1* for(i=0; iN; i+) if(strcmp(ainum,b)=0) *判断学号是否相等* strcpy(cnum, ainum); *相等,则对学号进行赋值* cs=ais;* 相等,则对成 绩进行赋值* break; * 退出循环体 * return c;* 返回结构体变量 *)解析:解析:该程序功能是函数返回指定学号的学生数据,指定的学号在主函数中输入。解题思路是在循环过程中,使用 if判断表达式,将输入的学号与所有的学号进行比较,如果找到该学号,将其赋值到指定变量,否则将空格赋值到指定变量,表明没有查找到该学号。

展开阅读全文
相关资源
猜你喜欢
  • DIN ISO 16853-2011 Textile machinery - Sliver cans rectangular - Main dimensions and tolerances (ISO 16853 2010)《纺织机械 矩形条筒 主要尺寸规格和公差(ISO 16853-2010)》.pdf DIN ISO 16853-2011 Textile machinery - Sliver cans rectangular - Main dimensions and tolerances (ISO 16853 2010)《纺织机械 矩形条筒 主要尺寸规格和公差(ISO 16853-2010)》.pdf
  • DIN ISO 16854-2006 Textile machinery - Ring twisting machines - Terms and definitions (ISO 16854 2004 text in German English and French)《纺织机械 环锭捻线机 术语和定义(ISO 16854-2004 德文、英文和法文文本).pdf DIN ISO 16854-2006 Textile machinery - Ring twisting machines - Terms and definitions (ISO 16854 2004 text in German English and French)《纺织机械 环锭捻线机 术语和定义(ISO 16854-2004 德文、英文和法文文本).pdf
  • DIN ISO 16875-2006 Textile machinery - Ring spinning machines for cotton spinning - Terms and definitions Principles of construction (ISO 16875 2004 text in German English and Fren.pdf DIN ISO 16875-2006 Textile machinery - Ring spinning machines for cotton spinning - Terms and definitions Principles of construction (ISO 16875 2004 text in German English and Fren.pdf
  • DIN ISO 16915-2005 Tools for moulding - Sprue pullers (ISO 16915 2003)《模铸工具 直浇口拉出器》.pdf DIN ISO 16915-2005 Tools for moulding - Sprue pullers (ISO 16915 2003)《模铸工具 直浇口拉出器》.pdf
  • DIN ISO 16916-2017 Tools for moulding - Tool specification sheet for injection moulds (ISO 16916 2016)《模铸工具 注塑模用工具规格表(ISO 16916-2016)》.pdf DIN ISO 16916-2017 Tools for moulding - Tool specification sheet for injection moulds (ISO 16916 2016)《模铸工具 注塑模用工具规格表(ISO 16916-2016)》.pdf
  • DIN ISO 16938-1-2012 Building construction - Determination of the staining of porous substrates by sealants used in joints - Part 1 Test with compression (ISO 16938-1 2008)《建筑构件 接合.pdf DIN ISO 16938-1-2012 Building construction - Determination of the staining of porous substrates by sealants used in joints - Part 1 Test with compression (ISO 16938-1 2008)《建筑构件 接合.pdf
  • DIN ISO 16938-2-2012 Building construction - Determination of the staining of porous substrates by sealants used in joints - Part 2 Test without compression (ISO 16938-2 2008)《建筑结构.pdf DIN ISO 16938-2-2012 Building construction - Determination of the staining of porous substrates by sealants used in joints - Part 2 Test without compression (ISO 16938-2 2008)《建筑结构.pdf
  • DIN ISO 171-2000 Plastics - Determination of bulk factor of moulding materials (ISO 171 1980)《塑料 模塑材料体积系数的测定》.pdf DIN ISO 171-2000 Plastics - Determination of bulk factor of moulding materials (ISO 171 1980)《塑料 模塑材料体积系数的测定》.pdf
  • DIN ISO 1711-1-2007 Assembly tools for screws and nuts - Technical specifications - Part 1 Hand-operated wrenches and sockets (ISO 1711-1 2007) English version of DIN ISO 1711-1-20.pdf DIN ISO 1711-1-2007 Assembly tools for screws and nuts - Technical specifications - Part 1 Hand-operated wrenches and sockets (ISO 1711-1 2007) English version of DIN ISO 1711-1-20.pdf
  • 相关搜索

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

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