• 实验:编写一个人员信息管理系统。这个系统的功能是:交互式的实现校园人员信息的录入与显示。


    学校里,主要有四类人员:大学本科学生、教师、研究生和助教。
    大学本科生每周有固定的学时数。教师除了固定的学时数外,还有每周的教学时数。研究生除了固定的学时数外,每周还可以自由做一定的研究。助教生除了上课外,还要做研究和一定的教学工作。
    人员的基本信息包括姓名、编号、性别、身份证号、总学时数以及每周固定学时数。各个人员之间的关系: people类派生出student 类和teacher类,student 类派生出graduate类, graduate类和teacher类派生出TA类。

    //people.h
    #include<iostream>
    #include<string>
    using namespace std;
    class people
    {
    public:
    people();
    people( string m_name, int m_number, char m_sex, int m_id, int m_sum, int m_week);//对数据初始化
    void show();
    string sexwm(char sex);
    ~people();
    protected:
    string name;//姓名
    int number;//编号
    char sex;//性别
    int id;//身份证号
    int sum;//总学时数
    int week;//周固定学时数
    };
    //people.cpp
    #include "pch.h"
    #include "people.h"


    people::people()
    {
    }


    people::people(string m_name, int m_number, char m_sex, int m_id, int m_sum, int m_week)
    {
    name = m_name;
    number = m_number;
    sex = m_sex;
    id = m_id;
    sum = m_sum;
    week = m_week;
    }

    void people::show()
    {
    cout << "人员信息" << endl;
    }
    string people::sexwm(char sex)
    {
    if (sex == 'm') return "man";
    else return "woman";
    }

    people::~people()
    {
    }
    //student.h
    #pragma once
    #include "people.h"
    class student :virtual public people
    {
    public:
    student();
    student( string m_name, int m_number, char m_sex, int m_id, int m_sum, int m_week);
    void show();
    ~student();
    };
    //student.cpp
    #include "pch.h"
    #include "student.h"


    student::student()
    {
    }

    student::student(string m_name, int m_number, char m_sex, int m_id, int m_sum, int m_week)
    {
    name = m_name;
    number = m_number;
    sex = m_sex;
    id = m_id;
    sum = m_sum;
    week = m_week;
    }
    void student::show()
    {
    cout << "姓名" << ' ' << "编号" << ' ' << "性别" << ' ' << "身份证号" << ' ' << "总学时" << ' ' << "周固定学时" << endl;
    cout << name << ' ' << number << ' ' << sexwm(sex) << ' ' << id << ' ' << sum << ' ' << week << endl;
    }


    student::~student()
    {
    }
    //teacher.h
    #pragma once
    #include "people.h"
    class teacher :virtual public people
    {
    public:
    teacher();
    teacher(string m_name, int m_number, char m_sex, int m_id, int m_sum, int m_week,int m_teach);
    void show();
    ~teacher();
    protected:
    int teach;//教学时数
    };
    //teacher.cpp
    #include "pch.h"
    #include "teacher.h"


    teacher::teacher()
    {
    }

    teacher::teacher(string m_name, int m_number, char m_sex, int m_id, int m_sum, int m_week, int m_teach)
    {
    name = m_name;
    number = m_number;
    sex = m_sex;
    id = m_id;
    sum = m_sum;
    week = m_week;
    teach = m_teach;
    }

    void teacher::show()
    {
    cout << "姓名" << ' ' << "编号" << ' ' << "性别" << ' ' << "身份证号" << ' ' << "总学时" << ' ' << "周固定学时" <<' '<<"教学时数"<< endl;
    cout << name << ' ' << number << ' ' << sexwm(sex) << ' ' << id << ' ' << sum << ' ' << week << ' ' << teach << endl;
    }

    teacher::~teacher()
    {
    }

    //graduate.h
    #pragma once
    #include "student.h"
    class graduate :virtual public student
    {
    public:
    graduate();
    graduate(string m_name, int m_number, char m_sex, int m_id, int m_sum, int m_week);
    void show();
    ~graduate();
    };
    //graduate.cpp

    #include "pch.h"
    #include "graduate.h"


    graduate::graduate()
    {
    }

    graduate::graduate(string m_name, int m_number, char m_sex, int m_id, int m_sum, int m_week)
    {
    name = m_name;
    number = m_number;
    sex = m_sex;
    id = m_id;
    sum = m_sum;
    week = m_week;
    }
    void graduate::show()
    {
    cout << "姓名" << ' ' << "编号" << ' ' << "性别" << ' ' << "身份证号" << ' ' << "总学时" << ' ' << "周固定学时" << endl;
    cout << name << ' ' << number << ' ' << sexwm(sex) << ' ' << id << ' ' << sum << ' ' << week << endl;
    cout << "可自由做一定研究" << endl;
    }

    graduate::~graduate()
    {
    }

    //TA.h
    #pragma once
    #include "graduate.h"
    #include "teacher.h"
    class TA :
    public graduate,public teacher
    {
    public:
    TA();
    TA(string m_name, int m_number, char m_sex, int m_id, int m_sum, int m_week,int teach);
    void show();
    ~TA();
    };
    //TA.cpp
    #include "pch.h"
    #include "TA.h"


    TA::TA()
    {
    }

    TA::TA(string m_name, int m_number, char m_sex, int m_id, int m_sum, int m_week, int m_teach)
    {
    name = m_name;
    number = m_number;
    sex = m_sex;
    id = m_id;
    sum = m_sum;
    week = m_week;
    teach = m_teach;
    }
    void TA::show()
    {
    cout << "姓名" << ' ' << "编号" << ' ' << "性别" << ' ' << "身份证号" << ' ' << "总学时" << ' ' << "周固定学时" << ' ' << "教学时数" << endl;
    cout << name << ' ' << number << ' ' << sexwm(sex) << ' ' << id << ' ' << sum << ' ' << week << ' ' << teach << endl;
    cout << "可自由做一定研究" << endl;
    }
    TA::~TA()
    {
    }

    //main.cpp
    #include "pch.h"
    #include "people.h"
    #include "student.h"
    #include "teacher.h"
    #include "graduate.h"
    #include "TA.h"
    #include <iostream>
    using namespace std;
    int main(http://www.my516.com)
    {
    student a("a", 1, 'm', 1801, 100, 10);
    a.show();
    teacher b("b", 2, 'w', 1802, 100, 10, 20);
    b.show();
    graduate c("c", 3, 'm', 1803, 100, 10);
    c.show();
    TA d("d", 4, 'w', 1804, 100, 10, 20);
    d.show();
    }

    ---------------------

  • 相关阅读:
    eclipse导出maven java project为jar包,包含第三方依赖jar包以及普通Java Project 导出包含第三方
    Joda-Time 工具类的使用
    spring-boot 分布式定时任务锁shedlock
    [DB][MyBatis]利用mybatis-paginator实现分页(目前看到MyBatis下最好的分页实现)
    KafKa脚本
    Es重建索引
    Canal1.1.4同步数据至Es时间格式问题
    CDH5.12.1添加Phoenix4.14
    CDH5.12.1利用Sqoop将mysql数据导入hive
    CDH5.12.1将Spark1.6升级到Spark2.2
  • 原文地址:https://www.cnblogs.com/hyhy904/p/11161449.html
Copyright © 2020-2023  润新知