[计算机类试卷]国家二级C++机试(操作题)模拟试卷347及答案与解析.doc
《[计算机类试卷]国家二级C++机试(操作题)模拟试卷347及答案与解析.doc》由会员分享,可在线阅读,更多相关《[计算机类试卷]国家二级C++机试(操作题)模拟试卷347及答案与解析.doc(10页珍藏版)》请在麦多课文档分享上搜索。
1、国家二级 C+机试(操作题)模拟试卷 347及答案与解析 一、基本操作题 1 请使用 VC6或使用【答题】菜单打开考生文件夹 projl下的工程 proj1,该工程中包含程序文件 main epp,其中有类 Foo和主函数 main的定义。程序中位于每个 “ ERROR*found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应该是: X=a Y=42 注意:只修改每个 “ ERROR*found*” 下的那一行,不要改动程序中的其 他内容。 #include using namespace st; d; class Foo public: Foo(char x)x =x; ) c
2、har getX()constreturn xj public: static int Y; private: char x_; ; ERROR*found* int Foo y_=42; int main(int argo, char*argv) ERROR* found* Foo f; ERROR*found* cout using namespace std; class Class “班级 ”类 public: ClasS(const char*id, const char。 room) strcpy(class id, id); /*found* const char*getClas
3、s ID()constre- turn class id; /返回班号 /*found* const char*getClassroom()const _ 返回所在教室房号 void changeRoOmTO(const char*new room) 改换到另一个指定房号的教室 strcpy(classroom, new room); private: char class id20; 班号 char classroom20;所在教室房号 ; class Student “学生 ”类 char my_id10; /学号 char my_name20; 姓名 Class strcpy(my_na
4、me, the_name); const char*getID()constreturn my_id; ) const char*getName()constre turn my_name; ) Class getClass 0constreturn my_class; ) ; void showStudent(Student*Stu) coutgetID()getName()getClass() getClassID()getClass() getClassr00m() using namespace std; ClaSS Person char*idcardno; 用动态空间存储的身份证号
5、 char*name; 用动态空间存储的姓名 bool ismale; 性别: true为男, false 为女 public: Person(const char*pid, const char *pname, bool pmale); 一 Person() *1* *found* _; const char*getIDCardNO()const return idcardno; ) const char*getName()constreturn name; ) void rename(const char*new name); bool isMale()const(return ismal
6、e; ) , class Staff: public Person char*department; double salary; public: Staff(const char*id card no, const char*P_name,bool is_male, const char*dept, double sal); Staff()deletedepartment; ) const char*getDepartment()const return department;) void setDepartment(const char*d); double getSalary()cons
7、treturn salary; ) void setSalary(double S)salary=S; , Person: Person fconst char*id card 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*n
8、ew name) deletename; *2* *found* _; strcpy(name, new name); Staff: Staff ( const char*id card no, const char*P name, bool is male, *3* * found* const char*dept, double sal): _ department=new charstrlen(dept)+1; strcpy(department, dept); salary=sal; void Staff: setDepartment (const char*dept) deleted
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 试卷 国家 二级 机试 操作 模拟 347 答案 解析 DOC
