欢迎来到天天文库
浏览记录
ID:56379679
大小:141.33 KB
页数:7页
时间:2020-06-22
《实验四 继承与派生2.docx》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、实验四继承与派生(二)班级:软件1302班学号:201313138064姓名:代永强[实验目的]:1.理解多重继承的概念;2.理解为了避免同一基类出现多个重复的副本而采用的虚基类概念和虚拟继承;3.学习利用虚基类解决二义性问题。[实验内容]:实验题目:设计一个用于人事管理的“people(人员)”基类。考虑到通用性,仅抽象出所有类型人员都具有的属性:编号、姓名、性别、出生日期、身份证号等;从people(人员)类派生出student(学生)类,并添加属性:班号ClassNo;从people类派生出teach
2、er(教师)类,并添加属性:专业subject、导师teacheradviser(teacher类);从graduate类和teacher类派生出TA(助教生)类。设计时注意虚基类的使用,注意重载相应的成员函数。测试这些类。程序源代码:#include#includeusingnamespacestd;classDate{private:intYear;intMonth;intDay;public:Date();Date(intY,intM,intD);voidSetDa
3、te(inty,intm,intd);intGetYear(){returnYear;}intGetMonth(){returnMonth;}intGetDay(){returnDay;}virtual~Date();};Date::Date(){Year=0;Month=0;Day=0;}Date::Date(intY,intM,intD){Year=Y;Month=M;Day=D;}voidDate::SetDate(inty,intm,intd){Year=y;Month=m;Day=d;}Date:
4、:~Date(){}classpeople{private:stringNum;stringName;stringSex;Datebirthday;stringId;public:people();people(stringnum,stringname,stringsex,inty,intm,intd,stringid);people(people&p);stringGetName();voidShow();virtual~people();};people::people(){}people::peopl
5、e(stringnum,stringname,stringsex,inty,intm,intd,stringid):birthday(){birthday.SetDate(y,m,d);Num=num;Name=name;Sex=sex;Id=id;}people::~people(){}people::people(people&p):birthday(p.birthday){Num=p.Num;Name=p.Name;Sex=p.Sex;Id=p.Id;}voidpeople::Show(){cout<
6、<"编号:"<7、:intClassNo;public:student(peoplep,intc);student(student&s);voidShow();virtual~student();};student::student(peoplep,intc):people(p){ClassNo=c;}student::student(student&s):people(s){ClassNo=s.ClassNo;}student::~student(){}voidstudent::Show(){people::Show();8、cout<<"班号:"<
7、:intClassNo;public:student(peoplep,intc);student(student&s);voidShow();virtual~student();};student::student(peoplep,intc):people(p){ClassNo=c;}student::student(student&s):people(s){ClassNo=s.ClassNo;}student::~student(){}voidstudent::Show(){people::Show();
8、cout<<"班号:"<
此文档下载收益归作者所有