继承练习之医学院教师类—C++
由于博客主题现在有点问题需要修复,暂时就不再花时间在这写过多的介绍了。
/*
功能:医学院教师类
日期:2013-11-25
*/
#include <iostream>
#include <string>
using namespace std;
//人员类
class Person
{
public:
Person(string id=NULL,string name=NULL);
void setId(string id);
string getID()const;
void setName(string name);
string getName()const;
private:
string m_aId;
string m_aName;
};
//教师类
class Teacher:virtual public Person
{
public:
Teacher(string Subject=NULL):
m_aSubject(Subject){};
void setSubject(string Subject);
string getSubject()const;
private:
string m_aSubject;
};
//医生类
class Doctor:virtual public Person
{
public:
Doctor(string department=NULL):
m_aDepartment(department){};
void setDepart(string departemt);
string getDepart()const;
private:
string m_aDepartment;
};
//医学院教师类
class TechDoc:public Teacher,public Doctor
{
public:
TechDoc(string aNumber,string aName,string aSubject,string aChife,string aAcademic);
string getAcademic()const;
private:
string m_strAcademic;
};
/***************************************************/
//人员类函数
Person::Person(string id,string name)
{
m_aId = id;
m_aName = name;
}
void Person::setId(string id)
{
m_aId = id;
}
string Person::getID()const
{
return m_aId;
}
void Person::setName(string name)
{
m_aName = name;
}
string Person::getName()const
{
return m_aName;
}
//教师类函数
void Teacher::setSubject(string Subject)
{
m_aSubject = Subject;
}
string Teacher::getSubject()const
{
return m_aSubject;
}
//医生类函数
void Doctor::setDepart(string departemt)
{
m_aDepartment = departemt;
}
string Doctor::getDepart()const
{
return m_aDepartment;
}
//医学院教师类函数
TechDoc::TechDoc(string aNumber,string aName,string aSubject,string aChife,string aAcademic):Person(aNumber,aName),Teacher(aSubject),Doctor(aChife),m_strAcademic(aAcademic){};
string TechDoc::getAcademic()const
{
return m_strAcademic;
}
/***************************************************/
int main(void)
{
TechDoc t1("2012011","李丽","物理","骨科","专家");
cout<<"编号:"<<t1.getID()<<endl;
cout<<"姓名:"<<t1.getName()<<endl;
cout<<"授课科目:"<<t1.getSubject()<<endl;
cout<<"主治科室:"<<t1.getDepart()<<endl;
cout<<"职称:"<<t1.getAcademic()<<endl;
system("pause");
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
预览
除特别注明外,本站所有文章均为 Windcoder网 原创,转载请注明出处来自: ji-cheng-lian-xi-zhi-yi-xue-yuan-jiao-shi-lei-c
Loading comments...

预览
暂无数据