【计算机类职业资格】国家二级C++机试(操作题)模拟试卷342及答案解析.doc
《【计算机类职业资格】国家二级C++机试(操作题)模拟试卷342及答案解析.doc》由会员分享,可在线阅读,更多相关《【计算机类职业资格】国家二级C++机试(操作题)模拟试卷342及答案解析.doc(5页珍藏版)》请在麦多课文档分享上搜索。
1、国家二级 C+机试(操作题)模拟试卷 342及答案解析(总分:8.00,做题时间:90 分钟)一、基本操作题(总题数:1,分数:2.00)1.请使用 VC6或使用【答题】菜单打开考生文件夹 projl下的工程 projl,其中在编辑窗口内显示的主程序文件中定义有类 ABC和主函数 main。程序文本中位于每行“ERROR*found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应该是: 21 23 注意:只修改每个“ERROR*found*”下面的一行,不要改动程序中的其他任何内容。#includeiostreamUSing namespace std;class ABCpubli
2、c:ERROR*found* ABC()a=0;b=0;c=0; ABC(int aa,int bb,int:CC); void Setab() +a,+b;) int Sum()return a+b+C;)private: int a,b; const int C;,ABC:ABC(int aa, int bb, int cc):c(CC)a=aa;b=bb;)int main() ABC X(1,2,3),y(4,5,6); ABC Z,*w= private: int level; ; void Employee:print()const cout”Name:”name endl; co
3、ut”Dept:”dept 一endl; VOid Manager:print()const *found* cout ”Level:” level endl;int main() Employee*emp=new Manager(”Sally Smith”,”Sales”,2); emp 一print(); delete emp;return 0;(分数:2.00)_三、综合应用题(总题数:2,分数:4.00)3.请使用 VC6或使用【答题】菜单打开考生文件夹 proj3下的工程文件 proj3。本题创建一个小型字符串类,字符串长度不超过 100。程序文件包括 proj3h、proj3cpp
4、、writeToFileobj。补充完成重载赋值运算符函数,完成深复制功能。 屏幕上输出的正确结果应该是: Hello! Happy new year! 要求: 补充编制的内容写在“*333*”与“*666*”两行之间。不得修改程序的其他部分。 注意: 程序最后调用 writeToFile函数,使用另一组不同的测试数据,将不同的运行结果输出到文件 outdat 中。输出函数 writeToFile已经编译为 obj文件。proj3h#includeiostream#includeiomanipusing namespace std;class MiniString public: friend
5、 ostream如果 string2是空指针,则为空字符串 MiniStringoperator=(const MiniStringotherString); MiniString(const char*s =”):length(S!=0)?strlen(S):0)构造函数 sPtr=0; if(length!=0) setString(S); 一 MiniString()析构函数 deletesPtr; private: int length;字符串长度 char*sPtr; 指向字符串起始位置 void setString( const char *string2 /辅助函数 sPtr=n
6、ew charstrlen(string2)+1; 分配内存 if(string2!=0)strcpy(SPtr,string2);如果 string2不是空指针,则复制内容 else sPtr0=0;如果 string2是空指针,则为空字符串 ;proj3cpp#includeiostream#includeiomanipusing namespace std;#include”proj 3h”MiniString使用重载的赋值运算符str2modString(”Happy new year!”); coutstr1n;coutstr2n;writeToFile(”);return 0;(分
7、数:2.00)_4.请使用 VC6或使用【答题】菜单打开考生目录 proj3下的工程文件 proj3,此工程包含一个源程序文件proj3cpp,其功能是从文本文件 indat 中读取全部整数,将整数序列存放到 intArray类的对象myArray中,然后对整数序列按非递减排序,最后由函数 writeToFile选择序列中的部分数据输出到文件outdat 中。文件 indat 中的整数个数不大于 300个。 要求: 补充编制的内容写在“*333*”与“*666*”两行之间。实现对整数序列按非递减排序,并将排序结果在屏幕上输出。不得修改程序的其他部分。 注意:程序最后已将结果输出到文件 outd
8、at 中。输出函数 writeToFile已经给出并且调用。/proj 3cpp#includeiostream#includefstream#includecstringusing namespace std;class intArrayprivate: int*array;整数序列首地址 int length;序列中的整数个数 public: 构造函数,从文件中读取数据用于初始化新对象。参数是文件名 intArray(char*filename); void sort();对整数序列按非递减排序 一 intArray(); void writeTOFile(char*filename);
9、; intArray:intArray(char*filename) ifstream myFile(filename); int len=300; array=new int1en; length=0; while(myFilearraylength+); length-; myFileclose(); void intArray:sort() *333* *666* intArray:-intArray() deletearray;void intArray:writeToFile(char*filename) int step=0; ofstream outFile(filename);
10、 for(int i=0;ilength;i=i+step) outFilearrayiendl; step+; outFileclose(); void main() intArray myArray(”indat”); myArraysort(); myArraywriteTOFile(”outdat”); (分数:2.00)_国家二级 C+机试(操作题)模拟试卷 342答案解析(总分:8.00,做题时间:90 分钟)一、基本操作题(总题数:1,分数:2.00)1.请使用 VC6或使用【答题】菜单打开考生文件夹 projl下的工程 projl,其中在编辑窗口内显示的主程序文件中定义有类 A
11、BC和主函数 main。程序文本中位于每行“ERROR*found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应该是: 21 23 注意:只修改每个“ERROR*found*”下面的一行,不要改动程序中的其他任何内容。#includeiostreamUSing namespace std;class ABCpublic:ERROR*found* ABC()a=0;b=0;c=0; ABC(int aa,int bb,int:CC); void Setab() +a,+b;) int Sum()return a+b+C;)private: int a,b; const int C;
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
5000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 职业资格 国家 二级 机试 操作 模拟 试卷 342 答案 解析 DOC
