#include<iostream>
#include<string>
using namespace std;
class person{
public:
void input()
{
cout<<"输入编号:";
cin>>number;
cout<<"输入姓名:";
cin>>name;
}
void show()
{
cout<<"编号:"<<number<<endl;
cout<<"姓名:"<<name<<endl;
}
protected:
int number;
string name;
};
class student:public person{
public:
void input()
{
person::input();
cout<<"输入班号:";
cin>>NO;
cout<<"输入成绩:";
cin>>score;
}
void show()
{
person::show();
cout<<"班号:"<<NO<<endl;
cout<<"成绩:"<<score<<endl;
}
protected:
int NO;
float score;
};
class teacher:public person{
public:
void input()
{
person::input();
cout<<"输入职称:";
cin>>title;
cout<<"输入部门:";
cin>>dept;
}
void show()
{
person::show();
cout<<"职称:"<<title<<endl;
cout<<"部门:"<<dept<<endl; }
protected:
string title,dept;
};
int main()
{
student stu1;
teacher teac1;
cout<<"请根据提示输入学生信息"<<endl;
stu1.input();
cout<<"学生信息如下"<<endl;
stu1.show();
cout<<endl;
cout<<"请根据提示输入老师信息"<<endl;
teac1.input();
cout<<"老师信息如下"<<endl;
teac1.show();
cout<<endl;
return 0;
}
作业5.18
最新推荐文章于 2024-05-19 22:50:18 发布