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

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

1、国家二级 C+机试(操作题)模拟试卷 10及答案与解析 一、基本操作题 1 使用 VC+6 0打开考生文件夹下的源程序文件 1 cpp,该程序运行时有错,请改正其中的错误,使程序正常运行,并使程序输出的结果为 TC1 TC2 注意:不要改动 main函数,不能增加或删除行,也不能更改程序的结构,错误的语句在 *error*的下面。 试题程序: #include #include struct TC0 *error* virtual void fun(); ; class TC1: public TC0 void fun() cout #include(cmath) using namespac

2、e std; void WriteFite(char*s) void fun(char*s) void ClearFile() ofstream out1; out1 open(“2 txt“); out1 close(); int main() ClearFile(); char s102; cout class Date public: *1* Date(int Y, int m, int d) *2* void print()const; private: data member *3* ; void Date: print()const *4* int main() Date Olym

3、pic_BJ(2008, 8, 8); Olympic_BJ print(); return 0; 国家二级 C+机试(操作题)模拟试卷 10答案与解析 一、基本操作题 1 【正确答案】 (1)应改为 “virtual void fun()=0; ”。 (2)应改为 “p=&obj1; ”。 (3)应改为 “p=&obj2; ”。 【试题解析】 如果在基类中不使用这个虚函数,其返回值也是没有意义的,它应该被定义为纯虚函数。所以虚函数 fun应该是纯虚函数,也就是声明虚函数时初始化为 0的函数。即第 1处的 “virtual void fun()=0; 99。第 2处的 P为指针变量,将对象 o

4、bj1赋值给 p,实际上是 P指向对象 obj1的地址,所以将 “p=*obj1; ”修改为 “p=&obj1; ”。第 3处的 “p=*obj2; ”修改为 “p=&obj2; ”。 二、简单应用题 2 【正确答案】 (1)void WriteFile(char*s)中的命令语句: ofstream out1; out1 open(“2 txt“, ios_base: binary ios_base: app);打开文件 2 txt out1s; 写入字符串 s out1 close(); (2)void fun(char*s)中的命令语句: for(int i=0; si!=0; i+)

5、循环判断每一个字符 if(si)=A&si(=Z) 如果是大写字符,则转换为小写字符 si=si-A+a; si-A+a等于字符 si+32 else if(si)=a &si(=z) 如果是小写字符,则转换为大写字符 si=si-a+A; si-a+A等于字符 si-32 writeFile(s): 【试题解析】 在 WriteFile(char*s)函数中,利用标准流 ofstream实现字符串写入文件 2 txt。在 fun函数中,利用 for循环逐个判断字符是大写还是小写。如果是大写,那么加上 32实现大 -g转换为小写。否则就减去 32,实现小写到大写的转换。最后调用前面实现的 Wr

6、iteFile函数,将字符串写入文件。 三、综合应用题 3 【正确答案】 (1)应添加 “Date()year=1; month=1; day=1; ”或 “Date():year(1), month(1), day(1)”。 (2)应添加 “year=y; month=m; day=d; ”。 (3)应添加 “int year, month, day; ”。 (4)应添加 “coutyear“-“month“-“dayend1;或 tout(year-month-dayend1; ”。 【试题解析】 本题考查了类的定义。根据题意,此处应定义 3个 int型数据成员year、 month和 day。根据题意,第 2处应添加默认构造函数,并初始化 3个变量,这里既可以使用赋值语句来实现,也可以使用初始化列表。第 3处只能通过赋值语句初始化 3个成员,因为注释 3位于函数中,无法在此处使用初始化列表。添加输出语句,注意题目头包含的头文件是 iostream h,不能添加 std:前缀。

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