继承与派生(二)实验报告

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

学号:姓名:班级:

实验四继承与派生(二)

【实验目的】

1、理解多重继承的概念;

2、理解为了避免同同一基类出现多个重复的副本而采用的虚基类概念和虚拟继承;

3、学习利用虚基类解决二义性问题。

【实验内容】

题目:

2、设计一个用于人事管理的“people(人员)”基类。考虑到通用

性,仅只抽象出所有类型人员都有的属性:编号、姓名、性别、出生日期、身份证号等;从people(人员)类派生出student(学生)类,并添加属性:班号classNO;从people类派生出teacher(教师)类,并添加属性:职务principalship、部门Department;从student类派生出graduate (研究生)类,并添加属性:专业subject、导师teacher adviser(teacher 类);从graduate类和teacher类派生出TA(助教生)类。设计时注意虚基类的使用,注意重载相应的成员函数。测试这些类。

UML图:

Date

-year: int

-month: int

-day: int

<>-Date(y: int, m: int, d: int) <>-Date(D: Date)

+init(y: int, m: int, d: int): void

+show(): void people

#m_date: Date

#m_no: long

#m_ident_no: string

#m_name: string

#m_sex: string

<>-people(no: long, name: string, sex: string, ident_no: string, year: int, month: int, day: int) <>-people(no: long, name: string, sex: string, ident_no: string, date: Date)

<>-people(p: people)

+init(no: long, name: string, sex: string, ident_no: string, year: int, month: int, day: int): void

+init(no: long, name: string, sex: string, ident_no: string, date: Date): void

+init(p: people): void

+show(): void

student

#m_classno: string

<>-student(person: people, classno: string)

<>-student(stu: student)

+show(): void

teacher

#m_principalship: string

#m_department: string

<>-teacher(p: people, principalship: string, department: string)

<>-teacher(stu: teacher)

+show(): void

graduate

#m_subject: string

#m_adviser: teacher

<>-graduate(s: student, subject: string, t: teacher)

<>-graduate(g: graduate)

+show(): void

TA

<>-TA(g: graduate, t: teacher)

<>-TA(t: TA)

+show(): void

源程序代码:

#include

#include

using namespace std;

class Date

{

private:

int year;

int month;

int day;

public:

Date(int y,int m,int d)

{

year=y;

month=m;

day=d;

}

Date(const Date &D)

{

year=D.year;

month=D.month;

day=D.day;

}

void init(int y,int m,int d)

{

year=y;

month=m;

day=d;

}

void show()const

{

cout<<"出生日期:"<

}

};

class people

{

public:

people(long no,string name,string sex,string ident_no,int year,int month,int day);

people(long no,string name,string sex,string ident_no,Date date);

people(const people &p);

void init(long no,string name,string sex,string ident_no,int year,int month,int day);

void init(long no,string name,string sex,string ident_no,Date date);

void init(const people &p);

相关文档
最新文档