学生信息管理系统3rd


​ 我们知道,一个学校有本科生,研究生,老师等各类人员。通过继承性的学习,我们可以对此进行管理。

#pragma once
#include<iostream>
#include<string>
using namespace std;
class Person
{
protected:
string ID;
string name;
string sex;
public:
Person(string = "000", string = "", string = "男");
void Input();
string GetID();
string GetName();
string GetSex();

};

class Student :virtual public Person
{
protected:
string speciality;
public:
Student(string, string, string, string = "");
void Input();
string GetSpeciality();

};
class Graduate :virtual public Student
{
protected:
string researchTopic;
public:
Graduate(string = "000", string = "", string = "男", string = "", string = "");
void Input();
string GetResearchTopic();
};
class Teacher :virtual public Person
{
public:
string academicTitle;
public:
Teacher(string, string , string , string = "");
void Input();
string GetAcademicTitle();

};
class PostgraduateOnJob :public Graduate, public Teacher
{
public:
PostgraduateOnJob(string = "000", string = "", string = "男", string = "", string = "", string = "");
void Input();

};
#include "Person.h"

Person::Person(string id, string na, string se):ID(id),name(na),sex(se)
{
}

void Person::Input()
{
cout << "请输入信息\n";
cout << "编 号:";
cin >> ID;
cout << "姓 名:";
cin >> name;
cout << "性 别 (男/女):";
cin >> sex;
}

string Person::GetID()
{
return ID;
}

string Person::GetName()
{
return name;
}

string Person::GetSex()
{
return sex;
}

Student::Student(string id, string na, string se, string sepc):Person(id,na,se),speciality(sepc)
{
}

void Student::Input()
{
Person::Input();
cout << "专 业:";
cin >> speciality;
}

string Student::GetSpeciality()
{
return speciality;
}



Teacher::Teacher(string id, string na, string se, string title):Person(id,na,se),academicTitle(title)
{
}

void Teacher::Input()
{
Person::Input();
cout << "职 称:";
cin >> academicTitle;
}

string Teacher::GetAcademicTitle()
{
return academicTitle;
}

Graduate::Graduate(string id, string na, string se, string sepc, string rese):Person(id,na,se),Student(id,na,se,sepc),researchTopic(rese)
{

}

void Graduate::Input()
{
Student::Input();
cout << "研究课题:";
cin >> researchTopic;
}

string Graduate::GetResearchTopic()
{
return researchTopic;
}

PostgraduateOnJob::PostgraduateOnJob(string id, string na, string se, string sepc, string rese, string title):Person(id,na,se),Student(id,na,se,sepc),Graduate(id,na,se,sepc,rese),Teacher(id,na,se,title)
{

}

void PostgraduateOnJob::Input()
{
Graduate::Input();
cout << "职 称:";
cin >> academicTitle;
}
#include "Person.h"
#include<iomanip>
const int SUM = 3;
class Group
{
protected:
PostgraduateOnJob st[SUM];
int sum;
public:
Group();
void Input();
void SortByID();
void Output();
};

Group::Group()
{
sum = SUM;
}

void Group::Input()
{
int i;
for (i = 0; i < sum;i++)
{
st[i].Input();
}
}

void Group::SortByID()
{
int index, i, k;
PostgraduateOnJob temp;
for (k = 0;k < sum - 1;k++)
{
index = k;
for (i = k + 1;i < sum;i++)
if (st[i].GetID() < st[index].GetID())
index = i;
if (index != k)
{
temp = st[index];
st[index] = st[k];
st[k] = temp;
}
}
}

void Group::Output()
{
int i;
cout << endl << "学生信息表" << endl;
cout << "编号 姓名 性别 专 业 研究课题 职称" << endl;
for (i = 0;i < sum;i++)
{
cout << st[i].GetID() << setw(8) << st[i].GetName() << setw(7) << st[i].GetSex() << setw(8) << st[i].GetSpeciality() << setw(11) << st[i].GetResearchTopic() << setw(7) << st[i].GetAcademicTitle() << endl;
}
}
int main()
{
Group g1;
g1.Input();
g1.SortByID();
g1.Output();
system("pause");
return 0;
}

下面是测试结果

请输入信息
编 号:10003
姓 名:李华
性 别 (男/女):男
专 业:Coumputer_Science
研究课题:区块链
职 称:助理教授
请输入信息
编 号:10002
姓 名:刘娟
性 别 (男/女):女
专 业:应用数学
研究课题:Matlab
职 称:讲师
请输入信息
编 号:10001
姓 名:Bob
性 别 (男/女):男
专 业:English
研究课题:20世纪欧美文学
职 称:外籍教授

学生信息表
编号 姓名 性别 专 业 研究课题 职称
10001 Bob 男 English20世纪欧美文学外籍教授
10002 刘娟 女应用数学 Matlab 讲师
10003 李华 男Coumputer_Science 区块链助理教授

(…为了简明起见,本程序在设计上做了一些简化,如没有采用用户界面,还有待提高…)


Author: T1g3r
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint policy. If reproduced, please indicate source T1g3r !
评论
  TOC