资源描述:
《实验四 继承与派生(工程版)》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、班级:计科(2)班 学号:201013137183姓名:王于铭完成时间:2011-4-21实验四继承与派生[实验目的]1、学习定义和使用类的继承关系,定义派生类;2、熟悉不同继承方式下对集类成员的访问控制;3、学习和利用虚基类解决二义性问题;[实验内容与步骤]4、设计一个人事管理的“people(人员)”基类。考虑到通用性,仅只抽象出所有类型人员都具有的属性:编号、姓名、性别、出生日期、身份证号等;从people(人员)类派生出student(学生)类,并添加属性:班号classno;从people(人员)类派生teacher(教师)类,并添加属性:职务p
2、rincipalship、部门department;从student类中派生出graduate(研究生)类,添加属性:专业subject、导师teacheradviser(teacher类);从graduate类和teacher类派生出TA(助教生)类。设计时注意虚基类的使用,注意重载相应的成员函数。测试这些类。[源代码]//Date.h#ifndefDate_H#defineDate_HclassDate{private:intyear,month,day;public:Date(inty=2010,intm=1,intd=1);~Date();Date
3、(constDate&p);voidGet_Date();voidSet_Date(inty,intm,intd);voidSet_Date(Dateb);};#endif//people.h#include"date.h"#ifndefpeople_H#definepeople_H#includeusingnamespacestd;//如果有包含别的头文件,就要有打开空间!classpeople{protected:stringname,idcard,num;charsex;Datea;public:people();people(str
4、ingn,stringi,stringm,chars,Dateb);~people();people(constpeople&p);voidSet_name(stringn);voidSet_idcard(stringi);voidSet_num(stringm);voidSet_sex(chars);stringGet_name();stringGet_idcard();stringGet_num();charGet_sex();voidSet_people(stringn,stringi,stringm,chars,Dateb);voidGet_peo
5、ple();};#endif//student.h#include"date.h"#include"people.h"#ifndefstudent_H#definestudent_Hclassstudent:virtualpublicpeople{private:stringclassNO;public:student(constpeople&a_2,stringc);student(conststudent&p);~student();voidSet_classNO(stringc);stringGet_classNO();voidGet_student
6、();voidSet_student(stringn,stringi,stringm,chars,Dateb,stringc);};#endif//teacher.h#include"date.h"#include"people.h"#ifndefteacher_H#defineteacher_Hclassteacher:virtualpublicpeople{protected:stringprincipalship;stringdepartment;public:teacher(constpeople&a_1,stringp,stringdepart)
7、;teacher(constteacher&p);~teacher();voidSet_principalship(stringp);voidSet_department(stringd);stringGet_principalship();stringGet_department();voidSet_teacher(stringn,stringi,stringm,chars,inty,intmon,intd,stringp,stringdepart);voidGet_teacher();};#endif//graduate.h#include"date.
8、h"#include"people.h"#include"stud