【计算机类职业资格】国家二级C++机试(操作题)模拟试卷340及答案解析.doc
《【计算机类职业资格】国家二级C++机试(操作题)模拟试卷340及答案解析.doc》由会员分享,可在线阅读,更多相关《【计算机类职业资格】国家二级C++机试(操作题)模拟试卷340及答案解析.doc(5页珍藏版)》请在麦多课文档分享上搜索。
1、国家二级 C+机试(操作题)模拟试卷 340及答案解析(总分:6.00,做题时间:90 分钟)一、基本操作题(总题数:1,分数:2.00)1.请使用 VC6或使用【答题】菜单打开考生文件夹 proj1下的工程 pmjl,此工程中包含了类 Pets(“宠物”)和主函数 main的定义。程序中位于每个“ERROR*found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为: Name:sonny Type:dog Name:John Type:dog Name:Danny Type:eat Name:John Type:dog 注意:只修改每个“ERROR*found*”下的那一行,
2、不要改动程序中的其他内容。#includeiostreamusing namespace st:d;enllm Pets typedog,cat,bird,fish;class PetSprivate: char*name; Pets_type type;public: Pets(const char*flame=”sonny”,Pets_type type=dog); Petsoperator=(const Petss); Pets(); void show()const; ; Pets:Pets(const char*name,Pets type type) /构造函数 this-name
3、=new charstrlen(name)+1; strcpy(this 一name,name); ERROR*found* type=type; Pets:Pets()析构函数,释放 name 所指向的字符串 ERROR*found* name=0; PetsDiscountSale: DiscountSale ( ):discount(0)DiScountSale:DiscountSale(doublethe_price,double the_discount) :Sale(the_price),discount(thediscount)double DiscountSale:bill()
4、const double fraction=discount100 ; *found*_;返回本对象打折以后的实际售价bool operator(const Sale(分数:2.00)_三、综合应用题(总题数:1,分数:2.00)3.请使用 VC6或使用【答题】菜单打开考生文件夹 proj3下的工程 proj3,其中包含主程序文件maincpp 和用户定义的头文件 Arrayh,整个程序包含有类 Array的定义和主函数 main的定义。请把主程序文件中的 Array类的成员函数 Contrary()的定义补充完整,经补充后运行程序,得到的输出结果应该是: 5 8 5,4,3,2,1 0,0,
5、84,56,45,34,23,12 注意:只允许在“*333*”和“*666*”之间填写内容,不允许修改其他任何地方的内容。Arrayh#includeiostreamusing namespace std;templateclass Type,int mclass Array数组类 public: Array(Type b,int mm) 构造函数 for(int i=0;im;i+) if(imm)ai=bi;else ai=0; void Contrary();交换数组 a中前后位置对称的元素的值 int Length()constreturn m;)返回数组长度 Type operat
6、or(int i)const下标运算符重载为成员函数 if(i0 | i=m)cout“下标越界!“endl;exit(1);) return ai, private: Type am; , void writeToFile(const char*); 不用考虑此语句的作用 maincpp #include”Arrayh” 交换数组 a中前后位置对称的元素的值 templateclass Type,int m void ArrayType,m:Contrary() 补充函数体 *333* *666* int main() int sl5=1,2,3,4,5; double s26=12,23,
7、34,45,56,84); Arrayint,5dl(s1,5); Arraydouble,8d2(s2,6); int i; d1Contrary(); d2Contrary(); coutd1Length()“d2Length()end1; for(i=0;i4;i+) coutd1i”,”; coutd14end1; for(i=0;i7;i+) coutd2i”,”; coutd27end1; writeToFile(”);不用考虑此语句的作用 return 0;(分数:2.00)_国家二级 C+机试(操作题)模拟试卷 340答案解析(总分:6.00,做题时间:90 分钟)一、基本操作
8、题(总题数:1,分数:2.00)1.请使用 VC6或使用【答题】菜单打开考生文件夹 proj1下的工程 pmjl,此工程中包含了类 Pets(“宠物”)和主函数 main的定义。程序中位于每个“ERROR*found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为: Name:sonny Type:dog Name:John Type:dog Name:Danny Type:eat Name:John Type:dog 注意:只修改每个“ERROR*found*”下的那一行,不要改动程序中的其他内容。#includeiostreamusing namespace st:d;enl
9、lm Pets typedog,cat,bird,fish;class PetSprivate: char*name; Pets_type type;public: Pets(const char*flame=”sonny”,Pets_type type=dog); Petsoperator=(const Petss); Pets(); void show()const; ; Pets:Pets(const char*name,Pets type type) /构造函数 this-name=new charstrlen(name)+1; strcpy(this 一name,name); ERR
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
5000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 职业资格 国家 二级 机试 操作 模拟 试卷 340 答案 解析 DOC
