【计算机类职业资格】国家二级C++机试(操作题)模拟试卷333及答案解析.doc
《【计算机类职业资格】国家二级C++机试(操作题)模拟试卷333及答案解析.doc》由会员分享,可在线阅读,更多相关《【计算机类职业资格】国家二级C++机试(操作题)模拟试卷333及答案解析.doc(5页珍藏版)》请在麦多课文档分享上搜索。
1、国家二级 C+机试(操作题)模拟试卷 333 及答案解析(总分:10.00,做题时间:90 分钟)一、基本操作题(总题数:1,分数:2.00)1.请使用 VC6 或使用【答题】菜单打开考生文件夹 proj1 下的工程 projl。程序中位于每个“ERROR*found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为: value=63 number=1 注意:只修改每个“ERROR*found*”下的那一行,不要改动程序中的其他内容。#includeiostreamusing namespace std;class MyClasS int*P; const int N;publi
2、c:ERROR*found* MyClass(int val):N=1 P=new int; *P=val; ERROR*found* 一 MyClass()delete*P;) friend void print(MyClassobj);;ERROR* found*void MyClass:print(MyClassobj) cout”value=”* (objP) end1; cout”number=” objNend1;int main() MyClass obj(63);print(obj); return 0;(分数:2.00)_二、简单应用题(总题数:2,分数:4.00)2.请使用
3、 VC6 或使用【答题】菜单打开考生文件夹 proj2 下的工程 proj2。该工程中包含一个程序文件maincpp,其中有“书”类 Book 及其派生出的“教材”类 TeachingMaterial 的定义,还有主函数 main的定义。请在程序中“*found*”下的横线处填写适当的代码,然后删除横线,以实现上述类定义和函数定义。此程序的正确输出结果应为: 教材名:C+语言程序设计 页 数:299 作 者:张三 相关课程:面向对象的程序设计 注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“*found*”。#includeiostreamusing namesp
4、ace std;claSS Book “书”类 char*title;/书名 int num_pages;页数 char*writer; 作者姓名 public: Book(const char*the title,int pages,const char*thewriter):num_pages(pages) title=new charstrlen(the title)+1; strcpy(title,the_title); *found* strcpy(writer,the_writer); /*found* 一 Book()_ int numOfPages()constreturn n
5、umpaqes;) 返回书的页数 const char*theTitle()constre-turn title;) 返回书名 const char*theWriter()constre-turn writer; 返回作者名,class TeachingMaterial:public Book“教材”类 char*course;public: TeachingMaterial(const char*the title,int pages,const char*the writer,const char*the course)*found* :_ course=new charstrlen(th
6、e course)+1; strcpy(course,the course); TeachingMaterial()deletecourse; const char*theCourse()constre-turn course;) 返回相关课程的名称;int main()TeachingMaterial a book(”C+语言程序设计”,299,“张三”,”面向对象的程序设计”); cout“教材名:“a booktheTitle()end1 ”页数:”abooknumOfPages()endl ”作 者:”a booktheWriter()end1 /*found*”相关课程:”_; co
7、utend1; return 0;(分数:2.00)_3.请使用 VC6 或使用【答题】菜单打开考生文件夹 proj2 下的工程 proj2,该工程中含有一个源程序文件proj2cpp,请将堆栈类的定义补充完整。使程序的输出结果为: The element of stack are:4 3 2 1 注意:请勿修改主函数 main 和其他函数中的任何内容,只在横线处编写适当代码,不要改动程序中的其他内容,也不要删除或移动“*found*”。proj2cpp#includeiostreamus ing namespace std;const int Size=5;class Stack;class
8、 Iternpublic:/*found*Item(const int)构造函数 对 item 进行初始化 private: int item; Item*next; friend class Stack; ; class Stack public: Stack():top(NULL) 一 Stack(); int Pop(); void Push(const int*found* _; 释放 P 所指向的节点 p=q; int Stack:Pop() Item*temp; int ret;/*found* _; 使 temp 指向栈顶节点 ret=top一item; top=top 一nex
9、t; delete temp; return ret;void Stack:Push(const intval) Item*temp=new Item(val);/*found*_;使新节点的 next 指针指向栈顶数据 top=temp;int main() Stack s; for(int i=1;iSize;i+) sPush(i); cout”The element of stack are:”; for(i=1;iSize;i+) coutsPop()t; return 0 ;(分数:2.00)_三、综合应用题(总题数:2,分数:4.00)4.请使用 VC6 或使用【答题】菜单打开考
10、生文件夹 proj3 下的工程 proj3,其中声明的 DataList 类,是一个用于表示数据表的类。sort 成员函数的功能是将当前数据表中的元素升序排列。请编写这个 sort 函数。程序的正确输出应为: 排序前:7,1,3,11,6,9,12,10,8,4,5,2 排序后:1,2,3,4,5,6,7,8,9,10,11,12 要求: 补充编制的内容写在“*333*”与“*666*”两行之间。不得修改程序的其他部分。注意:程序最后将结果输出到文件 outdat 中。输出函数 writeToFile 已经编译为 obj 文件,并且在本程序调用。/DataListh#includeiostre
11、amusing namespace std;class DataList数据表类 int len; double*d;public: DataList(int len,double data=NULL); 一 DataList()deleted;) int length()constreturn len;)数据表长度(即数据元素的个数) double getElement(int i)constre-turn di; void sort();数据表排序 void show()const;显示数据表 ; void writeToFile (char *, const DataList); mai
12、ncpp #include”DataListh DataList:DataList(int len,double data):len(len) d=new double1en; for(int i=0;ilen;i+) di=(data=NULL?00:data i); void DataList:sort()数据表排序 *333* *666* void DataList:show()const /显示数据表 for(int i=0;ilen 一 1;i+)coutdi“,“; coutdlen 一 1endl; int main() double S=7,1,3,11,6,9,12,10,8
13、,4,5,2; DataList list(12,s); COUt“排序前:“; listshow(); listsort(); coutendl“排序后:“; listshow(); writeToFile(”,list); return 0; (分数:2.00)_5.请使用 VC6 或使用【答题】菜单打开考生目录 proj3 下的工程文件 proj3,此工程中包含一个源程序文件 proj3cpp,其功能是从文本文件 indat 中读取全部整数,将整数序列存放到 intArray 类的对象中,然后建立另一对象 myArray,将对象内容赋值给 myArray。类 intArray 重载了“=
14、”运算符。程序中给出了一个测试数据文件 input,不超过 300 个的整数。程序的输出是: 10 11 13 16 20 要求: 补充编制的内容写在“*333*”与“*666*”之间。实现重载赋值运算符函数,并将赋值结果在屏幕输出。格式不限。不得修改程序的其他部分。 注意:程序最后将结果输出到文件 outdat 中。输出函数 writeToFile 已经编译为 obj 文件,并且在本程序中调用。/intArray,hclas S intArrayprivate: int*array; int length;public: intArray(char*filename); intArray()
15、; intArrayvoid writeToFile(const char*path);maincpp#includeioStream#includefstream#includecstring#include”intArrayh”using namespace std;intArray:intArray() length=10; array=new intlength;intArray:intArray(char*filename) ifstream myFile(filename); array=new int300; length=0; while(myFilearray1ength+)
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
5000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 职业资格 国家 二级 机试 操作 模拟 试卷 333 答案 解析 DOC
