using namespace std;
class person{
public:
person()
{}
void input()
{
cout<<"请输入编号:";
cin>>num;
cout<<"请输入姓名:";
cin>>name;
}
void show()
{
cout<<"编号:"<<num<<endl;
cout<<"姓名:"<<name<<endl;
}
private:
int num;
string name;
};
class student:public person{
public:
student():person()
{}
void inputs()
{
cout<<"请输入学生信息:"<<endl;
person::input();
cout<<"请输入班号:";
cin>>cnum;
cout<<"请输入分数:";
cin>>score;
}
void showstud()
{
cout<<"学生信息如下:"<<endl;
person::show();
cout<<"班号:"<<cnum<<endl;
cout<<"成绩:"<<score<<endl;
}
private:
int cnum;
int score;
};
class teacher:public person{
public:
teacher():person()
{}
void inputt()
{
cout<<"请输入老师信息:"<<endl;
person::input();
cout<<"请输入职称:";
cin>>zc;
cout<<"请输入部门:";
cin>>bm;
}
void showteach()
{
cout<<"老师信息如下:"<<endl;
person::show();
cout<<"职称:"<<zc<<endl;
cout<<"部门:"<<bm<<endl;
}
private:
string zc;
string bm;
};
int main()
{
student stu1;
stu1.inputs();
stu1.showstud();
teacher tea1;
tea1.inputt();
tea1.showteach();
system("pause");
return 0;
}
5.18
最新推荐文章于 2024-05-19 22:50:18 发布