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

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

1、国家二级 C+机试(操作题)模拟试卷 221及答案与解析 一、基本操作题 1 请使用 VC6或使用【答题】菜单打开考生文件夹 proj1下的工程 proj1,该工程中包含程序文件 main cpp,其中有类 Foo和主函数 main的定义。程序中位于每个 “ ERROR*found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应该是: X=a Y=42 注意:只修改每个 “ ERROR*found*”下的那一行,不要改动程序中的其他内容。 1 #include 2 using namespace std; 3 4 clasS Foo 5 public: 6 Foo(char X)x

2、x; ; 7 char getX()constreturn x_; 8 public: 9 static int y_; 10 private: 11 char x_; 12 ; 13 14 ERROR *found* 15 int Foo y_=42; 16 17 int main(int argc, char*argv) 18 19 ERROR *found* 20 Foo f; 21 22 ERROR*found* 23 cout 2 #include 3 #include“BaseX h“ 4 using namespace std; 5 BaseX: BaseX(int n) 6

3、 this-num=n; 7 8 BaseX: BaseX() 9 void BaseX: print(int x) 输出整数 num的 x进制表示形式 10 int arr100; 存放转换结果, arr0存放最低位 11 int index=0; 当前数组 arr中 12 元素的个数 13 *333* 14 15 16 *666* 17 for(int i=index-1; i=0; i-) 从高位到低位输出所需表示形式 18 coutarri; 19 20 coutendl; 21 22 int main() 23 BaseX b(129); 24 b print(4); 25 writ

4、eToFile(“c: test “); 26 return 0; 27 1 proj3 BaseX h 2 class BaseX 3 int num; 4 public: 5 BaseX(int n); 6 BaseX(); 7 void print(int x); 8 ; 9 void writeToFile(const char*path); 国家二级 C+机试(操作题)模拟试卷 221答案与解析 一、基本操作题 1 【正确答案】 (1)int Foo: y_=42; (2)Foo f(a); (3)cout“X=“f getX()endl; 【试题解析】 (1)主要考查考生对静态成员

5、的掌握,因为静态整型变量 y_是 Foo类的公有成员,所以给 y_赋值时要加上 “Foo: ”,即 int Foo: y_=42;。 (2)主要考查考生对构造函数的掌握,题目要求程序输出: X=a Y=42 可以知道,在给 Foo类的 f声明时要同时初始化为字符 a,即语句 Foo f(a);。 (3)主要考查考生对成员函数的掌握,因为 x是类 Foo的私有 成员,所以不能在main函数中直接调用,要通过公有成员函数 getX()调用。 二、简单应用题 2 【正确答案】 (1)x1(root), x2(root), num_of_roots(1) (2)cout“无实根 “; break; (

6、3)a(a), b(b), c(c) (4)return Quadratic(a-x a, b-x b, c-x e); 【试题解析】 (1)主要考查考生对构造函数的掌握,题目要求创建一个 “有两个相同的实根 ”的 Root对象。说明两个根 x1和 x2相等,根的数量为 1,因此可以得出语句: x1(root), x2(root), num_of_roots(1)。 (2)主要考查考生对 switch语句的掌握,在语句 switch(num_of_roots)中,num_of_roots代表根的数量,当为 0时,表示没有根,因此输出无实根,注意要在句尾加 break。 (3)主要考查考生对构造函数的掌握,本题使用成员初始化列表来构造函数。 (4)主要考查考生对成员函数的掌握,题目要求求两个多项式的差。两个多项式的差就是各个次方的系数相减,因此得出语句: return Quadratic(a-x a, b-x b, c-x c);。 三、综合应用题 3 【正确答案】 1 while(Hum) 2 3 arrindex+=num x; 4 nun =x: 5 【试题解析】 将一个数转化为 x进制,使用辗转相除法,将余数放在 arr数组中,对商继续使用辗转相除法来处理,直到商为 0。最后反向输出数组中的值,即为 x进制的数。

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