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

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

1、国家二级 C+机试(操作题)模拟试卷 167及答案与解析 一、基本操作题 1 下列给定程序中,函数 fun的功能是:将形参 n所指变量中,各位上为偶数的数去掉,剩余的数按原来从高位到低位的顺序组成一个新数,并通过形参指针 n传回所指变量。 例如,若输入一个数 27638496,则新数为 739。 请在程序的中括号处填入正确的内容并将中括号删除,使程序得出正确的结果。 注意:部分源程序给出如下。 不得增行或删行,也不得更改程序的结构 ! 试题程序: #include void fun(unsigned long*n) unsigned long x=0, i; int t; i=1; while

2、n) *found* t=*n【 1】; *found* if(t 2!=【 2】 ) x=x+t*i; i=i*10; *n=*n 10; *found* *n=【 3】; main() unsigned long n=一 1; while(n99999999 n #include *found* void fun(int m, int k); int aa20, i; for(i=0; m; i+) *found* aai=m k; m =k; for(; i; i-) *found* printf(“ d“, aai); main() int b, n; printf(“ nPlea

3、se enter a num bet and a hase: n“); scanf(“ d d“, &n, &b); fun(n, b); printf(“ n“); 三、综合应用题 3 函数 fun的功能是:将 s所指字符串中下标为 偶数同时 ASCII值为奇数的字符删除, s所指串中剩余的字符形成的新串放在 t所指的数组中。 例如,若 s所指字符串中的内容为 ”ABCDEFGl2345”,其中字符 C的 ASCII码值为奇数,在数组中的下标为偶数,因此必须删除;而字符 1的 ASCII码值为奇数,在数组中的下标为奇数,因此不应当删除,其他依此类推。最后 t所指的数组中的内容应是 ”BDF1

4、2345”。 注意:部分源程序在文件 PROG1 C中。 请勿改动 main函数和其他函数中的任何内容,仅在函数 fun的花括号中填入你编写的若干语句。 试题程序: #include #include void fun(char*s, char t) main() char s100, t100; void NONO(); printf(“knPlease enter string S: “); scanf(“ S“, S); fun(s, t); printf(“ nThe result is: s n“, t); NONO(), void NONO() *本函数用于打开文件,输入数据,调用

5、函数,输出数据,关闭文件。 * char s100, t100; FILE*rf, *wf; int i; rf=fopen(“in dat“, “r“); wf=fopen(“out dat“, “w“); for(i=0 ; i10; i+) fscanf(rf, “ s“, s); fun(s, t); fprintf(wf, “ s n“, t); fclose(rf), fclose(wf); 国家二级 C+机试(操作题)模拟试卷 167答案与解析 一、基本操作题 1 【正确答案】 (1)10 (2)0 (3)x 【试题解析】 填空 1:通过 t对 10求余,取出该数值的各个位。 填

6、空 2:通过 if条件语句实现奇偶数的判定。如果条件表达式对 2求余为 0即为偶数,反之则为奇数。 填空 3:最后将剩余的数赋给 n所指向的元素。 二、简单应用题 2 【正确答案】 (1)void fun(int m, int k) (2)aai=m k; (3)printf(“ d“, aai 1); 【试题解析】 (1)函数定义的格式错误,不应带有 ”; ”。 (2)将十进制正整数转换为任意进制的数与十进制正整数转换成二进制的数的方法是一样的。从整数 n泽出它的各位 k进制数值,需采用除 k取余的方法,即求 n除 k的余数,得到它的 k进制的个位数,接着将 n除以 k。在 n不等于 0的状况下循环,能顺序求出 n的 k进制的各个位上的数。 (3)在进行 for(i=0; m; i+)循环结束时, i已经多加了一个 1,所以这里要减去1。 三、综合应用题 3 【正确答案】 void fun(char*s, char t) int i, j =0; for(i =0, i strlen(s); i+) if(!(i 2)=0&(si 2) tj+=si; tj =0; 【试题解析】 本题是从一个字符串按要求生成另一个新的字符串。我们使用 for循环语句来解决这个问题。在赋值新的字符串之前,先对数组元素的下标和ASCII码的值进行判断,将满足要求的元素赋给新的 字符串。

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