#include <iostream>
#include<string.h>
using namespace std;
class person
{ private:
string name,sex;
int number;
public:
void setperson(string n,string s,int nu)
{
name = n;
sex = s;
number = nu;
}
void output();
};
void person::output()
{
cout<<"name: "<<name<<endl;
cout<<"sex: "<<sex<<endl;
cout<<"number: "<<number<<endl;
}
class student:public person
{
private:
int grade;
public:
student(){}
student(string n,string s,int nu,int g)
{
person::setperson(n,s,nu);
grade=g;
}
void output()
{
person::output();
cout<<"grade: "<<grade<<endl;
}
};
class teacher:public person
{
private:
int teachage;
public:
teacher(){}
teacher(string n,string s,int nu,int t)
{
person::setperson(n,s,nu);
teachage=t ;
}
void output()
{
person::output();
cout<<"teachage: "<<teachage<<endl;
}
};
int main()
{
student m("李磊","男",16064,100);
m.output();
teacher n("赵宝宝","男",1141,20);
n.output();
}
1.定义一个人员类Person,包括姓名、编号、性别等数据成员和用于输入、输出的成员函数,在此基础上派生出学生类Student类(增加成绩)和教师类Teacher(增加教龄),并实现对学生和教师信息的
最新推荐文章于 2024-07-05 20:59:19 发布