#include<iostream.h>
#include<string.h>
class stud
{
protected:
char *addr;
double tel;
public:
stud(char *a,double t)
{
addr=new(strlen(a)+1);
tel=t;
}
~stud()
{
delete []addr;
}
void show();
};
void show()
{
cout<<"地址:"<<addr<<endl;
cout<<"电话号码:"<<tel<<endl;
}
class score:virtual public stud
{
protected:
float math;
float eng;
public:
score(char *a,double t,float m,float e):stud(a,t)
{
math=m;
eng=e;
}
void show();
};
void score::show()
{
stud::show();
cout<<"数学分数:"<<math<<endl;
cout<<"英语分数:"<<eng<<endl;
}
class person:virtual public stud
{
protected:
char *name;
long int id;
public:
person(char *a,double t,char *n,long int i):stud(a,t)
{
name=new(strlen(n)+1);
id=i;
}
void show();
~person()
{
delete []name;
}
};
void person::show()
{
stud::show();
cout<<"姓名:"<<name<<endl;
cout<<"身份证号码:"<<id<<endl;
}
class teacher:virtual public stud,public person
{
protected:
char *degree;
char *dep;
public:
teacher(char *a,double t,char *n,long int i,char *d1,char *d2):stud(a,t),person(n,i)
{
degree=new(strlen(d1)+1);
dep=new(strlen(d2)+1);
}
~teacher()
{
delete []degree;
delete []dep;
}
void show();
};
void teacher::show()
{
person::show();
cout<<"学位:"<<degree<<endl;
cout<<"部门:"<<dep<<endl;
}
class student:virtual public stud,public person
{
protected:
int old;
int sno;
public:
student(char *a,double t,char *n,long int i,int o,int s):stud(a,t),person(n,i)
{
old=o;
sno=s;
}
void show();
};
void student::show()
{
person::show();
cout<<"年龄:"<<old<<endl;
cout<<"学号:"<<sno<<endl;
}
class score:virtual public student
{
protected:
float math;
float eng;
public:
score(char *a,double t,char *n,long int i,int o,int s,float m,float e):stud(a,t),person(n,i),student(o,s)
{
math=m;
eng=e;
}
void show();
};
viod score::show()
{
student::show();
cout<<"数学分数:"<<math<<endl;
cout<<"英语分数:"<<eng<<endl;
}
int main()
{
stud p1("武汉生物工程学院","89661064");
p1.show();
score p2("武汉生物工程学院","89661064",96,86);
p2.show();
person p3("武汉生物工程学院","89661064","小鑫","420583198901140055");
p3.show;
teacher p4("武汉生物工程学院","89661064","小鑫","420583198901140055","博士","计算机系");
p4.show;
student p5("武汉生物工程学院","89661064","小鑫","420583198901140055",21,35);
p5.show();
score p6("武汉生物工程学院","89661064","小鑫","420583198901140055",21,35,96,86);
p6.show();
}