#include <iostream.h>
#include <string.h>
class CPerson //基类
{
public:
void SetData()
{
cout<<"请输入姓名"<<endl;
cin>>pName;
cout<<"请输入编号";
cin>>pID;
cout<<"请输入性别(女输入0,男输入1)"<<endl;
cin>>bMan;
}
void Output()
{
cout<<"姓名: "<<pName<<endl;
cout<<"编号: "<<pID<<endl;
char *str=bMan?"男":"女";
cout<<"性别: "<<str<<endl;
}
private:
char pName[20]; //姓名
char pID[20]; //编号
int bMan; //性别:0表示女,1表示男
};
class CStudent :public CPerson //CStudent派生类
{
public:
void InputScore()
{
cout<<"请输入学生成绩:"<<endl;
cin>>dbScore;
}
void Print()
{
Output(); //调用基类成员函数
cout<<"成绩:"<<dbScore<<endl;
}
private:
double dbScore; //成绩
};
class CTeacher :public CPerson
{
public:
void InputAge()
{
cout<<"请输入老师教龄:"<<endl;
cin>>inage;
}
void Tprint()
{
Output();
cout<<"教龄: "<<inage<<endl;
}
private:
int inage;
};
void main() //主函数
{
CStudent stu;
stu.SetData();
stu.InputScore();
stu.Print();
CTeacher tea;
tea.SetData();
tea.InputAge();
tea.Tprint();
}