ImageVerifierCode 换一换
格式:DOC , 页数:4 ,大小:41KB ,
资源ID:1324116      下载积分:5000 积分
快捷下载
登录下载
邮箱/手机:
温馨提示:
如需开发票,请勿充值!快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝扫码支付 微信扫码支付   
注意:如需开发票,请勿充值!
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【http://www.mydoc123.com/d-1324116.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(【计算机类职业资格】二级C++-60及答案解析.doc)为本站会员(outsidejudge265)主动上传,麦多课文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知麦多课文库(发送邮件至master@mydoc123.com或直接QQ联系客服),我们立即给予删除!

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

1、二级 C+-60及答案解析(总分:100.00,做题时间:90 分钟)一、B基本操作题/B(总题数:1,分数:30.00)1.请使用 VC6或使用答题菜单打开考生文件夹 proj1下的工程 proj1,此工程中含有一个源程序文件proj1.cpp。其中每个注释“/ERROR *found*”之后的一行语句存在错误。请改正这些错误,使程序的输出结果为: The perimeter is 62.8 The area is 314 注意:只修改注释“/ERROR *found*”的下一行语句,不要改动程序中的其他内容。 / proj1.cpp #include iostream using name

2、space std; const double PI=3.14; class Circle public: / ERROR * found* Circle(int r) radius =r; void Display(); private: const int radius; ; /ERROR * found* void Display() cout “The perimeter is“ 2* PI * radius endl; cout “The area is“ PI* radius* radius endl; int main() Circle c(10); /ERROR * found

3、 c:Display(); return 0; (分数:30.00)_二、B简单应用题/B(总题数:1,分数:30.00)2.请使用 VC6或使用答题菜单打开考生文件夹 proj2下的工程 proj2,此工程中含有一个源程序文件proj2.cpp,其中定义了 Sort类和 InsertSort类。Sort 是一个表示排序算法的抽象类,成员函数 mySort为各种排序算法定义了统一的接口,成员函数 swap实现了两个整数的交换操作。InsertSort 是 Sort的派生类,它重新定义了基类中的成员函数 mySort,具体实现了简单插入排序法。本程序的正确输出结果应为: Before sort

4、ing a= 5,1,7,3,1,6,9,4,2,8,6, After sorting a= 1,1,2,3,4,5,6,6,7,8,9, 请首先阅读程序,分析输出结果,然后根据以下要求在横线处填写适当的代码并删除横线,以实现上述功能。 (1)将 Sort类的成员函数 swap补充完整,实现两个整数的交换操作; (2)将 InsertSort类的构造函数补充完整; (3)将 InsertSort类的成员函数 mySort补充完整,实现简单插入排序法(在交换数据时,请使用基类的成员函数 swap)。 注意:只在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“/*found *”

5、 /proj2.cpp #include iostream using namespace std; class Sort public: Sort (int* a0, int n0): a (a0), n(n0) virtual void mySort() = 0; static swap(int /* found* _; y = tmp; protected: int* a; int n; ; class InsertSort : public Sort public: InsertSort(int* a0, int n0) /* found* :_ virtual void mySor

6、t() for(int i =1; in; +i) for(int j = i; j0; -j) if(aj aj-i) /* found* _; else /* found* _; ; void fun (Sort void print (int * a, int n) for(int i = 0; in; +i) cout ai “,“; cout endl; int main(int argc, char * argv) int a =5, 1, 7, 3, 1, 6, 9, 4, 2, 8, 6; cout “Before sorting a = /n“; print(a, 11);

7、InsertSort bs(a, 11); fun(bs); cout “After sorting a = /n“; print(a, ii); return 0; (分数:30.00)_三、B综合应用题/B(总题数:1,分数:40.00)3.请使用 VC6或使用答题菜单打开考生文件夹 proj3下的工程文件 proj3。本题创建一个小型字符串类,字符串长度不超过 100。程序文件包括 proj3.h、proj3.cpp、writeToFile.obj。补充完成 proj3.h,重载复合赋值运算符+=。 要求: 补充编制的内容写在“/*333*”与“/*666*”之间,不得修改程序的其他部分

8、 注意:程序最后将结果输出到文件out.dat中。输出函数 writeToFile已经编译为 obj文件,并且在本程序中调用。 /proj3.h #include iostream #include iomanip using namespace std; class MiniString public: friendostream return output; friend istream /用于输入的临时数组 temp0 = /0; input setw(100 ) temp; int inLen = strlen(temp); /输入字符串长度 if( inLen!= 0) s.len

9、gth = inLen; /赋长度 if( s.sPtr! = 0) delete s.sPtr; s.sPtr = new char s.length + 1; strcpy( s.sPtr, temp ); /如果 s不是空指针,则复制内容 else s.sPtr 0 = /0; /如果 s是空指针,则为空字符串 return input; MiniString ( const char * s=“):length ( s!= 0 )?strlen(s) : 0 ) setString(s ); MiniString() delete sPtr; /析构函数 /* 333* /+=运算符重

10、载 /* 666* private: int length; /字符串长度 char * sPtr; /指向字符串起始位置 void setString( const char * string2 ) /辅助函数 sPtr = new char length + 1; /分配内存 if ( string2 ! = 0 ) strcpy( sPtr, string2 ); /如果 string2不是空指针,则复制内容 else smtr 0 = /0; /如果 string2是空指针,则为空字符串 ; /proj3.cpp #include iostream #include iomanip u

11、sing namespace std; #include “proj3.h“ int main () MiniString str1 (“World“), str2 (“Hello“) ; void writeToFile (char * ) ; str2 + = str1; /使用重载的+=运算符 cout str2 “/n“; writeToFile (“); return 0; (分数:40.00)_二级 C+-60答案解析(总分:100.00,做题时间:90 分钟)一、B基本操作题/B(总题数:1,分数:30.00)1.请使用 VC6或使用答题菜单打开考生文件夹 proj1下的工程 p

12、roj1,此工程中含有一个源程序文件proj1.cpp。其中每个注释“/ERROR *found*”之后的一行语句存在错误。请改正这些错误,使程序的输出结果为: The perimeter is 62.8 The area is 314 注意:只修改注释“/ERROR *found*”的下一行语句,不要改动程序中的其他内容。 / proj1.cpp #include iostream using namespace std; const double PI=3.14; class Circle public: / ERROR * found* Circle(int r) radius =r;

13、void Display(); private: const int radius; ; /ERROR * found* void Display() cout “The perimeter is“ 2* PI * radius endl; cout “The area is“ PI* radius* radius endl; int main() Circle c(10); /ERROR * found* c:Display(); return 0; (分数:30.00)_正确答案:(1)Circle(int r):radius(r) (2)void Circle:Display() (3)

14、c.Display();)解析:考点 本题考查 Circle类,其中涉及构造函数、常变量私有成员和成员函数。 解析 (1)主要考查考生对构造函数的掌握,常变量私有成员只能通过成员列表进行初始化。 (2)主要考查考生对成员函数的掌握,在定义类的成员函数时要加上类名和作用域符。 (3)主要考查考生对成员函数调用的掌握,调用成员函数时应使用标识符“.”。二、B简单应用题/B(总题数:1,分数:30.00)2.请使用 VC6或使用答题菜单打开考生文件夹 proj2下的工程 proj2,此工程中含有一个源程序文件proj2.cpp,其中定义了 Sort类和 InsertSort类。Sort 是一个表示排

15、序算法的抽象类,成员函数 mySort为各种排序算法定义了统一的接口,成员函数 swap实现了两个整数的交换操作。InsertSort 是 Sort的派生类,它重新定义了基类中的成员函数 mySort,具体实现了简单插入排序法。本程序的正确输出结果应为: Before sorting a= 5,1,7,3,1,6,9,4,2,8,6, After sorting a= 1,1,2,3,4,5,6,6,7,8,9, 请首先阅读程序,分析输出结果,然后根据以下要求在横线处填写适当的代码并删除横线,以实现上述功能。 (1)将 Sort类的成员函数 swap补充完整,实现两个整数的交换操作; (2)将

16、 InsertSort类的构造函数补充完整; (3)将 InsertSort类的成员函数 mySort补充完整,实现简单插入排序法(在交换数据时,请使用基类的成员函数 swap)。 注意:只在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“/*found *”。 /proj2.cpp #include iostream using namespace std; class Sort public: Sort (int* a0, int n0): a (a0), n(n0) virtual void mySort() = 0; static swap(int /* found*

17、 _; y = tmp; protected: int* a; int n; ; class InsertSort : public Sort public: InsertSort(int* a0, int n0) /* found* :_ virtual void mySort() for(int i =1; in; +i) for(int j = i; j0; -j) if(aj aj-i) /* found* _; else /* found* _; ; void fun (Sort void print (int * a, int n) for(int i = 0; in; +i) c

18、out ai “,“; cout endl; int main(int argc, char * argv) int a =5, 1, 7, 3, 1, 6, 9, 4, 2, 8, 6; cout “Before sorting a = /n“; print(a, 11); InsertSort bs(a, 11); fun(bs); cout “After sorting a = /n“; print(a, ii); return 0; (分数:30.00)_正确答案:(1)x=y (2)Sort(a0, n0) (3)swap(aj, aj-1) (4)break)解析:考点 本题考查

19、Sort类及其派生类 InsertSort,其中涉及动态数组、构造函数和纯虚函数。 解析 (1)主要考查考生对成员函数的掌握,题目要求将 Sort类的成员函数 swap补充完整,实现两个整数的交换操作,因此这里是个交换操作,程序利用中问变量 tmp交换 x和 y的值。 (2)主要考查考生对构造函数的掌握,派生类的构造函数使用成员列表初始化基类。 (3)主要考查考生对成员函数调用的掌握,题目提示:在交换数据时,请使用基类的成员函数 swap。因此这里可以直接调用 swap函数交换 aj和aj-1的值。 (4)主要考查考生对成员函数的掌握,当条件 ajaj-1不满足时,说明顺序没问题不需要交换,使

20、用 break语句跳出本次循环。三、B综合应用题/B(总题数:1,分数:40.00)3.请使用 VC6或使用答题菜单打开考生文件夹 proj3下的工程文件 proj3。本题创建一个小型字符串类,字符串长度不超过 100。程序文件包括 proj3.h、proj3.cpp、writeToFile.obj。补充完成 proj3.h,重载复合赋值运算符+=。 要求: 补充编制的内容写在“/*333*”与“/*666*”之间,不得修改程序的其他部分。 注意:程序最后将结果输出到文件out.dat中。输出函数 writeToFile已经编译为 obj文件,并且在本程序中调用。 /proj3.h #incl

21、ude iostream #include iomanip using namespace std; class MiniString public: friendostream return output; friend istream /用于输入的临时数组 temp0 = /0; input setw(100 ) temp; int inLen = strlen(temp); /输入字符串长度 if( inLen!= 0) s.length = inLen; /赋长度 if( s.sPtr! = 0) delete s.sPtr; s.sPtr = new char s.length +

22、1; strcpy( s.sPtr, temp ); /如果 s不是空指针,则复制内容 else s.sPtr 0 = /0; /如果 s是空指针,则为空字符串 return input; MiniString ( const char * s=“):length ( s!= 0 )?strlen(s) : 0 ) setString(s ); MiniString() delete sPtr; /析构函数 /* 333* /+=运算符重载 /* 666* private: int length; /字符串长度 char * sPtr; /指向字符串起始位置 void setString( c

23、onst char * string2 ) /辅助函数 sPtr = new char length + 1; /分配内存 if ( string2 ! = 0 ) strcpy( sPtr, string2 ); /如果 string2不是空指针,则复制内容 else smtr 0 = /0; /如果 string2是空指针,则为空字符串 ; /proj3.cpp #include iostream #include iomanip using namespace std; #include “proj3.h“ int main () MiniString str1 (“World“), s

24、tr2 (“Hello“) ; void writeToFile (char * ) ; str2 + = str1; /使用重载的+=运算符 cout str2 “/n“; writeToFile (“); return 0; (分数:40.00)_正确答案:(MiniString /给 pt动态分配 length+1大小的空间 strcpy(pt, sPtr); /把字符串 sptr复制到 pt中 int blength=length; /把 length赋值给 blength length+=s.length; /把对象 s中 length加到 length中 deletesPtr; /

25、删除字符串 SPtr sPtr=new charlength+1; /给 sptr分配 length+1大小的内存空间 strcpy(sPtr, pt); /把 pt复制到 Sptr中 deletept; /删除字符串 pt for(int i=0; ilength; +i) /遍 s中的 sptr数组,并且把字符拷到 sptr 中 sPtrblength+i=s.sPtr i; return*this; /返回 this对象 )解析:考点 本题考查 MinString类,其中涉及构造函数、运算符重载、动态数组和析构函数。 解析 主要考查考生对运算符重载的掌握,因为有动态数组,所以要使用 new语句来重新分配空间。

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