Experiment: write a personnel information management systems. The function of this system are: interactive entry realization of the campus staff and information display.

School, there are four categories of people: college undergraduate students, teachers, graduate students and teaching assistants.
University undergraduates have a fixed number of hours per week. Teachers addition to a fixed number of hours, as well as weekly teaching hours. Graduate addition to a fixed number of hours per week can also do some research freedom. In addition to the extra-curricular teaching assistant students, we need to do some research and teaching.
Basic information of personnel including name, number, gender, ID number, the total number of hours and a fixed number of hours per week. The relationship between the various personnel: people like derived class and the teacher student class, student class derived graduate classes, graduate class and the class teacher TA derived class.

//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 << "姓名" << '\t' << "编号" << '\t' << "性别" << '\t' << "身份证号" << '\t' << "总学时" << '\t' << "周固定学时" << endl;
	cout << name << '\t' << number << '\t' << sexwm(sex) << '\t' << id << '\t' << sum << '\t' << 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 << "姓名" << '\t' << "编号" << '\t' << "性别" << '\t' << "身份证号" << '\t' << "总学时" << '\t' << "周固定学时" <<'\t'<<"教学时数"<< endl;
	cout << name << '\t' << number << '\t' << sexwm(sex) << '\t' << id << '\t' << sum << '\t' << week << '\t' << 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 << "姓名" << '\t' << "编号" << '\t' << "性别" << '\t' << "身份证号" << '\t' << "总学时" << '\t' << "周固定学时" << endl;
	cout << name << '\t' << number << '\t' << sexwm(sex) << '\t' << id << '\t' << sum << '\t' << 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 << "姓名" << '\t' << "编号" << '\t' << "性别" << '\t' << "身份证号" << '\t' << "总学时" << '\t' << "周固定学时" << '\t' << "教学时数" << endl;
	cout << name << '\t' << number << '\t' << sexwm(sex) << '\t' << id << '\t' << sum << '\t' << week << '\t' << 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()
{
	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();
}

Guess you like

Origin blog.csdn.net/weixin_43981315/article/details/94759835