#include<iostream.h> #include<string.h> class cpeople { protected: char name[10]; char sex[4]; int age; public: char getsex[4]; char getname[10]; cpeople(char n[10],char s[4],int ag) { strcpy(name,n); strcpy(sex,s); age=ag; strcpy(getname,n); strcpy(getsex,s); } int getage() { return age; } }; class cstudent:virtual public cpeople { char id[20]; char date[20]; float grade; public: char getdate[20]; char getid[20]; cstudent(char n[10],char s[4],int ag,char id2[20],char da[20],float gr):cpeople(n,s,ag) { strcpy(id,id2); strcpy(date,da); grade=gr; strcpy(getid,id2); strcpy(getdate,da); } float getgrade() { return grade; } }; class cteacher:virtual public cpeople { char job[20]; char depart[20]; char worktime[20]; public: char getjob[20]; char getdepart[20]; char getworktime[20]; cteacher(char n[10],char s[4],int ag,char jo[20],char dep[20],char wo[20]):cpeople(n,s,ag) { strcpy(job,jo); strcpy(depart,dep); strcpy(worktime,wo); strcpy(getjob,jo); strcpy(getdepart,dep); strcpy(getworktime,wo); } }; class cgraduate:public cstudent { char search[20]; char teachername[10]; public: char getsearch[20]; char getteachername[10]; cgraduate(char n[10],char s[4],int ag,char id2[20],char dat[20],float gr,char sea[20],char tea[10]):cstudent(n,s,ag,id2,dat,gr),cpeople(n,s,ag) { strcpy(search,sea); strcpy(teachername,tea); strcpy(getsearch,sea); strcpy(getteachername,tea); } }; class cgradonwork:public cgraduate,public cteacher { public: cgradonwork(char n[10],char s[4],int ag,char jo[20],char dep[20],char wo[20],char id2[20],char dat[20],float gr,char sea[20],char tea[10]):cgraduate( n,s,ag,id2,dat,gr,sea,tea),cteacher(n,s,ag,jo,dep,wo),cpeople(n,s,ag) { cout<<"调用构造函数cgradonwork()"<<endl; } }; void main() { char name1[10],sex1[4],id11[20],date11[20],jo[20],dep[20],wo[20],sea[20],tea[10]; int age1; float grade11; cout<<"***************(1)普通人****************"<<endl; cout<<"***************(2)学生***************"<<endl; cout<<"***************(3)老师***************"<<endl; cout<<"***************(4)研究生**************"<<endl; cout<<"***************(5)在职研究生************"<<endl; int num; cout<<"请输入你所在职位的序号"<<endl; cin>>num; if(num==1) { cout<<"请输入您的姓名,性别,年龄"<<endl; cin>>name1>>sex1>>age1; cpeople pe(name1,sex1,age1); cout<<"此人的信息为"<<pe.getname<<' '<<pe.getsex<<' '<<pe.getage(); } else if(num==2) { cout<<"请输入您的姓名,性别,年龄,学号,入学时间,入学成绩"<<endl; cin>>name1>>sex1>>age1>>id11>>date11>>grade11; cstudent st(name1,sex1,age1,id11,date11,grade11); cout<<"此人的信息为"<<st.getname<<' '<<st.getsex<<' '<<st.getage()<<' '<<st.getid<<' '<<st.getdate<<' '<<st.getgrade()<<endl; } else if(num==3) { cout<<"请输入您的姓名,性别,年龄,职务,部门,工作时间"<<endl; cin>>name1>>sex1>>age1>>jo>>dep>>wo; cteacher te(name1,sex1,age1,jo,dep,wo); cout<<"此人的信息为"<<te.getname<<' '<<te.getsex<<' '<<te.getage()<<' '<<te.getjob<<' '<<te.getdepart<<' '<<te.getworktime<<endl; } else if(num==4) { cout<<"请输入您的姓名,性别,年龄,学号,入学时间,入学成绩,研究方向,导师"<<endl; cin>>name1>>sex1>>age1>>id11>>date11>>grade11>>sea>>tea; cgraduate gr(name1,sex1,age1,id11,date11,grade11,sea,tea); cout<<"此人的信息为"<<gr.getname<<' '<<gr.getsex<<' '<<gr.getage()<<' '<<gr.getid<<' '<<gr.getdate<<' '<<gr.getgrade()<<' '<<gr.getsearch<<' '<<gr.getteachername<<endl; } else { cout<<"请输入您的姓名,性别,年龄,职务,部门,工作时间,学号,入学时间,入学成绩,研究方向,导师"<<endl; cin>>name1>>sex1>>age1>>jo>>dep>>wo>>id11>>date11>>grade11>>sea>>tea; cgradonwork gradon(name1,sex1,age1,jo,dep,wo,id11,date11,grade11,sea,tea); cout<<"此人的信息为"<<gradon.getname<<' '<<gradon.getsex<<' '<<gradon.getage()<<' '<<gradon.getjob<<' '<<gradon.getdepart<<' '<<gradon.getworktime<<endl; cout<<gradon.getid<<' '<<gradon.getdate<<' '<<gradon.getgrade()<<' '<<gradon.getsearch<<' '<<gradon.getteachername<<endl; } }