【计算机类职业资格】国家二级C++机试(操作题)模拟试卷328及答案解析.doc
《【计算机类职业资格】国家二级C++机试(操作题)模拟试卷328及答案解析.doc》由会员分享,可在线阅读,更多相关《【计算机类职业资格】国家二级C++机试(操作题)模拟试卷328及答案解析.doc(4页珍藏版)》请在麦多课文档分享上搜索。
1、国家二级 C+机试(操作题)模拟试卷 328及答案解析(总分:6.00,做题时间:90 分钟)一、基本操作题(总题数:1,分数:2.00)1.请使用 VC6或使用【答题】菜单打开考生文件夹 projl下的工程 projl,该工程中包含程序文件maincpp,其中有类 Clock(“时钟”)的定义和主函数 main的定义。程序中位于每个“ERROR*found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为: Initial times are 0 d:0 h:0 m:59 s After one second times are 0 d:0 h:1 m:0 s 注意:只修改每个“
2、ERROR*found*”下的那一行,不要改动程序中的其他内容。#includeiostreamusing namespace std;class Clockpublic: Clock(unsigned long i=0); void set(unsigned long i=0); void print()const; void tick();时间前进一秒 Clock operator+();private: unsigned long total_sec,seconds,minutes ,hours, days;Clock:Clock(unsigned long i) :total sec(
3、i),seconds(i60), minutes(i60)60), hours(i3 600)24), days(i8 64 00)void Clock:set(unsigned long i) total sec=i; seconds=i60; minutes=(i60)60; hours=(i3600)60; days=i864 00;ERROR*found*void Clock:print() toutdays”d:”hours”h:” minutes”m:”seconds”s”endl;void Clock:tick()ERROR*found* set(total sec+);Cloc
4、k Clock:operator+() tick();ERROR*found* return ths;int main() Clock ck(59); tout ”Initial timeS aEe” endl; ckprint(); +ck; tout ”After one second timesaEe”endl; ckprint(); return 0;(分数:2.00)_二、简单应用题(总题数:1,分数:2.00)2.使用 VC6打开考生文件夹 proj2下的工程 Proj2,其中有元素类 Element和队列类 Queue的定义。请在程序中的横线处填写适当的代码,然后删除横线,以实现
5、上述类定义。此程序的输出结果应为: 3 8 5 0 5 0 7 注意:只能在横线处填写适当的代码,不要改动程序中的其他内容。#includeiOStream#includecmath#includecstdlibusing namespace std;#define MaxLength i 00 class Element “元素”类 public: int n; Element(int i=0):n(i) ; class Queue “队列”类 Element * element; 指向存储元素的数组的指针 int tail;队尾元素的下标 public: Queue():element(n
6、ew Element100),tail(一 1) 一 Queue()deleteelement; void push(Element ele); 在队列尾端添加一个元素 Element pop();在队列首端删除一个元素,返回被删元素 Element front()constreturn element0;返回队首元素,但不从队列中删除该元素 *found* int size()const return(_);返回元素个数 void show()const,显示集合中所有元素;void Queue:push(Element ele) if(tail=MaxLength一 1) return;空
7、间满,不做任何处理 *found* _;Element Queue:pop() if(Size()=0)exit(1); 队列空,不做任何处理 Element tmp=element0; for(int i=0;itail;i+) elementi=elementi+1; *found* _; return tmp;VOid Queue:show ()const *found* for(_) coutelementin; coutendl;int main() Queue q; qpush(3); qpush(8); qpush(5); qpush(0); qshow(); qpop(); q
8、pop(); qpush(7); qshow(); return 0;(分数:2.00)_三、综合应用题(总题数:1,分数:2.00)3.请使用 VC6或使用【答题】菜单打开考生文件夹 proj3下的工程 proj3,其中使用友元函数访问类的私有数据成员,求出两个数据成员的大于 1的最小公因子。请编写友员函数 FriFun,使其输出结果为:Commnn denominator is 2 要求:补充编制的内容写在“*333*”与“*666*”之间,不得修改程序的其他部分。 注意:程序最后将结果输出到文件outdat 中。输出函数 writeToFile已经编译为 0bj文件,并且在本程序中调用。
9、proj3h clasS FriFunClass int a,b;public: EriFunClass(int i,int j)a=i;b=j;) friend int FriFun(FriFunClass x); /友元函数 ; void writeToFile(const char*);proj3cpp#includeiostreamusing namespace std;#include”prj3h”int FriFun(FriFunClass X)/*333* 由于函数 FriFun()是类 FriFunclass的友元函数,所以它可以直接访问 a和 b*666*int main()
10、 FriFunClass n(10,20);if(FriFun(n) tout;”Common denominat:or iS”FriFun(n) ”n”; else cout:”No commom denominatorn”; writeToFile(”); return 0; (分数:2.00)_国家二级 C+机试(操作题)模拟试卷 328答案解析(总分:6.00,做题时间:90 分钟)一、基本操作题(总题数:1,分数:2.00)1.请使用 VC6或使用【答题】菜单打开考生文件夹 projl下的工程 projl,该工程中包含程序文件maincpp,其中有类 Clock(“时钟”)的定义和主
11、函数 main的定义。程序中位于每个“ERROR*found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为: Initial times are 0 d:0 h:0 m:59 s After one second times are 0 d:0 h:1 m:0 s 注意:只修改每个“ERROR*found*”下的那一行,不要改动程序中的其他内容。#includeiostreamusing namespace std;class Clockpublic: Clock(unsigned long i=0); void set(unsigned long i=0); void pri
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
5000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 职业资格 国家 二级 机试 操作 模拟 试卷 328 答案 解析 DOC
