【计算机类职业资格】国家二级C++机试(操作题)模拟试卷335及答案解析.doc
《【计算机类职业资格】国家二级C++机试(操作题)模拟试卷335及答案解析.doc》由会员分享,可在线阅读,更多相关《【计算机类职业资格】国家二级C++机试(操作题)模拟试卷335及答案解析.doc(6页珍藏版)》请在麦多课文档分享上搜索。
1、国家二级 C+机试(操作题)模拟试卷 335及答案解析(总分:10.00,做题时间:90 分钟)一、基本操作题(总题数:2,分数:4.00)1.请使用 VG6或使用【答题】菜单打开考生文件夹 pmjl下的工程 proj1,其中有枚举 DOGCOLOR、狗类Dog和主函数 main的定义。程序中位于每个“ERROR*found*”下的语句行有错误,请加以改正。改正后程序的输出结果应该是: There is a white dog named Hoho There is a black dog named HaIla There is a motley dog named Hihi 注意:只修改每
2、个“ERROR*found*”下的那一行,不要改动程序中的其他内容。#includeiostreamusing namespace std;狗的颜色:黑、白、黄、褐、花、其他 enum DOGCOLORBLACK,WHTTE,YELLOW,BROWN,PTEBALD,OTHER);class Dog /狗类 DOGCOLOR colot; char name2 O; static int count;public: Dog(char name,DOGCOLOR color) strcpy(this一name,name);ERROR*found* strcpy(this一color,color)
3、; DOGCOLOR getColor()constreturn color;)ERROR*found* COnSt char*get:Name()constreturn*name;) const char* getColorString()const switch(colot) CaSe BLACK:return”blaCk”; case WHITE:return”white”; CaSe YELLOW:return”yellow”; case BROWN:return”brown”; CaSe PIEBALD:return”piebald”; return”motley”; Void sh
4、ow()const cout”There is a”getColorString()”dog named”nameendl; ; int main() ERROR*found* Dog dog1(”Hobo”,WHITE),dog2(”Haha”,BLACK);dog3(”Hihi”,OTHER); dog1show(); dog2show(); dog3show(); return 0; (分数:2.00)_2.请使用 VC6或使用【答题】菜单打开考生文件夹 pmj1下的工程 pmj1,此工程中含有一个源程序文件pmj1cpp。其中位于每个注释“ERROR *found*”之后的一行语句存在
5、错误。请改正这些错误,使程序的输出结果为: The value is:10 注意:只修改注释“ERROR *found*”的下一行语句,不要改动程序中的其他内容。proj1cpp#includeiostreamusing namespace std;class Member ERROR*found*private: Member(int val):value(val) int value; ,class MyClass Member m;public:ERROR*found* MyClass(int val) int GetValue()constreturn mvalue;);int mai
6、n() MyClass*obj=new MyClass(i0); ERROR*found* 下列语句输出 obj指向类中的 value值 cout”The value is:”objGetValue()endl; delete obj; return 0; (分数:2.00)_二、简单应用题(总题数:1,分数:2.00)3.请使用 VC6或使用【答题】菜单打开考生文件夹 proj2下的工程 proj2,其中有整数栈类 IntList、顺序栈类 SeqList和链接栈类 LinkList的定义。请在程序中的横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为: 4 6 3
7、1 8 4 6 3 1 8 注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“*found*”。#includeiostreamusing namespace std;class IntStack 整数栈类 public:virtual VOid push(int)=0;入栈virtual int pop()=0;出栈并返回出栈元素 virtual int topElement()const=0;返回栈顶元素。但不出栈 virtual bool isEmpty()oonst=0;判断是否栈空;class SeqStack:public IntStack int da
8、ta100; 存放栈元素的数组 int top; 栈顶元素的下标 public: *found* SeqStack():_()把 top初始化为一 1表示栈空 void push(int n)data+top=n;) *found* int pop()return_; int topElement()constreturn datatop; bool isEmpty()constreturn top=一 1;) ; struct Node int data; Node*next; ; class LinkStack:public IntStack Node*top;public:* found
9、*LinkStack():_)把 top初始化为NULL表示栈空 void push(int n) Node*P=new Node; P-data=n; * found* _; top=P; int pop() int d=top-data; top=top-next; return d; int topElement()constreturn top 一data;) bool isEmpty()constreturn top= NULL;) ,void pushData(IntStack pushData(stl);pop Data(stl); coutend1; LinkStack st2
10、;pushData(st2);pop Data(st2); coutend1; return 0;(分数:2.00)_三、综合应用题(总题数:2,分数:4.00)4.请使用 VC6或使用【答题】菜单打开考生文件夹 proj3下的工程 proj3,其中声明的 DataList类,是一个用于表示数据表的类。DataList 的重载运算符函数 operator+,其功能是求当前数据表与另一个相同长度的数据表之和;即它返回一个数据表,其每个元素等于相应两个数据表对应元素之和。请编写这个operator+函数。程序的正确输出应该是: 两个数据表: 1,2,3,4,5,6 3,4,5,6,7,8 两个数据
11、表之和: 4,6,8,10,12,14 要求: 补充编制的内容写在“*333*”与“*666*”之间,不得修改程序的其他部分。 注意:程序最后将结果输出到文件outdat 中。输出函数 writeToFile已经编译为 0bj文件,并且在本程序中调用。 /DataList,h #includeiostream using namespace std; class DataList数据表类 int fen; double*d;public: DataList(int len,double data=NULL); DataList(DataList return 0; (分数:2.00)_5.请使
12、用 VC6或使用【答题】菜单打开考生文件夹 proj3下的工程 prog3,其中声明了 ValArray类,该类在内部维护一个动态分配的整型数组。ValArray 类的复制构造函数应实现对象的深层复制。请编写VMArray类的复制构造函数。在 main函数中给出了一组测试数据,此种情况下程序的输出应该是: ValArray v1=1,2,3,4,5 ValArray v2=2,2,2,2,2 要求: 补充编制的内容写在“*333*”与“*666*”之间。不要修改程序的其他部分。注意: 相关文件包括:maincpp、ValArrayh。 程序最后调用 writeToFile函数,使用另一组不同的
13、测试数据,将不同的运行结果输出到文件 outdat 中。输出函数 writeToFile已经编译为 obj文件。ValArrayh#includeiostreamusing namespace std;clas s ValArray int*v; int Size;public: ValArray(const int*P,int n):Size(n) v=new intsize; for(int i=0;iSize;i+) vi=Pi; ValArray(const ValArray for(int i=0;isize 一 1;i+) out vi ”,”; outvsize 一 1 ); ;
14、 void writeToFile(const char*); maincpp #include”ValArrayh” ValArray:ValArray(const ValArray v1print(cout); coutendl; cout”ValArray v2=”; v2print(cout); coutendl; writeToFile(”); return 0;(分数:2.00)_国家二级 C+机试(操作题)模拟试卷 335答案解析(总分:10.00,做题时间:90 分钟)一、基本操作题(总题数:2,分数:4.00)1.请使用 VG6或使用【答题】菜单打开考生文件夹 pmjl下的工
15、程 proj1,其中有枚举 DOGCOLOR、狗类Dog和主函数 main的定义。程序中位于每个“ERROR*found*”下的语句行有错误,请加以改正。改正后程序的输出结果应该是: There is a white dog named Hoho There is a black dog named HaIla There is a motley dog named Hihi 注意:只修改每个“ERROR*found*”下的那一行,不要改动程序中的其他内容。#includeiostreamusing namespace std;狗的颜色:黑、白、黄、褐、花、其他 enum DOGCOLORBL
16、ACK,WHTTE,YELLOW,BROWN,PTEBALD,OTHER);class Dog /狗类 DOGCOLOR colot; char name2 O; static int count;public: Dog(char name,DOGCOLOR color) strcpy(this一name,name);ERROR*found* strcpy(this一color,color); DOGCOLOR getColor()constreturn color;)ERROR*found* COnSt char*get:Name()constreturn*name;) const char
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
5000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 职业资格 国家 二级 机试 操作 模拟 试卷 335 答案 解析 DOC
