(虚基类和虚函数)学校人员管理系统

  • Post author:
  • Post category:其他

【问题描述】

建立一个简单的学校人员管理系统,包括对学生、员工和在职学生(既是员工又是学生)的管理。需要完成如下功能:
1、建立一个School类,在其中定义增加人员的Append函数。
2、建立一个基类Person类,要具有姓名和性别的属性,并把输出函数ShowMe()定义为虚函数;
3、建立一个员工Staff类和一个学生类Student,均由Person继承而来。要求可以输出员工类(学生类)对象的属性(姓名、性别和工作证号码(或学生学号),分别写出对ShowMe()函数的具体实现。
4、建立一个在职学生类Staff_Student类,由员工类和学生类继承而来。写出对ShowMe()函数的具体实现,可以输出对象属性,。
5、重载,实现用cin为员工类、学生类和在职学生类对象赋值。
6、编写main()主函数,测试上述功能。

在这里插入图片描述
打了半天呜呜呜呜呜呜呜上课不听课自学火葬场
看完请点个赞吧

#include  <iostream>  
using  namespace  std;
#include<string>
class  Staff
{
protected:
    int  number;
    string  name;
    int  age;
public:
    Staff(int  num, const  string  na, int  a)
    {
        number = num;
        name = na;
        age = a;
    }
    void  Display()
    {
        cout << name << "  is  a  staff,  " << age << "  yeas  old." << endl;
    }
};
class  Teacher :virtual public Staff 
{
protected:
    string  title;          //职称
public:
    Teacher(int  num, const  string  na, int  a, const  string  ttl);
    void  Display()
    {
        cout << name << "  is  a  teacher,  " << age << "  yeas  old,  " << title << ".  " << endl;
    }
};
Teacher::Teacher(int  num, const  string  na, int  a, const  string  ttl):Staff(num,na,a)
{
    title = ttl;
}
class  Management :virtual public Staff
{
protected:
    string  post;                          //职务
public:
    Management(int  num, const  string  na, int  a, const  string  pt);
    void  Display()
    {
        cout << name << "  is  a  manager,  " << age << "  yeas  old,  " << post << ".  " << endl;
    }
};
Management::Management(int    num, const  string  na, int  a, const  string  pt) :Staff(num, na, a)
{
    post = pt;
}
class  TeacherManagement :virtual public Staff,Teacher, Management
{
public:
    TeacherManagement(int  num, const  string  na, int  a, const  string  ttl, const  string  pt);
    void  Display()
    {
        cout << name << "  is  a  teacher  manager,  " << age << "  yeas  old,  " << title << ",  " << post << ".  " << endl;
    }
};
TeacherManagement::TeacherManagement(int  num, const  string  na, int  a, const  string  ttl, const  string  pt) :Staff(num, na, a),Teacher(num,na,a,ttl), Management(num, na, a, post)
{
    number = num;
    age = a;
    name = na;
    title = ttl;
    post = pt;
}
int  main()
{
    Staff s1(1, "Zhao", 20);
    Teacher t1(1, "Zhang", 30, "Lecturer");
    Management m1(1, "Wang", 50, "Dean");
    TeacherManagement tm1(1, "Li", 40, "Department head");
    s1.Display();
    t1.Display();
    m1.Display();
    tm1.Display();
    return  0;
}

看完请点个赞吧


版权声明:本文为qq_51593505原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。