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