#include<iostream>
#include<string.h>
using namespace std;
class person
{
private:
string name,sex;
int age;
public:
person (string n,string s,int a)
{
name=n;
sex=s;
age=a;
}
virtual void print()
{
cout<<"姓名: "<<name<<endl;
cout<<"性别: "<<sex<<endl;
cout<<"年龄: "<<age<<endl;
}
};
class student:public person
{
private:
string speciality;
public:
friend class stuacher;
student (string n,string s,int a,string sp):person(n,s,a)
{
speciality=sp;
}
void print()
{
person::print();
cout<<"专业: "<<speciality<<endl;
}
};
class teacher:public person
{
private:
string department;
public:
friend class stuteacher;
teacher (string n,string s,int a,string d):person(n,s,a)
{
department=d;
}
string show(){
cout<<"系别: "<<department<<endl;
}
virtual void print()
{
person::print();
cout<<"系别: "<<department<<endl;
}
};
class stuteacher:public student,public teacher
{
public:
stuteacher(string n,string s,int a,string sp,string d):student(n,s,a,sp),teacher(n,s,a,d)
{
}
virtual void print(){
student::print();
teacher::show();
}
};
int main()
{
student s("王二麻子","男",20,"物联网");
s.print();
teacher t("二嘎子","男",10,"计算机");
t.print();
stuteacher st("栋宝宝","男",40,"物联网","在计算机学院教物联网");
st.print();
return 0;
}
3开发一个简单的大学人员管理程序,该程序可以管理大学的一些基本人员:学生(student)、教师(teacher)、教授(professor)。首先设计一个虚基类person。通过该类保存人员的最
最新推荐文章于 2024-05-26 14:38:41 发布