【计算机类职业资格】国家二级C++机试(操作题)模拟试卷347及答案解析.doc
《【计算机类职业资格】国家二级C++机试(操作题)模拟试卷347及答案解析.doc》由会员分享,可在线阅读,更多相关《【计算机类职业资格】国家二级C++机试(操作题)模拟试卷347及答案解析.doc(5页珍藏版)》请在麦多课文档分享上搜索。
1、国家二级 C+机试(操作题)模拟试卷 347及答案解析(总分:8.00,做题时间:90 分钟)一、基本操作题(总题数:1,分数:2.00)1.请使用 VC6或使用【答题】菜单打开考生文件夹 projl下的工程 proj1,该工程中包含程序文件mainepp,其中有类 Foo和主函数 main的定义。程序中位于每个“ERROR*found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应该是: X=a Y=42 注意:只修改每个“ERROR*found*”下的那一行,不要改动程序中的其他内容。#includeiostreamusing namespace st;d;class Foop
2、ublic: Foo(char x)x =x;) char getX()constreturn xjpublic: static int Y;private: char x_;;ERROR*found*int Fooy_=42;int main(int argo,char*argv)ERROR* found* Foo f;ERROR*found* cout”X=”fx end1; cout”Y=” fy_endl; return 0;(分数:2.00)_二、简单应用题(总题数:1,分数:2.00)2.请使用 VC6或使用【答题】菜单打开考生文件夹 prog2下的工程 prog2,此工程中包含一
3、个程序文件maincpp,其中有“班级”类 Class和“学生”类 Student的定义,还有主函数 main的定义。在主函数中定义了两个“学生”对象,他们属于同一班级。程序展示,当该班级换教室后,这两个人的教室也同时得到改变。请在横线处填写适当的代码,然后删除横线,以实现上述类定义。此程序的正确输出结果应为:改换教室前: 学号:0789 姓名:张三 班级:062113 教室:521 学号:0513 姓名:李四 班级:062113 教室:521 改换教室后: 学号:0789 姓名:张三 班级:062113 教室:311 学号:0513 姓名:李四 班级:062113 教室:311 注意:只能在
4、横线处填写适当的代码,不要改动程序中的其他内容。#includeiostreamusing namespace std;class Class “班级”类 public: ClasS(const char*id,const char。room) strcpy(class id,id); /*found* const char*getClass ID()constre-turn class id; /返回班号/*found* const char*getClassroom()const_ 返回所在教室房号 void changeRoOmTO(const char*new room) 改换到另一个
5、指定房号的教室 strcpy(classroom,new room); private: char class id20; 班号 char classroom20;所在教室房号 ; class Student “学生”类 char my_id10;/学号 char my_name20; 姓名 Class strcpy(my_name,the_name); const char*getID()constreturnmy_id;) const char*getName()constreturn my_name;)Class getClass 0constreturn my_class;);void
6、 showStudent(Student*Stu)cout”学号:”stu 一getID()“ “;cout”姓名:”stu-getName()“ “;cout”班级:”stu 一getClass()getClassID()”; cout“教室:”stu 一getClass()getClassr00m()endl;int main() Class cla(”062113”,”521”); Student Zhang(“0789”,“张三”,cla),Li(”0513”,“李四”,cla); cout”改换教室前:”endl; showStudent(Zhang);showStudent(Li)
7、;062113 班的教室由 521改换到 311*found* cout”改换教室后:”endl; showStudent(Zhang); showStudent( Staff()deletedepartment;) const char*getDepartment()constreturn department;) void setDepartment(const char*d); double getSalary()constreturn salary;) void setSalary(double S)salary=S; , Person:Person fconst char*id ca
8、rd no,const char*P_name,bool_is_ male):ismale(iS male) idcardno=new charstrlen(id card no)+1; strcpy(idcardno,id card no); name=new charstrlen(p name)+1;strcpy(name,P name); void Person:rename ( const char*new name) deletename;*2* *found* _; strcpy(name,new name);Staff:Staff ( const char*id cardno,c
9、onst char*P name,bool ismale,*3* * found*const char*dept,double sal):_department=new charstrlen(dept)+1;strcpy(department,dept);salary=sal;void Staff: setDepartment (constchar*dept)deletedepartment; department=new charstrlen(dept)+1;strcpy(department,dept);int main() Staff Zhangsan(”123456789012345”
10、,“张三“,false,”人事部”,123456);Zhangsanrename(”张小丽”);coutZhangsangetName()Zhang。sangetIDCardNO()endl; return 0;(分数:2.00)_4.请使用 VC6或使用【答题】菜单打开考生目录 proj3下的工程文件 proj3,此工程包含一个源程序文件proj3cpp,其中定义了用于表示二维向量的类 MyVector;程序应当显示(6,8)。但程序中有缺失部分,请按照以下提示,把缺失部分补充完整: (1)在“* 1* *found*”的下方是构造函数的定义,它用参数提供的坐标对 x和 y进行初始化。 (2
11、)在“*2* *found*”的下方是减法运算符函数定义中的一条语句。两个二维向量相减生成另一个二维向量:其 X坐标等于两向量 X坐标之差,其Y坐标等于两向量 Y坐标之差。 (3)在“*3* *found*”的下方,语句的功能是使变量 v3获得新值,它等于向量 v1与向量 v2之和。 注意:只在指定位置编写适当代码,不要改动程序中的其他内容,也不要删除或移动“*found*”。proj 3cpp#includeiostreamusing std:ostream;using std:cout;using std:endl;class MyVector 表示二维向量的类double X;x 坐标值
12、 double y; Y 坐标值 public:MyVector(double i=00,double j=00);构造函数 MyVector operator+(MyVector j); 重载运算符+ friend MyVector operator 一(MyVector i,MyVector j); 重载运算符一 friend ostream *1* *found* _(double i,double j):X(i), Y(j) MyVector MyVector:operator+(MMVecor j) return MyVector(x+jX,Y+jy); MyVector opera
13、tor 一(MyVector i, MyVector J) *2* *found*return MyVector(_); ostreamprivate: char x_;;ERROR*found*int Fooy_=42;int main(int argo,char*argv)ERROR* found* Foo f;ERROR*found* cout”X=”fx end1; cout”Y=” fy_endl; return 0;(分数:2.00)_正确答案:(正确答案:(1)int Foo:y_=42; (2)Foo f(a); (3)coutfgetX()endl;)解析:解析:(1)主要考
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
5000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 职业资格 国家 二级 机试 操作 模拟 试卷 347 答案 解析 DOC
