【计算机类职业资格】二级C++-32及答案解析.doc

上传人:hopesteam270 文档编号:1324081 上传时间:2019-10-17 格式:DOC 页数:5 大小:33KB
下载 相关 举报
【计算机类职业资格】二级C++-32及答案解析.doc_第1页
第1页 / 共5页
【计算机类职业资格】二级C++-32及答案解析.doc_第2页
第2页 / 共5页
【计算机类职业资格】二级C++-32及答案解析.doc_第3页
第3页 / 共5页
【计算机类职业资格】二级C++-32及答案解析.doc_第4页
第4页 / 共5页
【计算机类职业资格】二级C++-32及答案解析.doc_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

1、二级 C+-32及答案解析(总分:28.00,做题时间:90 分钟)一、B1改错题/B(总题数:1,分数:30.00)使用 VC+6.0打开考生文件夹下的源程序文件 1.cpp,该程序运行时有错,请改正其中的错误,使程序正确运行,其输出的结果为30130注意:错误的语句在/*error*的下面,修改该语句即可。试题程序:#includeiostream.hint a=10;class TCpublic:TC()a=b=0;void display()/*error*coutabend1;void func(int a)/*error*a+=a;void func2()/*error*a+=a;

2、private:int a,b;void main()TC obj;obj.func(3);obj.display();obj.func2();obj.display();(分数:30.00)填空项 1:_填空项 1:_填空项 1:_二、B2简单应用题/B(总题数:1,分数:-1.00)1.使用 VC+6.0打开考生文件夹下的源程序文件 2.cpp。阅读下列函数说明和代码,完成空出部分程序。函数 fun(int n)的功能是在 n行 n列的矩阵中,每行都有最大的数,本程序求这 n个最大数中的最小一个,并作为参数返回。 注意:不能修改程序的其他部分,只能修改 fun函数。 试题程序: #incl

3、udeiostream.h #define N 100 int aNN; int fun(int n) void main() int n; cout“please input N:“end1; cinn; for(int i=0;in;i+) for(int j=0;jn;j+) cout“please input a Number:“end1; cinaij; cout“The min of max numbers is“fun(n)end1; (分数:-1.00)_三、B3综合应用题/B(总题数:1,分数:-1.00)2.使用 VC6打开考生文件夹下的工程 test5_3。此工程包含一个

4、源程序文件 test5_3.cpp,其中定义了一个类 Pn,用于求 n!。请按要求完成下列操作,将程序补充完整。 (1)定义私有数据成员 value(存放 n)和 fact(存放 n!),它们都是 int型的数据。请在注释“/*1*”之后添加适当的语句。 (2)完成默认构造函数 Fn的定义,使 Fn对象的数据成员 value值为 i,fact 值为 1。请在注释“/*2*”之后添加适当的语句。 (3)完成函数 Cal的定义,该函数计算 value的阶乘,并将运算结果保存在 fact中,要求使用 while循环实现。请在注释“/*3*”之后添加适当的语句。 (4)将主函数补充完整,直接调用类的成

5、员函数,在界面上输出 value的阶乘值。请在注释“/*4*”之后添加适当的语句。 注意;除在指定位置添加语句之外,请不要改动程序中的其他内容。 源程序文件 test5_3.cpp清单如下: #includeiostream.h class Fn /*1* public: Fn(int i); void Cal(); void disp(); ; Fn:Fn(int i) /*2* void Fn:Cai() /*3* fact*=i-; void Fn:disp() coutvalue“!=“factendl; void main() int value; cout“Enter the va

6、lue:“; cinvalue; Fn A(value); /*4* (分数:-1.00)_二级 C+-32答案解析(总分:28.00,做题时间:90 分钟)一、B1改错题/B(总题数:1,分数:30.00)使用 VC+6.0打开考生文件夹下的源程序文件 1.cpp,该程序运行时有错,请改正其中的错误,使程序正确运行,其输出的结果为30130注意:错误的语句在/*error*的下面,修改该语句即可。试题程序:#includeiostream.hint a=10;class TCpublic:TC()a=b=0;void display()/*error*coutabend1;void func

7、(int a)/*error*a+=a;void func2()/*error*a+=a;private:int a,b;void main()TC obj;obj.func(3);obj.display();obj.func2();obj.display();(分数:30.00)填空项 1:_ (正确答案:应改为“coutabend1;”。)解析:填空项 1:_ (正确答案:应改为“thisa+=a;”。)解析:填空项 1:_ (正确答案:应改为“a+=:a;”。)解析:解析 成员函数 display打印变量 a和 b的值,即 cout输出 a和 b的值,cout 流中的数据是用流插入运算符

8、“”顺序加入的,因此“”不正确,第 1处的语句应改成“coutabend1。在 func(int a)中,参数 a传递进来,其和成员变量 a的名称一样,因此第2处的“a+=a”有歧义,从程序的运行结果来分析,TC obj 声明对象 obj,初始化类成员变量 a和 b均为0,调用 func函数后输出 30,说明 a为 3,b 为 0,因此这里应该是成员变量与参数 a的和赋给成员变量a,正确的写法是“thisa+=a;”。func2 函数虽然没有参数,但成员变量 a和全局变量 a重名,第3处的“a+=a”也会有歧义,分不清楚是全局变量加倍还是类成员变量加倍或者其他情况,调用 func2函数后,输出

9、“130”,说明 a为 13,b 为 0,因此是成员变量与全局变量 a的和赋给成员变量 a,正确的写法是“a+=:a;”,“:a”表示是全局变量 a。二、B2简单应用题/B(总题数:1,分数:-1.00)1.使用 VC+6.0打开考生文件夹下的源程序文件 2.cpp。阅读下列函数说明和代码,完成空出部分程序。函数 fun(int n)的功能是在 n行 n列的矩阵中,每行都有最大的数,本程序求这 n个最大数中的最小一个,并作为参数返回。 注意:不能修改程序的其他部分,只能修改 fun函数。 试题程序: #includeiostream.h #define N 100 int aNN; int f

10、un(int n) void main() int n; cout“please input N:“end1; cinn; for(int i=0;in;i+) for(int j=0;jn;j+) cout“please input a Number:“end1; cinaij; cout“The min of max numbers is“fun(n)end1; (分数:-1.00)_正确答案:(int row; int max; int min; int col; for(row=0;row(n;row+) /外循环求行最大值中的最小值 for(max=arow0,col=1;coln;

11、col+)/求每一行中的最大值 if(max(arowcol) max=arowcol; if(row=0) /求最小值 min=max; else if(max(min) min=max; return min;)解析:解析 本题有两层循环,内层循环求每一行的最大值,外层循环求最小值。求最大值,首先将最大值赋值为每行第一列的元素,然后依次循环比较。将求出的第一个最大值赋值为第一个最小值,然后将以后求得的最大值依次与之比较,求出所有值的最小值。三、B3综合应用题/B(总题数:1,分数:-1.00)2.使用 VC6打开考生文件夹下的工程 test5_3。此工程包含一个源程序文件 test5_3.

12、cpp,其中定义了一个类 Pn,用于求 n!。请按要求完成下列操作,将程序补充完整。 (1)定义私有数据成员 value(存放 n)和 fact(存放 n!),它们都是 int型的数据。请在注释“/*1*”之后添加适当的语句。 (2)完成默认构造函数 Fn的定义,使 Fn对象的数据成员 value值为 i,fact 值为 1。请在注释“/*2*”之后添加适当的语句。 (3)完成函数 Cal的定义,该函数计算 value的阶乘,并将运算结果保存在 fact中,要求使用 while循环实现。请在注释“/*3*”之后添加适当的语句。 (4)将主函数补充完整,直接调用类的成员函数,在界面上输出 val

13、ue的阶乘值。请在注释“/*4*”之后添加适当的语句。 注意;除在指定位置添加语句之外,请不要改动程序中的其他内容。 源程序文件 test5_3.cpp清单如下: #includeiostream.h class Fn /*1* public: Fn(int i); void Cal(); void disp(); ; Fn:Fn(int i) /*2* void Fn:Cai() /*3* fact*=i-; void Fn:disp() coutvalue“!=“factendl; void main() int value; cout“Enter the value:“; cinvalue; Fn A(value); /*4* (分数:-1.00)_正确答案:(1) int value; int fact; (2) value=i; fact=1; (3) int i=value; while(i1) (4) A.Cal(); A.disp();)解析:解析 主要考查考生对类和对象的综合掌握,该题涉及类的成员对象与成员函数的定义,类成员函数的外部调用等知识点。注意(3)中 while语句的使用,当满足括号中表达式的条件时,就一直执行后面或者后面花括号中的语句,直到不满足时跳出。

展开阅读全文
相关资源
猜你喜欢
  • EN 50288-2-1-2013 en Multi-element metallic cables used in analogue and digital communication and control - Part 2-1 Sectional specification for screened cables characterised up to.pdf EN 50288-2-1-2013 en Multi-element metallic cables used in analogue and digital communication and control - Part 2-1 Sectional specification for screened cables characterised up to.pdf
  • EN 50288-2-2-2013 en Multi-element metallic cables used in analogue and digital communication and control - Part 2-2 Sectional specification for screened cables characterised up to.pdf EN 50288-2-2-2013 en Multi-element metallic cables used in analogue and digital communication and control - Part 2-2 Sectional specification for screened cables characterised up to.pdf
  • EN 50288-3-1-2003 en Multi-element metallic cables used in analogue and digital communication and control Part 3-1 Sectional specification for unscreened cables characterised up to.pdf EN 50288-3-1-2003 en Multi-element metallic cables used in analogue and digital communication and control Part 3-1 Sectional specification for unscreened cables characterised up to.pdf
  • EN 50288-3-2-2013 en Multi-element metallic cables used in analogue and digital communication and control - Part 3-2 Sectional specification for unscreened cables characterised up .pdf EN 50288-3-2-2013 en Multi-element metallic cables used in analogue and digital communication and control - Part 3-2 Sectional specification for unscreened cables characterised up .pdf
  • EN 50288-4-1-2003 en Multi-element metallic cables used in analogue and digital communication and control Part 4-1 Sectional specification for screened cables characterised up to 6.pdf EN 50288-4-1-2003 en Multi-element metallic cables used in analogue and digital communication and control Part 4-1 Sectional specification for screened cables characterised up to 6.pdf
  • EN 50288-4-2-2013 en Multi-element metallic cables used in analogue and digital communication and control - Part 4-2 Sectional specification for screened cables characterised up to.pdf EN 50288-4-2-2013 en Multi-element metallic cables used in analogue and digital communication and control - Part 4-2 Sectional specification for screened cables characterised up to.pdf
  • EN 50288-5-1-2013 en Multi-element metallic cables used in analogue and digital communication and control - Part 5-1 Sectional specification for screened cables characterized up to.pdf EN 50288-5-1-2013 en Multi-element metallic cables used in analogue and digital communication and control - Part 5-1 Sectional specification for screened cables characterized up to.pdf
  • EN 50288-5-2-2013 en Multi-element metallic cables used in analogue and digital communication and control - Part 5-2 Sectional specification for screened cables characterized up to.pdf EN 50288-5-2-2013 en Multi-element metallic cables used in analogue and digital communication and control - Part 5-2 Sectional specification for screened cables characterized up to.pdf
  • EN 50288-6-1-2013 en Multi-element metallic cables used in analogue and digital communication and control - Part 6-1 Sectional specification for unscreened cables characterised up .pdf EN 50288-6-1-2013 en Multi-element metallic cables used in analogue and digital communication and control - Part 6-1 Sectional specification for unscreened cables characterised up .pdf
  • 相关搜索

    当前位置:首页 > 考试资料 > 职业资格

    copyright@ 2008-2019 麦多课文库(www.mydoc123.com)网站版权所有
    备案/许可证编号:苏ICP备17064731号-1