64,637
社区成员
发帖
与我相关
我的任务
分享
#include<iostream>
#include<string>
#include<string.h>
using namespace std;
class School
{
private:
string object;
string name;
int age;
int numeber;
char sex;
public:
School(const string& object1,const string& name1, const int& age1, const int& numeber1, char sex1)
{
if (sex1 == 'm')
sex = 0;
if (sex1 == 'f')
sex = 1;
age = age1;
numeber = numeber1;
name = name1;
object =object1;
}
void printf();
};
void School::printf()
{
cout << "身份:" << object << endl;
cout <<"姓名:"<<name<<endl;
cout << "年龄: " << age<<endl;
if (sex == 0)
cout << "性别:男" << endl;
if (sex ==1)
cout<<"性别:女:"<<endl;
cout << "numeber:" << numeber << endl;
}
class Student :public School
{
private:
int ave_gar; //平均成绩
public:
Student(const string& object1, const string& name1, const int& age1, const int& numeber1, char sex1,int ave_gar1) :School
(object1, name1, age1, numeber1,sex1), ave_gar(ave_gar1)
{
cout << "平均成绩:" << ave_gar << endl;
}
};
class Teacher :public School
{
private:
string teacher; //教授的学科
public:
Teacher(const string& object1,const string& name1, const int& age1, const int& numeber1, char sex1, string teacher1) :School
(object1,name1,age1,numeber1,sex1), teacher(teacher1)
{
cout << "教授的学科:" << teacher << endl;
}
};
class Staff :public School
{
private:
string work;
public:
Staff(const string& object1, const string& name1, const int& age1, const int& numeber1, char sex1,string work1):School
(object1, name1, age1,numeber1, sex1),work(work1)
{
cout << "工作类型:" << work<<endl;
}
};
int main()
{
Teacher a("教师","王一",(const int&)32,(const int&)2017320,'f',"History");
a.printf();
Student b("学生","李二",(const int&)15,(const int&)2017203,'m',45);
b.printf();
Staff c("职工","赵三",(const int&)28,(const int&)2017256,'f',"清洁");
c.printf();
return 0;
}