欢迎来到天天文库
浏览记录
ID:55514737
大小:45.50 KB
页数:5页
时间:2020-05-15
《实验四 继与派生.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、班级:计科(2)班 学号:201013137183姓名:王于铭完成时间:2011-4-21实验四继承与派生[实验目的]1、学习定义和使用类的继承关系,定义派生类;2、熟悉不同继承方式下对集类成员的访问控制;3、学习和利用虚基类解决二义性问题;[实验内容与步骤]4、设计一个人事管理的“people(人员)”基类。考虑到通用性,仅只抽象出所有类型人员都具有的属性:编号、姓名、性别、出生日期、身份证号等;从people(人员)类派生出student(学生)类,并添加属性:班号classno;从people(人员)类派生teacher(
2、教师)类,并添加属性:职务principalship、部门department;从student类中派生出graduate(研究生)类,添加属性:专业subject、导师teacheradviser(teacher类);从graduate类和teacher类派生出TA(助教生)类。设计时注意虚基类的使用,注意重载相应的成员函数。测试这些类。[源代码]#include#includeusingnamespacestd;classDate{private:intyear,month,day;pub
3、lic:Date(inty=2010,intm=1,intd=1){year=y;month=m;day=d;}~Date(){}Date(Date&p);intGet_Date(){cout<<"出生年月:"<4、vate:stringname,idcard,num;charsex;Datea;public:people(stringn,stringi,stringm,chars,Dateb):a(b){name=n;num=m;idcard=i;sex=s;}~people(){}voidSet_name(stringn){name=n;}voidSet_idcard(stringi){idcard=i;}voidSet_num(stringm){num=m;}voidSet_sex(chars){sex=s;}stringGet_na5、me(){returnname;}stringGet_idcard(){returnidcard;}stringGet_num(){returnnum;}charGet_sex(){returnsex;}voidSet_people(stringn,stringi,stringm,chars,inty,intmon,intd){Set_name(n);Set_idcard(i);Set_num(m);Set_sex(s);a.Set_Date(y,mon,d);}voidGet_people(){cout<<"编号:"<6、_num()<<"姓名:"<7、sNO(stringc){classNO=c;}voidGet_student(){Get_people();cout<<"classNO:"<8、stringdepartment;public:teacher(stringn,stringi,stringm,chars,Dateb,stringp,stringdepart):people(n,i,m,s,b){principalship=p;departm
4、vate:stringname,idcard,num;charsex;Datea;public:people(stringn,stringi,stringm,chars,Dateb):a(b){name=n;num=m;idcard=i;sex=s;}~people(){}voidSet_name(stringn){name=n;}voidSet_idcard(stringi){idcard=i;}voidSet_num(stringm){num=m;}voidSet_sex(chars){sex=s;}stringGet_na
5、me(){returnname;}stringGet_idcard(){returnidcard;}stringGet_num(){returnnum;}charGet_sex(){returnsex;}voidSet_people(stringn,stringi,stringm,chars,inty,intmon,intd){Set_name(n);Set_idcard(i);Set_num(m);Set_sex(s);a.Set_Date(y,mon,d);}voidGet_people(){cout<<"编号:"<6、_num()<<"姓名:"<7、sNO(stringc){classNO=c;}voidGet_student(){Get_people();cout<<"classNO:"<8、stringdepartment;public:teacher(stringn,stringi,stringm,chars,Dateb,stringp,stringdepart):people(n,i,m,s,b){principalship=p;departm
6、_num()<<"姓名:"<7、sNO(stringc){classNO=c;}voidGet_student(){Get_people();cout<<"classNO:"<8、stringdepartment;public:teacher(stringn,stringi,stringm,chars,Dateb,stringp,stringdepart):people(n,i,m,s,b){principalship=p;departm
7、sNO(stringc){classNO=c;}voidGet_student(){Get_people();cout<<"classNO:"<8、stringdepartment;public:teacher(stringn,stringi,stringm,chars,Dateb,stringp,stringdepart):people(n,i,m,s,b){principalship=p;departm
8、stringdepartment;public:teacher(stringn,stringi,stringm,chars,Dateb,stringp,stringdepart):people(n,i,m,s,b){principalship=p;departm
此文档下载收益归作者所有