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

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

1、国家二级 C+机试(操作题)模拟试卷 257及答案与解析 一、基本操作题 1 使用 VC6打开考生文件夹下的源程序文件 modi1 cpp,该程序运行时有错误,请改正其中的错误,使程序正常运行,并且输出以下结果: (4, 5) 7, 8 (4, 8) 注意:错误的语句在 *error*的下面,修改该语句即可。 #include iostream h class CObj0 public: CObj0(int i, int j) x=i; y=j; *error* virtual void move(int a; int b) x+=a; y+=b; void print() cout “(“

2、x “, “ y “)“ endl; public: int x, y; ; class CObj1: public CObj0 public: *error* CObj1(int i, int j, int k): (i, j) m=k; n=1; void print() cout m “, “ n endl; void func() move(3, 5); void display() *error* print(); private: int m, n; ; void main() CObj0 obj(4, 5); obj print(); CObj1 obj1(1, 3, 7, 8)

3、; obj1 func(); obj1 print(); obj1 display(); 二、简单应用题 2 使用 VC6打开考生文件夹下的源程序文件 modi2 cpp。阅读下列函数说明和代码。函数 sort(int &m, int &n, int &1)实现将三个整数 m、 n、 1由大到小输出。 m最大, 1最小。 程序分析:程序实现时,可以把最大的数放到 m上,先将 m与 n进行比较,如果m n则将 m与 n的值进行交换,然后再用 m与 1进行比较,如果 m 1则将 m与1的值进行交换,这样能使 m最大。然后再将 n与 1进行比较,若 n 1则将 n与 1的值互换,互换后则 1最小。

4、将函数 sort(int&m, int&n, int&1)补充完整,实现三个数的排序。 注意:请勿改动主函数。 #include iostream h void sort(int&m, int&n, int&1) int main() int x=9; int y=13; int z=-3; sort(x, y, z), cout x , y , z endl; return0; 三、综合应用题 3 使用 VC6打开考生文件夹下的源程序文件 modi3 cpp。其中定义的类并不完整,按要求完成下列操作,将类的定义补充完整。完成以下功能: (1)定义类 CPoint的带有两个参数的构造函数,两个

5、变 量为 x、 y都为 int型,且缺省值为 0。请在注释 *1*后添加适当的语句。 (2)完成类 CRectangle的构造函数,给 point1和 point2进行赋值。请在注释*2*后添加适当的语句。 (3)完成类 CRectangle的函数 GetArea(),用来计算矩形面积。请在注释*3*后添加适当的语句。 (4)定义 CRectangle类,拥有两个私有对象 point1和 point2,类型为 Point,请在注释 *4*后添加适当的语句。 注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。 #include iostream h #include cmath cla

6、ss CPoint public: *1* x=i; y=j; int GetX() return x; int GetY() return Y; private: int x, y; ; class CRectangle public: *2* int GetArea() *3* int height=point1 GetY()-point2 GetY(); return(width*height)?width*height: -width*height, int GetGirth() int width=abs(point1 GetX()-point2 GetX(); int height

7、=abs(point1 GetY()-point2 GetY(); return(2*(width+height); private: *4* CPoint point2; ; int main() CRectangle rect(5, 2, 13, 18); cout rect GetArea() endl; cout rect GetGirth() endl; return0; 国家二级 C+机试(操作题)模拟试卷 257答案与解析 一、基本操作题 1 【正确答案】 (1)Virtual void move(int a, int b) (2)CObj1(int i, int j, int

8、k, int1): CObj0(i, j) (3)CObj0: print(); 【试题解析】 (1)编译程序可知第 l标识下有错误,此处是声明虚函数,虚函数的声明方式为: virtual类型说明符函数名 (参数表 ),参数表中各参数之间应该用 “, ”隔开,因此第 1个标识下应改为 “virtual void move(int a, int b)”。 (2)在主函数里 “CObj1 obj1(1, 3, 7, 8); ”,可知构造函数 CObj1()有四 个参数,完成变量 m、 n、 x和 y的初始化, k和 1赋值给 m和 n, i和 j赋值给 x和 y, x和y的初始化可通过基类构造函数

9、来完成对 x和 y的初始化,第 2个标识下应改为CObj1(int i, int j, int k, int1): CObj0(i,j)。 (3)由程序运行结果可知标识 3下调用的是基类的 print()函数,而 “print(); ”是调用的派生类的 print()函数,因此此时只能通过类名来直接调用 print()函数,即第3个标识下应改为 “CObj0: print(); ”。 二、简单应用题 2 【正确答案】 int t; if(m n) t=m; m=n; n=t; *交换 x, y的值 * if(m 1) t=m; m=1; 1=t; *交换 x, z的值 * if(n 1) (t

10、=n; n=1; 1=t; *交换 z, y的值 * 【试题解析】 (1)由审题分析可知,三次比较便可将 m、 n、 1排序。 (2)在实现时,先将 m与 n进行比较,如果 m n则将 m与 n的值进行交换,然后再用 m与 1进行比较,如果 m 1则将 m与 1的值进行交换,这样能使 m最大。然后再将 n与 1进行比较,若 n 1则将 n与 1的值互换,互换后则 1最小,这样就得到 m最大, 1最小的排序结果。 (3)在 sort函数内用三个 if比较即可,条件成立则进行交换。 三、综合应用题 3 【正确答案】 (1)添加语句: CPoint(int i=0, int j=0) (2)添加语句

11、: CRectangle(int top, int left, int right, int bottom): point1(top, left),point2(right, bottom) (3)添加语句: int width=point1 GetX()-point2 GetX(); (4)添加语句: CPoint point1; 【试题解析】 (1)在第 1个标识下添加构造函数定义,该构造带有两个参数 x和 y的构造函数, x、 y都为 int型,缺省值为 0,因此第 1个标识下应添加 CPoint(int i=0, int j0)。 (2)第 2个标识下通过 Cpoint类的构造函数来完

12、成 Crectangle类成员的初始化,在函数体内没有任何函数语句,因此其初始化过程是在初始化列表里完成的,通过调用基类的构造函数来实现两个私有对象 point1和 point2的初始化,故第 2个标识下应添加 CRectangle(int top, int left, int right, int bottom): point1(top,left), point2(right, bottom)。 (3)面积为矩形的长宽之积,因此先计算矩形的长和宽,可由两个 Cpoint对象的 x坐标相减计算得到, CPoint对象的 x坐标为私有成员,只能通过公有接口函数调用获得,因此第 3个标识下为 “int width=point1 GetX()-point2 GetX(); ”。 (4)Crectangle类的成员变量为两个 Cpoint对象成员 point1和 point2,第 4个标识下补充 point1的定义,故第 4个标识下应添加 “CPoint point1; ”。

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