【计算机类职业资格】二级C++分类模拟89及答案解析.doc

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

1、二级 C+分类模拟 89 及答案解析(总分:100.00,做题时间:90 分钟)一、程序改错题(总题数:1,分数:30.00)1.使用 VC6 打开 下的源程序文件 modi1.cpp,该程序运行时有错误,请改正程序中的错误,使得程序输出: 1,2,3,4,5, 注意:不要改动 main 函数,不能增行或删行,也不能更改程序的结构,错误的语句在/*error*的下面。 #include iostream. h class TestClass /*error* TestClass(int i) m_i = i; void print() cout public : int m_i; ; int

2、main () /*error* int i(); TestClass data(0); while(i5) /*error* i+; data.print(); (分数:30.00)_二、程序填空题(总题数:1,分数:30.00)2.使用 VC6 打开 下的源程序文件 modi2.cpp。请实现函数 fun(double b,int len)的如下功能: (1)b是一个数组,长度为 len; (2)b0=0,b1=1; (3)bi+2=bi+bi+1; 注意:请勿改动主函数 main 与其他函数中的任何内容,仅在函数 fun 的花括号中填入所编写的若干语句。#include iostream

3、 void fun(double b,int len) void main() double b128; fun (b, 128); for (int i=0; i128;i+) if (i%6 = 5) std: cout (分数:30.00)_三、程序设计题(总题数:1,分数:40.00)3.使用 VC6 打开 下的源程序文件 modi3.cpp,其中定义了用于表示日期的类 Date,但类 Date 的定义并不完整。请按要求完成下列操作,将类 Date 的定义补充完成。 (1)定义私有数据成员 year、month 和 day,分别用于表示年、月和日,它们都是 int 型的数据。请在注释/

4、*1*之后添加适当的语句。 (2)完成默认构造函数 Date 的定义,使 Date 对象的默认值为:year=1,month=1,day=1,请在注释*2*之后添加适当的语句。 (3)完成重载构造函数 Date(int y,int m,hat d)的定义,把数据成员 year、month 和 day 分别初始化为参数 y、m 和 d 的值,请在注释/*3*之后添加适当的语句。 (4)完成成员函数 print()的类外定义,使其以“年-月-日”的格式将 Date 对象的值输出到屏幕上,例如:2008-8-8。请在注释/*4*之后添加适当的语句。 注意:仅在函数指定位置添加语句,请勿改动主函数 m

5、ain 与其他函数中的任何内容。 #include iostream.h class Date public: /*2* Date(int y, int m, int d) /*3* void print() const; private: /data member /*1* ; void Date:print() const /*4* int main() Date national_day(1949,10,1); national_day.print(); return 0; (分数:40.00)_二级 C+分类模拟 89 答案解析(总分:100.00,做题时间:90 分钟)一、程序改错题

6、(总题数:1,分数:30.00)1.使用 VC6 打开 下的源程序文件 modi1.cpp,该程序运行时有错误,请改正程序中的错误,使得程序输出: 1,2,3,4,5, 注意:不要改动 main 函数,不能增行或删行,也不能更改程序的结构,错误的语句在/*error*的下面。 #include iostream. h class TestClass /*error* TestClass(int i) m_i = i; void print() cout public : int m_i; ; int main () /*error* int i(); TestClass data(0); wh

7、ile(i5) /*error* i+; data.print(); (分数:30.00)_正确答案:()解析:public:TestClass(int i) (2)int i(10); (3)i-; 答案考生文件夹 解析 程序要求输出 1,2,3,4,5,。主函数 main()中有 while 循环,调用类 TestClass 中的成员函数 print()实现函数功能。 (1)打开 moid1.cpp 调试程序,显示错误提示为第一标识下“modi1.cpp(20):error C2248:“TestClass:TestClass“:cannotaccess private member de

8、clared in class“TestClass“,提示类 TestClass 中的构造函数 TestClass 被定义为私有的,无法获得,所以这里应该是 public,即“public:TestClass(int i)”。 (2)题目中要求输出结果为 1,2,3,4,5,即循环 5 次。第三个表示 while 循环条件是 i 大于 5 就进行循环。“int 10;”应该实现变量 i 的初始化,题干中要求不能删除 i 初始化中的括号,所以在括号中添加 i 的初始值。大于 5 且循环 5 次,所以 i 的初始值为 10,而 while 循环中对 i 的操作应该是 i-,这样第二个和第三个标示下

9、应该是“int i(10);”和“i-;”。二、程序填空题(总题数:1,分数:30.00)2.使用 VC6 打开 下的源程序文件 modi2.cpp。请实现函数 fun(double b,int len)的如下功能: (1)b是一个数组,长度为 len; (2)b0=0,b1=1; (3)bi+2=bi+bi+1; 注意:请勿改动主函数 main 与其他函数中的任何内容,仅在函数 fun 的花括号中填入所编写的若干语句。#include iostream void fun(double b,int len) void main() double b128; fun (b, 128); for

10、(int i=0; i128;i+) if (i%6 = 5) std: cout (分数:30.00)_正确答案:()解析:if(len0)/最小值位置 b0=0; /赋值第一个元素 if(1en1) b1=1; /赋值第二个元素 for(int i=2; i18n; i+) bi=bi-1+bi-2; /将两个元素之和赋予当前元素 答案考生文件夹 解析 根据题干中给出的要求,从已给部分源程序的 main 主函数开始入手,补全函数 void tim(double b, int len)。 (1)判断数组长度,如果存在第一个元素,那么将第一个元素赋值为 0,即 b0=0;。 (2)然后再判断数

11、组长度,如果存在第二个元素,那么将第二个元素赋值为 1,即 b1=1;。 (3)最后从第三个元素到数组最后一个元素,赋值 bi=bi-1+bi-2;。三、程序设计题(总题数:1,分数:40.00)3.使用 VC6 打开 下的源程序文件 modi3.cpp,其中定义了用于表示日期的类 Date,但类 Date 的定义并不完整。请按要求完成下列操作,将类 Date 的定义补充完成。 (1)定义私有数据成员 year、month 和 day,分别用于表示年、月和日,它们都是 int 型的数据。请在注释/*1*之后添加适当的语句。 (2)完成默认构造函数 Date 的定义,使 Date 对象的默认值为

12、:year=1,month=1,day=1,请在注释*2*之后添加适当的语句。 (3)完成重载构造函数 Date(int y,int m,hat d)的定义,把数据成员 year、month 和 day 分别初始化为参数 y、m 和 d 的值,请在注释/*3*之后添加适当的语句。 (4)完成成员函数 print()的类外定义,使其以“年-月-日”的格式将 Date 对象的值输出到屏幕上,例如:2008-8-8。请在注释/*4*之后添加适当的语句。 注意:仅在函数指定位置添加语句,请勿改动主函数 main 与其他函数中的任何内容。 #include iostream.h class Date p

13、ublic: /*2* Date(int y, int m, int d) /*3* void print() const; private: /data member /*1* ; void Date:print() const /*4* int main() Date national_day(1949,10,1); national_day.print(); return 0; (分数:40.00)_正确答案:()解析:添加语句:int year,month,day; (2)添加语句:Date()year=1;month=1;day=1;) (3)添加语句:year=y;month=m;

14、day=d; (4)添加语句:cout year “-“ month “-“ day endl; 答案考生文件夹 解析 在 VC 环境下打开程序,根据题干给出的几条功能要求,对程序中给出注释下的内容逐个补全或修改。从已给定源程序的 main 主函数开始入手,可以看出程序通过调用类 Date 和函数print 实现各种输出操作。 (1)题目 1 要求“定义私有数据成员 year、month 和 day,分别用于表示年、月和日,它们都是 int 型的数据”。在 C+程序的 private 区域中添加变量 year、month、day 的定义,即在第 1 个标识下添加“int year,month,

15、day;”。 (2)题目 2 要求“完成默认构造函数 Date 的定义,使 Date 对象的默认值为:year=1,month=1,day=1”。在 C+中,构造函数是一种特殊的成员函数,它的名字与类同名。在 Date 构造函数体内,根据题目要求,设置变量默认值“year=1,month=1,day=1”,即:“Date()year=1;month=1;day=1;”。 (3)题目 3 要求“完成重载构造函数 Date(int y,int m,int d)的定义,把数据成员 year、month 和 day分别初始化为参数 y、m 和 d 的值。”在构造函数 Date(int y,int m,int d)函数体内,即标识 3 下,添加赋值语句,将 y,m,d 赋值给 year,month,day,即“year=y;month=m;day=d;”。 (4)题目 4 要求“完成成员函数 print()的类外定义,使其以“年-月-日”的格式将 Date 对象的值输出到屏幕上”。在程序中的 voidDate:print()const 函数体内,标识 4 下,添加输出语句。根据 cout 输出格式,实现题目中的输出要求,即“cout year“-“ dav

展开阅读全文
相关资源
猜你喜欢
  • NF R12-204-1988 Commercial vehicles and buses Gearbox flanges Type A 《运输车辆和客车 变速箱法兰 A型》.pdf NF R12-204-1988 Commercial vehicles and buses Gearbox flanges Type A 《运输车辆和客车 变速箱法兰 A型》.pdf
  • NF R12-205-1988 Commercial vehicles and buses Gearbox flanges Type S 《运输车辆和客车 变速箱法兰 S型》.pdf NF R12-205-1988 Commercial vehicles and buses Gearbox flanges Type S 《运输车辆和客车 变速箱法兰 S型》.pdf
  • NF R12-403-1987 Commercial road vehicles Commercial vehicles Side openings for truck power take-offs 《商用道路车辆 货车侧向动力输出轴》.pdf NF R12-403-1987 Commercial road vehicles Commercial vehicles Side openings for truck power take-offs 《商用道路车辆 货车侧向动力输出轴》.pdf
  • NF R12-613-1988 Road vehicles Brake linings Internal shear strength of lining material Test procedure 《道路车辆 制动磨擦片 磨擦法抗剪强度 试验规程》.pdf NF R12-613-1988 Road vehicles Brake linings Internal shear strength of lining material Test procedure 《道路车辆 制动磨擦片 磨擦法抗剪强度 试验规程》.pdf
  • NF R12-615-1988 Road vehicles Brake linings Effects of heat on dimensions and form of disc brake pads Test procedure 《道路车辆 制动磨擦片 闸瓦发热效应 试验方法》.pdf NF R12-615-1988 Road vehicles Brake linings Effects of heat on dimensions and form of disc brake pads Test procedure 《道路车辆 制动磨擦片 闸瓦发热效应 试验方法》.pdf
  • NF R12-616-1988 Road vehicles Brake linings Resistance to water saline solution oil and brake fluid Test procedure 《道路车辆 制动磨擦片 抗水性、抗碱溶液性、抗油脂和抗制动液性能 试验规程》.pdf NF R12-616-1988 Road vehicles Brake linings Resistance to water saline solution oil and brake fluid Test procedure 《道路车辆 制动磨擦片 抗水性、抗碱溶液性、抗油脂和抗制动液性能 试验规程》.pdf
  • NF R12-617-1988 Road vehicles Brake linings Seizure to ferrous mating surface due to corrosion Test procedure 《道路车辆 制动器磨擦片 硬金属表面的粘连性 试验规程》.pdf NF R12-617-1988 Road vehicles Brake linings Seizure to ferrous mating surface due to corrosion Test procedure 《道路车辆 制动器磨擦片 硬金属表面的粘连性 试验规程》.pdf
  • NF R12-618-1997 Road vehicles Brake hose assemblies for hydraulic braking systems used with a non-petrolum-base brake fluid 《道路车辆 与非石油基制动液一起使用的压液制动系统用制动软管组件》.pdf NF R12-618-1997 Road vehicles Brake hose assemblies for hydraulic braking systems used with a non-petrolum-base brake fluid 《道路车辆 与非石油基制动液一起使用的压液制动系统用制动软管组件》.pdf
  • NF R12-619-1997 Road vehicles Brake hose assemblies for hydraulic braking systems used with a petrolum-base brake fluid 《道路车辆 与石油基制动液一起使用的压液制动系统用制动软管组件》.pdf NF R12-619-1997 Road vehicles Brake hose assemblies for hydraulic braking systems used with a petrolum-base brake fluid 《道路车辆 与石油基制动液一起使用的压液制动系统用制动软管组件》.pdf
  • 相关搜索

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

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