【计算机类职业资格】二级C++机试-129及答案解析.doc
《【计算机类职业资格】二级C++机试-129及答案解析.doc》由会员分享,可在线阅读,更多相关《【计算机类职业资格】二级C++机试-129及答案解析.doc(7页珍藏版)》请在麦多课文档分享上搜索。
1、二级 C+机试-129 及答案解析(总分:100.00,做题时间:90 分钟)一、1基本操作题(总题数:1,分数:30.00)1.请使用“答题”菜单或使用 VC6 打开考生文件夹 proj1 下的工程 proj1,其中有枚举 DOGCOLOR、狗类Dog 和主函数 main 的定义。程序中位于每个/ERROR*found*下的语句行有错误,请加以改正。改正后程序的输出应该是:There is a white dog named Hoho.There is a black dog named Haha.There is a motley dog named Hihi.注意:只能修改每个/ERRO
2、R*found*下的那一行,不要改动程序中的其他内容。/源程序#include iostreamusing namespace std;/狗的颜色:黑、白、黄、褐、花、其他enum DOGCOLOR BLACK,WHITE,YELLOW,BROWN,PIEBALD,OTHER;class Dog/狗类DOCCOLOR color;char name20;static int count;public:Dog(char name,DOGCOLOR color)strcpy(this-name,name);/ERROR*found*strcpy(this-color,color);DOGCOLOR
3、 getColor() const return color;/ERROR*found*const char*getName() const return*name;const char*getColorString() constswitch(color)case BLACK: return“black“;case WHITE: return“white“;case YELLOW: return“yellow“;case BROWN: return“brown“;case PIEBAIJD: return“piebald“;return“motley“;void show() const c
4、out“There is a“getColorString()“dog named“name.endl;;int main()/ERROR*found*Dog dog1(“Hoho“,WHITE),dog2(“Haha“,BLACK); dog3(“Hihi“,OTHER);dog1show();dog2.show();dog3.show();return 0:(分数:30.00)_二、2简单应用题(总题数:1,分数:40.00)2.请使用“答题”菜单或使用 VC6 打开考生文件夹 proj2 下的工程 proj2,函数 void Insert(node*q)使程序能够完成如下功能:从键盘输入
5、一行字符,调用该函数建立反序的无头结点的单链表,然后输出整个链表。注意:请勿修改主函数 main 和其他函数中的任何内容,只需在画线处编写适当代码,也不能删除或移动/*found*。/源程序 proj2.cpp#includeiostreamusing namespace std;struct nodechar data;node*link:*head; /链表首指针void Insert(node*q) /将节点插入链表首部/*found*_;head=q;int main()char ch;node *p;head=NULL:cout“Please input the string“end
6、l;while(ch=cin.get()!=/n)/*found*_;/用 new 为节点 p 动态分配存储空间p-data=ch;/*found*_; /在链表首部插入该节点p=head;while(p!=NULL)coutp-data;p=p-link;coutendl;return 0:(分数:40.00)_三、3综合应用题(总题数:1,分数:30.00)3.请使用“答题”菜单或使用 VC6 打开考生文件夹 proj3 下的工程 proj3,其中声明了 DataList 类,这是一个用于表示数据表的类。sort 成员函数的功能是将当前数据表排序,使得表中的元素呈升序排列。请编写这个 so
7、rt 函数。程序的正确输出应该是:排序前: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*两行之间,不得修改程序的其他部分。注意:程序最后已经将结果输出到文件 out.dat 中。输出函数 writeToFile 已经编译为 obj 文件,并且在本程序中调用。/源程序#include“DataList.h“DataList: DataList(int len, double data):len(len)d=new doublelen;for(int i=0; ilen; i+) di
8、=(data=NULL?0.0:datai);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,4,5,2;DataList list(12,s);cout“排序前:“;list.show();list.sort();coutendl“排序后:“;list.show();/writeToFile(“K:/b10/61000102/
9、“,list);return 0:(分数:30.00)_二级 C+机试-129 答案解析(总分:100.00,做题时间:90 分钟)一、1基本操作题(总题数:1,分数:30.00)1.请使用“答题”菜单或使用 VC6 打开考生文件夹 proj1 下的工程 proj1,其中有枚举 DOGCOLOR、狗类Dog 和主函数 main 的定义。程序中位于每个/ERROR*found*下的语句行有错误,请加以改正。改正后程序的输出应该是:There is a white dog named Hoho.There is a black dog named Haha.There is a motley do
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
5000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 职业资格 二级 机试 129 答案 解析 DOC
