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

上传人:diecharacter305 文档编号:497398 上传时间:2018-11-28 格式:DOC 页数:5 大小:29.50KB
下载 相关 举报
[计算机类试卷]国家二级C++机试(操作题)模拟试卷319及答案与解析.doc_第1页
第1页 / 共5页
[计算机类试卷]国家二级C++机试(操作题)模拟试卷319及答案与解析.doc_第2页
第2页 / 共5页
[计算机类试卷]国家二级C++机试(操作题)模拟试卷319及答案与解析.doc_第3页
第3页 / 共5页
[计算机类试卷]国家二级C++机试(操作题)模拟试卷319及答案与解析.doc_第4页
第4页 / 共5页
[计算机类试卷]国家二级C++机试(操作题)模拟试卷319及答案与解析.doc_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

1、国家二级 C+机试(操作题)模拟试卷 319及答案与解析 一、基本操作题 1 使用 VC6打开考生文件夹下的源程序文件 modi1 cpp,该程序运行时有错,请改正其中的错误,使程序正常运行,即使程序在界面输出以下类似内容: 0012FF68 1 0012FF3C 5 0012FF6C 2 0012FF44 4 0012FF70 3 0012FF4C 3 0023FF74 4 0012FF54 2 0012FF78 5 0012FF5C 1 006AFDCC 006AFDEF数据可能因为机器的不同,程序的输出的内容会有差异。只要相差为 4的连续地址即可。 注意:不要改动 main函数,不能增行

2、或删行,也不能更改程序的结构,错误的语句在 *error*的下面。 #include using namespace std; int main() int*p, a5=1, 2, 3, 4, 5; double*q, b5=5 0, 4 0, 3 0, 2 0, 1 0; int x; p=a; q=b; *error* for(x=0; x Void func(int d, int num) int main() int Data=1, 2, 3, 4, 5, 6, 7, 8, 9); func(Data, 9); for(int i=0; i using namespace std; C

3、lass TestClass public: *1* cout“int“endl; return 10; *2* coutstrendl; ; int main() TestClass obj; *3* *4* return 0; 国家二级 C+机试(操作题)模 拟试卷 319答案与解析 一、基本操作题 1 【正确答案】 (1)for(x=0; x5; x+) (2)coutp+x “ “ *(p+x) “ “ q+x “ “ *(q+x) endl; 【试题解析】 (1)根据数组 a、 b定义,它们都是 5个元素,而第 1个标识下的“for(x=0; x=5; x+)”循环了 6次,应该是

4、5次,所以第 1个标识下的将其修改为 “for(x=0; x5; x+)” (2)第 2个标识下的 P变量为指针型变量 , p+x为指向数组中第 x个元素的地址,这里要输出的是存储单元的内容,所以使用 “*”指针元素符,即修改为“coutp+x“ “*(p+x)“ “q+x“ “*(q+x)endl; ”。 二、简单应用题 2 【正确答案】 for(int i=0; inum; i+) if(di 2!=0) di=2*di; 【试题解析】 (1)由审题分析可知,利用循环来逐个判断 d中的元素, d中元素个数为 num,因此循环变量从 0变化至 num。 (2)在循环内,用 if 判断该元素是

5、不是奇数,即 if(di 2!=0),将满足条件的 di扩大一倍。 三、综合应用题 3 【正确答案】 (1)添加语句: operator int() (2)添加语句: operator(char*str) (3)添加语句: int i=int(obj); (4)添加语句: obj“Hello Test“; 【试题解析】 (1)题目 1要求 “重载运算符 int”的定义。运算符重载的方法是定义一个重载运算符的函数,其一般格式为:函数类型 opemmr运算符名称 (形参列表 )对运算符的重载处理 )。所以第 1个标识下,重载运算符 int的语句为 “operator int()”。 (2)题目 2

6、要求 “重载运算符 ”。同 (1),第 2个标识下 “”的重载函数定义为“operator(char*str)”。 (3)题目 3要求 “在主函数 main()中定义变量 i,并调用对象 obj的 int运算符,给变量赋初值为 10。 ”定义变量 i,即 int i。 “operator int()”中的返回值为 10,所以调用对象 obi的 int运算符,给变量赋初值为 10,就是 int(obj),即第三个标识下添加 “inti=int(obj); ”。 (4)题目 4要求 “调用 0bj的 “”运算符输出 “HelloTest”“。重载运算符 “”后,不仅能输出标准类型数据,而且可以输出用户自己定义的类对象。所以直接添加要输出的字符串即可,即 “obj“Hello Test“; ”。

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