<>c/c++ To realize a simple school personnel management system

<> Hands on front frame :

This is how the finished product looks :

If you are interested in the rest, copy and paste it :

<> The code is as follows :
//Main.cpp #include"US.h" int People::sizes = 0; int main() { US s; s.start();
s.out(); return 0; }
<> Above Main In function US Class is used to manage people and implement operations ( The right part of the frame diagram at the beginning ).

<>US class :
//US.h #pragma once #include"Student.h" #include"Staff.h" class US :virtual
public Student ,virtual public Staff { public: void start();// Main switch void
outScreen();// Show menu void out();// sign out void Oper();// operation void writeFile();// Save in file
void readFile();// Read from file void deleFile();// Delete saved data protected: People* P = NULL,
* head = P,*temp=NULL; }; //US.cpp #include"US.h" void US::start() {
this->outScreen(); this->Oper(); } void US::outScreen() { cout <<
"---------------------------------------------------------\n"; cout << "\n\n";
cout << " School personnel management system \n"; cout << " Implementation function :\n"; cout << " 1. increase 2. Delete 3. check 4. change
5. Sort by number \n"; cout << " 6. View all information 7. Save in personnel .txt in 8. Read from file \n"; cout << " 9. delete
personnel .txt Data in \n"; cout << "\n\n"; cout <<
"---------------------------------------------------------\n"; } void
US::Oper() { cout << " Input the number to do the corresponding operation , input 0 Then exit \n"; int t; int u; People* p = NULL;
Student* p1 = NULL; Staff* p2 = NULL; while (true) { cin >> t; if (t == 0)
out(); else { switch (t){ case 1: cout << " New student input 1, New staff input 2:\n"; cin >> u; if
(u == 1) { p1 = new Student; p1->addMessage(); if (P == NULL) P = p1; else
P->next = p1; } else { p2 = new Staff; p2->addMessage(); if (P == NULL) P = p2;
else P->next = p2; } if (head == NULL) { head = P; temp = head; } else {
temp->next = P; temp = temp->next; } P = P->next; break; case 2: cout <<
" Enter delete member :"; cin >> u; head=head->delMessage(u); break; case 3: cout <<
" Enter view members :"; cin >> u; p = (head->searchPeople(u)); if(p!=NULL) p->showMess();
break; case 4: head->changePeople(); break; case 5: head->sortPeople(); break;
case 6: p = head; while (p != NULL) { p->showMess(); p = p->next; } break; case
7: writeFile(); break; case 8: readFile(); break; case 9: deleFile(); break;
default: break; } } system("pause"); system("cls"); outScreen(); cout <<
" Input the number to do the corresponding operation , input 0 Then exit \n"; } } void US::out() { exit(0); } void US::writeFile() {
ofstream ofs; People* p = head; ofs.open(" personnel .txt", ios::out | ios::app); while
(p != NULL) { p->writeF(ofs); p = p->next; } ofs.close(); } void US::readFile()
{ ifstream ifs(" personnel .txt", ios::in); char s[80]; while (!ifs.eof()) {
ifs.getline(s, 80); cout << s; cout << '\n'; } ifs.close(); } void
US::deleFile() { ofstream ofs(" personnel .txt", ios::trunc); ofs.close(); }
<> Above is the right part of the frame diagram , Here is the left part :

<>People class :
//People.h #pragma once #include<iostream> #include<fstream> using namespace
std; class People { public: People() { num = 0; sizes = 0; sex = ' '; name = "
"; }; virtual void setBasic();// set information virtual void showMess();// display information virtual
void addMessage();// Add personnel information virtual void outPeople();// General output personnel information virtual void
outOne();// Output a person information virtual void changePeople();// Modify personnel information virtual void
writeF(ofstream& ofs);// write file People* delMessage(int nums);// Delete personnel information People*
searchPeople(int num);// Find people information People* sortPeople();//// Sort according to certain data static int
sizes;// Number of people People* next = NULL; protected: int num;// number char sex;// Gender string
name;// full name }; //People.cpp #include"People.h" People* People::sortPeople()
{// Sort by number People* p = this, * t = this, * head = this; for (int i = 0; i <
sizes; i++) { p = t = this; while (p->next != NULL) { if (p->num >
p->next->num) { p = p->next; t->next = p->next; p->next = t; head = p; } else {
p = p->next; t = t->next; } } } return head; } bool People::judge(People* l,
People* r) { if (l->num > r->num) return true; else return false; } void
People::addMessage() { if (this == NULL) { this->next = new People; People* p =
this->next; p->setBasic(); } else { this->setBasic(); } } People*
People::delMessage(int nums) { People* head=this; People* p = this, * t = this;
int i; for (i = 1; i < nums; i++) p = p->next; if (i == 1) { delete p; return
NULL; } else { t = p; p = p->next; t->next = p->next; delete p; return head; }
} People* People::searchPeople(int num) { People* p = this; if (p != NULL) {
for (int i = 1; i < num; i++) p = p->next; return p; } else { cout <<
" No one !\n"; return NULL; } } void People::outOne() { cout << num << ' ' << sex
<< ' ' << name << '\n'; } void People::outPeople() { People* p = this; while (p
!= NULL) { cout << num << ' ' << sex << ' ' << name << '\n'; p = p->next; } }
void People::changePeople() { People* t = this; cout << " Enter the member information to modify :"; int
u1; cin >> u1; for (int i = 1; i <= u1; i++) t = t->next; if (t == NULL) { cout
<< " No one \n"; } else { int u; cout << " Input operator : \n"; cout <<
"1. Change name ,2. Gender change ,3. Change number \n"; cin >> u; string nName; char x; int nums; switch (u) {
case 1:// Change name cout << " Enter a new name :"; cin >> nName; t->name = nName; break; case
2:// Gender change cout << " Enter new gender :"; cin >> x; t->sex = x; break; case 3:// Change number cout <<
" Enter new number :"; cin >> nums; t->num = nums; break; default: break; } } } void
People::setBasic() { cout << " Enter the number of the new member , Gender (m/w), name :\n"; cin >> num >> sex >>
name; sizes++; } void People::showMess() { if(this!=NULL) cout << " number :" << num
<< '\t'; cout << " Gender :" << sex << '\t'; cout << " name :" << name << '\n'; } void
People::writeF(ofstream& ofs) { People* p = this; if (p == NULL) { cout <<
" no data ! Please do it again \n"; return; } ofs << this->num<<' ' << this->sex<<' ' <<
this->name << '\n'; }
<> above People Is a base class , Next Staff and Student Is a derived class :

<>Staff class :
//Staff.h #pragma once #include"People.h" class Staff : protected People {
public: Staff() { money = 0; workTime = 0; } void setBasic(); void showMess();
void addMessage(); Staff* delMessage(int nums); //Staff* searchPeople(); Staff*
sortPeople(int value);// according to value sort void changePeople(); void writeF(ofstream&
ofs); Staff* next = NULL; protected: int money; int workTime; string type; };
#include"Staff.h" void Staff::setBasic() { cout << " Enter the number of the new member , Gender , name :\n"; cin >>
num >> sex >> name; cout << " Enter employee's salary , working hours :\n"; cin >> this->money >>
this->workTime; cout << " Enter position ( teacher , workers ):\n"; cin >> type; sizes++; } void
Staff::showMess() { cout << " number :" << num << '\t'; cout << " Gender :" << sex << '\t';
cout << " name :" << name << '\t'; cout << " position :" << type << '\t'; cout << " wages :" <<
money << '\t'; cout << " Working hours :" << workTime << '\n'; } void Staff::addMessage()
{ if (this == NULL) { this->next = new Staff; Staff* p = this->next;
p->setBasic(); } else { this->setBasic(); } } Staff* Staff::delMessage(int
nums) { Staff* head=this; Staff* p = this, * t = this; int i; for (i = 1; i <
nums; i++) p = p->next; if (i == 1) { delete p; return NULL; } else { t = p; p
= p->next; t->next = p->next; delete p; return head; } } Staff*
Staff::sortPeople(int value) { Staff* p = this, * t = this, * head = this; if
(value == 1) { for (int i = 0; i < sizes; i++) { p = t = this; while (p->next
!= NULL) { if (p->money > p->next->money) { p = p->next; t->next = p->next;
p->next = t; head = p; } else { p = p->next; t = t->next; } } } } else { for
(int i = 0; i < sizes; i++) { p = t = this; while (p->next != NULL) { if
(p->workTime > p->next->workTime) { p = p->next; t->next = p->next; p->next =
t; head = p; } else { p = p->next; t = t->next; } } } } return head; } void
Staff::changePeople() { Staff* t = this; cout << " Enter the member information to modify :"; int u1; cin
>> u1; for (int i = 1; i <= u1; i++) t = t->next; int u2; cout <<
" Input operator , Choose to change a data :\n"; cout << " 1. Change name ,2. Gender change (m/w),3. Change number ,4. Change salary ,5. Change working hours \n"; cin >>
u2; string nName; char x; int nums; switch (u2) { case 1:// Change name cout <<
" Enter a new name :"; cin >> nName; t->name = nName; break; case 2:// Gender change cout << " Enter new gender :";
cin >> x; t->sex = x; break; case 3:// Change number cout << " Enter new number :"; cin >> nums; t->num
= nums; break; case 4:// Change salary cout << " Enter new salary :"; cin >> nums; t->money = nums;
break; case 5:// Change working hours cout<< " Enter new working time :"; cin >> nums; t->workTime = nums;
break; default: break; } } void Staff::writeF(ofstream& ofs) { Staff* p = this;
if (p == NULL) { cout << " no data ! Please do it again \n"; return; } ofs << this->num <<' '<<
this->sex<<' ' << this->name<<' ' <<this->type<<' '<< this->money<<' ' <<
this->workTime<<'\n'; }
<>Student class :
//Student.h #pragma once #include"People.h" class Student : protected People {
public: Student() { averGrade = 0; eduCa = " "; } void addMessage(); void
setBasic(); void showMess(); Student* delMessage(int nums); //People*
searchPeople(); Student* sortPeople(int value); void changePeople(); void
writeF(ofstream& ofs); Student* next = NULL; protected: int averGrade; string
eduCa; }; //Student.cpp #include"Student.h" void Student::addMessage() { if
(this == NULL) { this->next = new Student; Student* p = this->next;
p->setBasic(); } else { this->setBasic(); } } Student* Student::delMessage(int
nums) { Student* head=this; Student* p = this, * t = this; int i; for (i = 1; i
< nums; i++) p = p->next; if (i == 1) { delete p; return NULL; } else { t = p;
p = p->next; t->next = p->next; delete p; return head; } } void
Student::setBasic() { cout << " Enter the number of the new member , Gender (m/w), name :\n"; cin >> num >> sex >>
name; cout << " Enter GPA :\n"; cin >> this->averGrade; cout <<
" Enter Education ( undergraduate , graduate student , Doctor ):\n"; cin >> eduCa; sizes++; } void Student::showMess() {
cout << " number :" << num << '\t'; cout << " Gender :" << sex << '\t'; cout << " name :" <<
name << '\t'; cout << " education :" << eduCa << '\t'; cout << " GPA " << averGrade <<
'\n'; } Student* Student::sortPeople(int value) { Student* p = this, * t =
this, * head = this; if (value == 1) { for (int i = 0; i < sizes; i++) { p = t
= this; while (p->next != NULL) { if (p->averGrade > p->next->averGrade) { p =
p->next; t->next = p->next; p->next = t; head = p; } else { p = p->next; t =
t->next; } } } } return head; } void Student::changePeople() { Student* t =
this; cout << " Enter the member information to modify :"; int u1; cin >> u1; for (int i = 1; i < u1; i++)
t = t->next; int u2; cout << " Input operator , Choose to change a data :\n"; cout << "
1. Change of name ,2. Gender change ,3. Change number ,4. Change salary ,5. Change working hours \n"; cin >> u2; string nName; char x; int nums;
switch (u2) { case 1:// Change name cout << " Enter a new name :"; cin >> nName; t->name = nName;
break; case 2:// Gender change cout << " Enter new gender (m/w):"; cin >> x; t->sex = x; break; case
3:// Change number cout << " Enter new number :"; cin >> nums; t->num = nums; break; case 4:// Change to GPA
cout << " Enter new GPA :"; cin >> nums; t->averGrade = nums; break; default: break; }
} void Student::writeF(ofstream& ofs) { Student* p = this; if (p == NULL) {
cout << " no data ! Please do it again .\n"; return; } ofs << this->num<<' ' << this->sex<<' ' <<
this->name<<' ' << this->averGrade<<' ' << this->eduCa << '\n'; }
I wanted to use more data structure knowledge , For example, sorting by binary tree , But because I'm not familiar , After all, I just learned discrete mathematics, but I haven't realized those data structures yet ,,
And close deadLine...
We have to delete some operations , I'll find another chance to do that later .

Technology
©2019-2020 Toolsou All rights reserved,
It's unexpected Python Cherry tree (turtle The gorgeous style of Library )Unity3D of UGUI Basics -- Three modes of canvas os Simple use of module computer network --- Basic concepts of computer network ( agreement , system )html Writing about cherry trees , Writing about cherry trees Some East 14 Pay change 16 salary , Sincerity or routine ?Unity-Demo Examples ✨ realization UI- Backpack equipment drag function 06【 Interpretation according to the frame 】 Data range filtering -- awesome java Four functional interfaces ( a key , simple )