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

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

1、国家二级 C+机试(操作题)模拟试卷 157及答案与解析 一、基本操作题 1 给定程序中,函数 fun的功能是:将参数给定的字符串、整数、浮点数写到文本文件中,再用字符串方式从此文本文件中逐个读入,并调用库函数 atoi和 atof将字符串转换成相应的整数、浮点数,然后将其显示在屏幕上。 请在程序的中括号处填入正确的内容并把中括号删除,使程序得出正确的结果。 注意:部分源程序给出如下。不得增行或删行,也不得更改程序的结构 ! 试题程序: #include #include void fun(char*s, 2nt a, double f) *found* 【 1】 p; char sir100

2、 str1100, sir2100; int a1; double f1; fp=fopen(“filel txt“, “w“); fprintf(fp, “ s d f n“, s, a, f); *found* 【 2】; fp=fopen(“filel txt“, “r“); *found* fscanf(【 3】, “ s s s“, sir, str1, str2); fclose(fp); al=atoi(strl); f1=atof(str2); printf(“ nThe result: n n s d f n“, str, al, f1); main() char a10=

3、Hello!“; int b=12345; double c=98 76; fun(a, b, c); 二、简 单应用题 2 下列给定函数中,函数 fun的功能是:统计字符串中各元音字母 (即 A、 E、 I、O、 U)的个数。注意:字母不分大小写。 例如,输入 ”THIs is a boot”,则应输出是 1 0 2 2 0。 请改正程序中的错误,使它能得出正确的结果。 注意:部分源程序在文件 MODIl C中,不要改动 main函数,不得增行或删行,也不得更改程序的结构 ! 试题程序: #include #include #include *found* fun(char*s, int

4、num5) (int k, i=5; for(k=0; k=0) rlLlmi+; void main() char s181; int hum15, i; system(“CLS“); printf (“ nplease enter a string: “); gets(s1); fun(s1, num1); for(i=0; i #define N 80 int fun(char * sir) main() char sN; FILE*out; char*test=“1234321“, “123421“, “123321“, “abcdCBA“; int i; printf(“Enter

5、a string: “); gets(s); prLntf(“ n n“); puts(s); if(fun(s) printf(“YES n“); else printf(“NO n“); * out=fopen(“out dat“, “w“); for(i=0; i4; i+) if(fun(testi) fprintf(out, “YES n“); else fprintf(out, “NO n“); fclose(out); * 国家二级 C+机试(操作题)模拟试卷 157答案与解析 一、基本操作题 1 【正确答案】 (1)FILE* (2)fclose(fp) (3)fp 【试题解析

6、 填空 1:从使用 fp=fopen(“filel txt“, “w“)可知 fp应该是文件类型指针,因此本空应该填写 FILE*。 填空 2:当对 fp作打开操作的时候,并进行不同的操作前,应该对其关闭,因为在第一次打开时是对 fp进行写操 作,而在第二次打开后进行的是读操作,因此应该先对 fp进行关闭,本空填 fclose(fp)。 填空 3: fscanf()是把文本文件输出,因此本空只能填写 fp。 二、简单应用题 2 【正确答案】 (1)void fun(char*s, int num5) (2)numk=0; (3)switch(*s) 【试题解析】 switch语句说明如下:

7、1)switch后的表达式,可以是整型或字符型,也可以是枚举类型。在新的ANSIC标准中允许表达式的类型为任何类型。 (2)每个 case后的常量表达式只能是由常量组成的表达式,当 switch后表达式的值与某一个常量表达式的值一致时,程序就转到此 case后的语句开始执行。如果没有一个常量表达式的值与 switch后的值一致,就执行 default后的语句。 (3)各个 case后的常量表达式的值必须互不相同。 (4)各个 case的次序不影响执行结果,一般情况下,尽量将出现概率大的 case放在前面。 (5)在执行完一个 case后面的语句后,程序会转到下一个 case后的语句开始执行,

8、因而必须使用 break语句 才能跳出。 三、综合应用题 3 【正确答案】 int fun(char*str) int i, n=0, fg=1; char*p=str; while(*p) *将指针 p置位到字符串末尾,并统计字符数 * n+; p+; for(i=0; in 2; i+) *循环比较字符 * if(stri=strn一 1一 i); *相同,什么都不作 * else *不同,直接跳出循环 * fg=0; break; return fg; 【试题解析】 判断回文就是将第一个字符与最后一个字符比较,第二个字符与倒数第二个字符进行比较,依此类推,直到中间的字符,如果比较的结果都相同,那么这个字符串就是回文,否则不是。程序中循环语句用来遍历字符串,条件语句用来判断当前字符与对应位置的字符是否相同。

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