#include <iostream>
using namespace std;
class person
{
public:
person(string a,string b)
{
name = a;
sex = b;
cout << __func__ << ":" << __LINE__ << endl;
}
~person()
{
cout << __func__ << ":" << __LINE__ << endl;
}
void get_show()
{
cout<<"姓名:"<<name<<endl;
cout<<"性别:"<<sex<<endl;
}
private:
string name;
string sex;
};
class teacher:public person
{
public:
teacher(string a,string b,int sa,string ra):person(a,b)
{
salary = sa;
rank = ra;
cout << __func__ << ":" << __LINE__ << endl;
}
~teacher()
{
cout << __func__ << ":" << __LINE__ << endl;
}
void get_show1()
{
cout<<"教师:"<<endl;
get_show();
cout<<"职称:"<<rank<<endl;
cout<<"工资:"<<salary<<endl;
cout<<endl;
}
private:
int salary;
string rank;
};
class student:public person
{
public:
student(string a,string b,string c,float s):person(a,b)
{
score = s;
stu_cla = c;
cout << __func__ << ":" << __LINE__ << endl;
}
~student()
{
cout << __func__ << ":" << __LINE__ << endl;
}
void get_show2()
{
cout<<"学生:"<<endl;
get_show();
cout<<"班级:"<<stu_cla<<endl;
cout<<"成绩:"<<score<<endl;
cout<<endl;
}
private:
int score;
string stu_cla;
};
int main()
{
teacher tea("周sir","男",5000,"教师");
tea.get_show1();
student stu("张三","男","19-1",99);
stu.get_show2();
return 0;
}
“姓名”和“性别”是教师、学生共有的属性,“职称”和“工资”是教师特有的属性, “班级”和“成绩”是学生特有的。 请用类模拟
最新推荐文章于 2024-05-13 09:55:25 发布