1、题为:定义一个基类有姓名、年龄,再由基类派生出教师类和学生类,教师类增加工号、职称和工资,学生类增加学号、班级、专业和入学成绩。 请大神们给出答案./定义一个基类有姓名、年龄,再由基类派生出教师类和学生类,教师类增加工号、职称和工资,学生类增加学号、班级、专业和入学成绩#includeusing namespace std;#includeclass Person/基类public:Person(string n,int a):name(n),age(a)void disp()cout“姓名“nameendl;cout“年龄“ageendl;protected:string name;int
2、age;class Teacher:public Person/派生类 teacherpublic:Teacher(string n,int a,int n1,string w,int p):Person(n,a),num(n1),wa(w),pay(p)void dist()disp();cout“工号 “num“n“职称“wa“n“工资“pay“nn“;protected:int num;string wa;int pay;class Student:public Person/派生类 studentpublic:Student(string n,int a,int n1,string c
3、1,string z,int c2):Person(n,a),num1(n1),cla(c1),zy(z),cj(c2)void diss()disp();cout“学号“num1“n“班级“cla“n“专业“zy“n“入学成绩“cj“n“;protected:int num1;string cla;string zy;int cj;void main()Teacher teach1(“Li“,22,1001,“professor“,4500);teach1.dist();Student stud1(“Sun“,19,1001,“class 1“,“computer“,500);stud1.diss();