刚学C++帮忙分析一下
#include <iostream.h>#include <string.h>
class person
{
protected:
char name[20];
int sex;
int age;
public:
Person(char *na,int ag,int se)
{
strcpy(name, na);
sex= se;
age = ag;
}
void initname(char *na)
{
strcpy(name, na);
}
void initsex(int se)
{
sex=se;
}
void initage(int ag)
{
age=ag;
}
char * getname()
{
return name;
}
int getage()
{
return age;
}
int getsex()
{
return sex;
}
void printf()
{
cout<<"姓名:"<<name<<endl;
cout<<"性别:"<<sex<<endl;
cout<<"年龄:"<<age<<endl;
}
};
class teacher:public person
{
int post;
int salary;
public:
teacher(char *na,int ag,int se,int po,int sa):person(na,ag,se)
{
post=po;
salary=sa;
}
void printf()
{
person::printf();
cout<<"职位:"<<post<<endl;
cout<<"工资:"<<salary<<endl;
}
};
class student:public person
{
char xuehao[20];
char Class[20];
public:
student(char *na,int ag,int se,char *xh,char *cl):person(na,ag,se)
{
strcoy(xuehao,xh);
strcpy(Class,cl);
}
printf()
{
person::printf();
cout<<"学号:"<<xuehao<<endl;
cout<<"班级:"<<Class<<endl;
}
};
void main()
{
teacher te("liang",22,男,教授,5000);
student st("liang",22,男,"20112111225","11B");
te.printf();
cout<<"__________________"<<endl;
st.printf();
}