一、问题及代码:
<pre class="cpp" name="code">/*
02.* 文件名称:教师干部类
03.* 作 者:张岚
04.* 完成日期:2016年5月18日
05.* 版 本 号:v1.0
06.* 对任务及求解方法的描述部分:
07.* 输入描述:
08.* 问题描述: 略
09.* 程序输出: 略
10.* 问题分析: 略
11.* 算法设计: 略
12.*/
#include <iostream>
14.#include <string>
15.using namespace std;
16.class Teacher
17.{
18.private:
19. int age;
20. string name;
21. bool xing;//输入1为男,0为女
22. string title;//(职称)
23.public:
24. void set(int a,string n,bool x,string t);
25. void dispaly();
26.};
27.void Teacher::set(int a,string n,bool x,string t)
28.{
29. age=a;name=n;xing=x;title=t;
30.}
31.void Teacher::dispaly()
32.{
33. cout<<"姓名:"<<name<<endl;
34. cout<<"年龄:"<<age<<endl;
35. cout<<"性别:"<<(xing?"男":"女")<<endl;
36. cout<<"职称:"<<title<<endl;
37.}
38.class Cadre
39.{
40.private:
41. int age;
42. string name;
43. bool xing;//输入1为男,0为女
44. string post;//职务
45.public:
46. void set(int a,string n,bool x,string p);
47. string getPost();
48.};
49.string Cadre::getPost()
50.{
51. return post;
52.}
53.void Cadre::set(int a,string n,bool x,string p)
54.{
55. age=a;name=n;xing=x;post=p;
56.}
57.class Teacher_Cadre:public Teacher,public Cadre
58.{
59.private:
60. double wages;
61.public:
62. void setWages(double w);
63. void show();
64. double getWages();
65.};
66.double Teacher_Cadre::getWages()
67.{
68. return wages;
69.}
70.void Teacher_Cadre::setWages(double w)
71.{
72. wages=w;
73.}
74.void Teacher_Cadre::show()
75.{
76. dispaly();
77.}
78.void main()
79.{
80. Teacher_Cadre t1;
81. t1.Teacher::set(42,"曾辉",1,"副教授");
82. t1.Cadre::set(42,"曾辉",1,"主任");
83. t1.setWages(1534.5);
84. t1.show();
85. cout<<"职务:"<<t1.getPost()<<endl;
86. cout<<"工资:"<<t1.getWages()<<endl;
87.}
二、运行结果:
三、心得体会:
多练习才会熟练派生不同类型的类
四、知识点总结:
当输入一个字符串型的数据时需要在该数据上加双引号。