【计算机类职业资格】二级C++-60及答案解析.doc
《【计算机类职业资格】二级C++-60及答案解析.doc》由会员分享,可在线阅读,更多相关《【计算机类职业资格】二级C++-60及答案解析.doc(4页珍藏版)》请在麦多课文档分享上搜索。
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;
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
5000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 职业资格 二级 C60 答案 解析 DOC
