本系统能实现的功能及优点有:
1.动态创建对象(链表实现,使用new向系统申请内存)
2.输入与输出对象的信息:包括单项输入与输出,与全部输入与输出
3.定位插入及删除对象资料(链表实现)
4.动态查找与身份数据匹配的人,并输出他的信息
5.动态查找工资最高的人
6.重要数据类型使用private,实现数据的保密
7. 输出某一对象的总人数(构造时人数++,析构时–)
8.使用了文件的输入输出
9.用归并排序对链表进行排序
10.较为人性化

总代码长度1757行

测试数据文件

总结一下自己犯的错,及debug时的痛苦
1.find函数的循环是

while(temp->next&&temp->Tnum!=data)

注意的是逻辑运算符是&&不是||,其中一个不符合就停止,而且是temp->next!=NULL;,不是temp!=NULL;,否则编译器会强制停止,这么做的话特判一下

if(temp->Tnum!=data) return NULL;

即可

2.creat函数的参数要加引用&,否则无法改变尾指针的地址,然后insert函数调用creat函数的时候尾指针就仍是NULL,然后编译器又会强制停止

3.delete函数参数也要加引用,否则当删除的是第一个对象时,无法改变首指针的地址,又会强制停止

void delete1(Teacher* &head)

而且当删除为第一个对象(head==temp)时,不能在

while(temp->Tnum!=data&&temp!=NULL)   pre=temp,temp=temp->next;

后特判,而是要先判断temp是否为NULL,不为空才head=temp->next;否则先判断完后,head与temp就不相等了然后删除的就不是第一个对象了

4.同样的sort函数参数head也要加&

void Tsort(Teacher* &h)

5.findrich函数找到一个类中最有钱的人,也是

while(head->next){if(Maxn<head->SMwage)///原来在后面没注意加了一个';'导致判断没用了{Maxn=head->SMwage;temp=head;}head=head->next;}

6.注意加&的head要让temp=head,temp=temp->next,否则head的地址会改变

7.find函数返回的地址temp,if(temp) cout<<"查找成功";
而不是if(!temp) cout<<"查找成功"; 类似的逻辑符号上的错误还犯了一些

#include <iostream>
#include<bits/stdc++.h>
using namespace std;
const int TEACHER =2;
const int STUDENT =1;
const int S_MANAGER=4;
const int MANAGER=3;
class S_Manager;
class Person
{string name,gender,birtheday;string others[10];int cnt;///补充其他数据的数量
public:static int sum;///总对象数量Person():cnt(0){sum++;}virtual ~Person(){sum--;}///必须提供定义 否则找不到析构函数入口void printprompt(int case1){if(case1==1) cout<<"请按如下顺序输入";if(case1==2) cout<<"请根据数字选择输出哪一项";if(case1==3) cout<<"请根据数字选择选择替换的";cout<<"基本信息1:名字,2:性别,3:出生年月";if(case1==2) cout<<",4:全部";if(case1==2||case1==3)cout<<"\n请输入数字";cout<<'\n';}virtual void setwage( int)=0;///给工资的信息输入留一个接口void baseread()///读入基本数据{printprompt(1);///提示语cin>>name;cin>>gender;cin>>birtheday;cout<<'\n';}void baseprint()///输出基本数据{int n;printprompt(2);cin>>n;switch(n){case 1:if(!name.size())cout<<"没有此项数据\n";else cout<<name<<' ';break;case 2:if(!gender.size())cout<<"没有此项数据\n";else cout<<gender<<' ';break;case 3:if(!birtheday.size())cout<<"没有此项数据\n";else cout<<birtheday<<' ';break;case 4:if(!name.size())cout<<"没有姓名数据 ";else cout<<name<<' ';if(!gender.size())cout<<"没有性别数据\n";else cout<<gender<<' ';if(!birtheday.size())cout<<"没有生日数据\n";else cout<<birtheday<<' ';break;default:cout<<"没有此输出项\n";}cout<<'\n';cout<<'\n';}void Preplacedata()///数据替换{int n;string rdata;printprompt(3);cin>>n;switch(n){case 1:cout<<"请输入替换后的姓名\n";cin>>rdata;name=rdata; break;case 2:cout<<"请输入性别\n";cin>>rdata;gender=rdata; break;case 3:cout<<"请输入生日\n";cin>>rdata;birtheday=rdata; break;default:cout<<"没有此项数据\n";}cout<<'\n';}string getname(){return name;}
};
int Person:: sum=0;class Manager: virtual public Person
{string departmant;int Mwage;string Mnum;
public:friend class S_Manager;static int Msum;Manager *next;Manager():next(NULL){Msum++;}~Manager(){Msum--;};int getMwage(){return Mwage;}friend void Msort(Manager* &head);friend Manager* Mfind(Manager* head);///查找函数friend void delete1(Manager* &head);///删除函数void printManprompt(int case1){if(case1==1) cout<<"请按如下顺序输入";if(case1==2) cout<<"请根据数字选择输出哪一项";if(case1==3) cout<<"请根据数字选择替换哪一项";cout<<"管理员信息:1.管理员编号,2.所属部门,3.管理员工资";if(case1==2)cout<<",4.全部";if(case1==2||case1==3)cout<<"\n请输入数字";cout<<"\n";}void Msetdata()///输入基础信息{baseread();printManprompt(1);cin>>Mnum>>departmant>>Mwage;}void setwage(int wage){Mwage=wage;}void Mprint()///输出基本数据{int n;this->baseprint();printManprompt(2);cin>>n;switch(n){case 1:if(!Mnum.size())cout<<"没有此项数据\n";else cout<<Mnum<<' ';break;case 2:if(!departmant.size())cout<<"没有此项数据\n";else cout<<departmant<<' ';break;case 3:if(!Mwage)cout<<"没有此项数据\n";else cout<<Mwage<<' ';break;case 4:if(!Mnum.size())cout<<"没有管理员编号数据\n";else cout<<Mnum<<' ';if(!departmant.size())cout<<"没有所属部门数据\n";else cout<<departmant<<' ';if(!Mwage)cout<<"没有管理员工资数据\n";else cout<<Mwage<<' ';break;default:cout<<"没有此输出项\n";}cout<<'\n';cout<<'\n';}void Mreplacedata()///数据替换{Preplacedata();int n;printManprompt(3);cin>>n;string rdata;int Rdata;switch(n){case 1 :cout<<"请输入替换后的管理员编号\n";cin>>rdata;Mnum=rdata;cout<<"替换成功\n";break;case 2:cout<<"请输入替换后的所属部门\n";cin>>rdata;departmant=rdata;cout<<"替换成功\n";break;case 3:cout<<"请输入替换后的工资\n";cin>>Rdata;Mwage=Rdata;cout<<"替换成功\n";break;default:cout<<"没有此项数据\n";}printf("\n");cout<<'\n';}};
int Manager:: Msum=0;string Mfindpromote(int &case1)
{cout<<"请输入查询的方式(输入数字):1.管理员编号,2.姓名\n";int n;cin>>n;while(n!=1&&n!=2){cout<<"没有此项查找方式,请重新输入查找方式\n";cin>>n;}string data;if(n==1){cout<<"请输入管理员编号\n";cin>>data;case1=n;}else if(n==2){cout<<"请输入姓名\n";cin>>data;case1=n;}cout<<'\n';return data;
}Manager* Mfind(Manager* head)
{if(head==NULL) {cout<<"还未创建对象\n";return NULL;}cout<<"请输入查询的方式(输入数字):1.管理员编号,2.姓名\n";int n; cin>>n;while(n!=1&&n!=2){cout<<"没有此项查找方式,请重新输入查找方式\n";cin>>n;}string data;if(n==1){cout<<"请输入管理员编号\n";cin>>data;Manager* temp=head;while(temp->Mnum!=data&&temp->next!=NULL)temp=temp->next;if(temp->Mnum!=data) return NULL;return temp;}else if(n==2){cout<<"请输入姓名\n";cin>>data;Manager* temp=head;while(temp->getname()!=data&&temp->next!=NULL)temp=temp->next;if(temp->getname()!=data) return NULL;return temp;}else return NULL;
}Manager* creatManager(Manager* &back1)///head要加引用!!!!!!!!!!!!!,否则地址不会改变
{//int i=1;cout<<"请输入录入信息的管理员个数\n";int n;cin>>n;Manager *head=NULL;Manager *ob1=NULL;Manager *ob2=NULL;ob1=new Manager();head=ob1;for(int i=0;i<n;i++){cout<<"请输入第"<<i+1<<"个管理员的信息\n";ob1->Msetdata();///注意调用方式,是*(ob1).Tsetdata();或者ob1->Tsetdata();if(i+1<n){ob2=ob1;ob1=new Manager;ob2->next=ob1;}}back1=ob1;///用于插入时返回尾指针的位置//cout<<"!!"<<ob1<<endl;back1->next=NULL;ob1->next=NULL;ob2=NULL;ob1=NULL;cout<<'\n';return head;
}void Minsert(Manager* &head)///head要加引用!!!!!!!!!!!!!,否则地址不会改变
{Manager* back1=NULL;if(!head){cout<<"还未创建对象,现在开始创建\n";head=creatManager(back1);cout<<"创建完成,是否继续插入信息:1.是,2.否\n";int n; cin>>n;if(n==2) return;}cout<<"请选择信息的插入方式,1.直接插入信息,2.插入到某一管理员的信息位置后\n";int n;cin>>n;if(n==2){Manager *temp=NULL;temp=Mfind(head);//cout<<temp;if(temp){cout<<"查找成功,开始插入管理员信息\n";Manager *temphead=creatManager(back1);///创建一个新的链表//cout<<back1->next<<endl;///将新链表连接到原来的链表上back1->next=temp->next;temp->next=temphead;//cout<<temp<<' '<<head->next;//cout<<temp->next;}else {cout<<"查找失败,自动选择直接插入信息模式\n";n=1;}}if(n==1){Manager *temp=head;//cout<<head->next;while(temp->next) temp=temp->next;///条件是temp->head,不是!temp->head;//cout<<head;Manager *temphead=creatManager(back1);///创建一个新的链表///将新链表连接到原来的链表上temp->next=temphead;}cout<<'\n';
}void delete1(Manager* &head)///head要加引用!!!!!!!!!!!!!,否则地址不会改变
{if(!head) {cout<<"还未录入数据\n";return;}string data;int case1;data=Mfindpromote(case1);while(case1!=1&&case1!=2)cout<<"请重新输入查找方式\n",data=Mfindpromote(case1);Manager* temp=head,*pre=NULL;if(case1==1){while(temp->Mnum!=data&&temp!=NULL)pre=temp,temp=temp->next;if(!temp) {cout<<"没有此人数据\n";return;}else{if(head==temp) head=temp->next;///排除删除链表头的特殊情况,防止指针悬挂else pre->next=temp->next;delete temp;}}else if(case1==2){while(temp->getname()!=data&&temp!=NULL)pre=temp,temp=temp->next;if(!temp) {cout<<"没有此人数据\n";return;}else{if(head==temp) head=temp->next;///排除删除链表头的特殊情况else pre->next=temp->next;delete temp;}}cout<<'\n';
}///对链表进行归并排序
void Msort(Manager* &h)///教师工资排序
{if((h -> next == NULL) || (h -> next -> next == NULL)){return;}Manager *head, * pre, * cur, *next, * endd, * temp;head = h;endd = NULL;//从链表头开始将较大值往后沉while(head -> next != endd){for(pre = head, cur = pre -> next, next = cur -> next; next != endd; pre = pre -> next, cur = cur -> next, next = next -> next){//相邻的节点比较if(cur -> Mwage > next -> Mwage){cur -> next = next -> next;pre -> next = next;next -> next = cur;temp = next;next = cur;cur = temp;}}endd = cur;}cout<<'\n';
}class Student: virtual public Person
{string Snum,subject[20];int score[20];int N;///录入成绩的科目数目int Swage;
public:friend class S_Manager;static int Ssum;Student* next;///链表指针//static Student* back1;///尾指针~Student(){Ssum--;};Student():N(0),next(NULL){Ssum++;};friend Student* Sfind(Student* head);///查找函数friend void delete1(Student* &head);///删除函数void setwage(int wage){Swage=wage;}string getSnum(){return Snum;}void printStuprompt(int case1){if(case1==1) cout<<"请按如下顺序输入";if(case1==2) cout<<"请根据数字选择输出哪一项";if(case1==3) cout<<"请根据数字选择替换哪一项";cout<<"学生信息:1.学号、2.录入成绩的科目数目,3.具体科目,4.成绩";if(case1==2) cout<<",5.全部";if(case1==1) cout<<"\n输入时的科目和成绩的格式:科目1 成绩1 科目2 成绩2...";if(case1==2||case1==3)cout<<"\n请输入数字";cout<<"\n";}void setdata()///输入基础信息{baseread();printStuprompt(1);int cnt;cin>>Snum>>cnt;///注意i从N开始for(int i=N;i<N+cnt;i++)cin>>subject[i]>>score[i];//cout<<i<<endl;N+=cnt;cout<<'\n';}void Studentprint()///输出基本数据{int n;this->baseprint();printStuprompt(2);cin>>n;switch(n){case 1:if(!Snum.size())cout<<"没有此项数据\n";else cout<<Snum<<' ';break;case 2:if(!n)cout<<"没有此项数据\n";else cout<<n<<' ';break;case 3:if(!n)cout<<"没有此项数据\n";else for(int i=0;i<N;i++)cout<<subject[i]<<' ';break;case 4:if(!n)cout<<"没有此项数据\n";else for(int i=0;i<N;i++)cout<<subject[i]<<' '<<score[i]<<endl;break;case 5:if(!Snum.size())cout<<"没有学号数据\n";else cout<<Snum<<' ';if(!n)cout<<"没有录入成绩的科目数目数据\n";else cout<<n<<' ';if(!n)cout<<"没有科目数据\n";else {for(int i=0;i<N;i++)cout<<subject[i]<<' ';cout<<'\n';}if(!n)cout<<"没有成绩数据\n";else for(int i=0;i<N;i++)cout<<subject[i]<<' '<<score[i]<<endl;break;default:cout<<"没有此输出项\n";cout<<'\n';}}void Stureplacedata()///数据替换{Preplacedata();int n;printStuprompt(3);cin>>n;string rdata;int Rdata;int i;switch(n){case 1:cout<<"请输入替换后的学号\n";cin>>rdata;Snum=rdata;break;case 2:cout<<"请输入替换后的科目数目\n";cin>>Rdata;n=Rdata;break;case 3:cout<<"请输入替换的科目\n";cin>>rdata;for(i=0;i<N;i++){if(subject[i]==rdata){cout<<"查找成功!请输入替换后的科目\n";string rsubject;cin>>rsubject;subject[i]=rsubject;}}if(i==N)cout<<"没有此科目\n";break;case 4:cout<<"请输入替换成绩的科目\n";cin>>rdata;for(i=0;i<N;i++){if(subject[i]==rdata){cout<<"查找成功!请输入替换后的科目成绩\n";int rscore;cin>>rscore;score[i]=rscore;}}if(i==N)cout<<"没有此科目\n";break;default:cout<<"没有此项数据\n";}printf("\n");cout<<'\n';}};int Student:: Ssum=0;string Sfindpromote(int &case1)
{cout<<"请输入查询的方式(输入数字):1.学号,2.姓名\n";int n;cin>>n;string data;while(n!=1&&n!=2){cout<<"没有此项查找方式,请重新输入查找方式\n";cin>>n;}if(n==1){cout<<"请输入学号\n";cin>>data;case1=n;}else if(n==2){cout<<"请输入姓名\n";cin>>data;case1=n;}return data;cout<<'\n';
}
Student* Sfind(Student* head)
{if(head==NULL) {cout<<"还未创建对象\n";return NULL;}cout<<"请输入查询的方式(输入数字):1.学号,2.姓名\n";int n;cin>>n;string data;while(n!=1&&n!=2){cout<<"没有此项查找方式,请重新输入查找方式\n";cin>>n;}if(n==1){cout<<"请输入学号\n";cin>>data;Student* temp=head;while(temp->Snum!=data&&temp->next!=NULL)temp=temp->next;if(temp->Snum!=data) return NULL;return temp;}else if(n==2){cout<<"请输入姓名\n";cin>>data;Student* temp=head;while(temp->getname()!=data&&temp->next!=NULL)temp=temp->next;if(temp->getname()!=data) return NULL;return temp;}else return NULL;
}Student* creatStudent(Student* &back1)
{//int i=1;cout<<"请输入录入信息的学生个数\n";int n;cin>>n;Student *head=NULL;Student *ob1=NULL;Student *ob2=NULL;ob1=new Student();head=ob1;for(int i=0;i<n;i++){cout<<"请输入第"<<i+1<<"个学生的信息\n";ob1->setdata();///注意调用方式,是*(ob1).setdata();或者ob1->setdata();if(i+1<n){ob2=ob1;ob1=new Student;ob2->next=ob1;}}back1=ob1;///用于插入时返回尾指针的位置back1->next=NULL;ob1->next=NULL;ob2=NULL;ob1=NULL;cout<<'\n';return head;
}void Sinsert(Student* &head)
{Student* back1=NULL;if(!head){cout<<"还未创建对象,现在开始创建\n";head=creatStudent(back1);cout<<"创建完成,是否继续插入信息:1.是,2.否\n";int n; cin>>n;if(n==2) return;}cout<<"请选择信息的插入方式,1.直接插入信息,2.插入到某一学生的信息位置后\n";int n;cin>>n;if(n==2){Student *temp=NULL;temp=Sfind(head);//cout<<temp;if(temp){cout<<"查找成功,开始插入学生信息\n";Student *temphead=creatStudent(back1);///创建一个新的链表//cout<<back1->next<<endl;///将新链表连接到原来的链表上back1->next=temp->next;temp->next=temphead;//cout<<temp<<' '<<head->next;//cout<<temp->next;}else {cout<<"查找失败,自动选择直接插入信息模式\n";n=1;}}if(n==1){Student *temp=head;//cout<<head->next;while(temp->next) temp=temp->next;///条件是temp->head,不是!temp->head;//cout<<head;Student *temphead=creatStudent(back1);///创建一个新的链表///将新链表连接到原来的链表上temp->next=temphead;}cout<<'\n';
}void delete1(Student* &head)///n为创建的对象的总数量
{if(!head) {cout<<"还未录入数据\n";return;}string data; int case1;data=Sfindpromote(case1);while(case1!=1&&case1!=2)cout<<"请重新输入查找方式\n",data=Sfindpromote(case1);//cout<<data<<"1111111111111111111111111111111"<<endl;Student* temp=head,*pre=NULL;//cout<<temp<<endl;//cout<<temp->next<<endl;if(case1==1){while(temp->Snum!=data&&temp!=NULL)pre=temp,temp=temp->next;if(!temp) {cout<<"没有此人数据\n";return;}else{//cout<<head<<endl;//cout<<temp->next<<endl;if(head==temp) head=head->next;///排除删除链表头的特殊情况,防止指针悬挂,而且注意了if的位置只能在这里//cout<<head;else pre->next=temp->next;delete temp;}}else if(case1==2){//cout<<temp->getname();//cout<<"head "<<head<<endl;while(temp->getname()!=data&&temp!=NULL)pre=temp,temp=temp->next;//cout<<"1234567";//cout<<"head "<<head<<endl;if(!temp) {cout<<"没有此人数据\n";return;}else{//cout<<head<<endl;if(head->getname()==temp->getname()) head=head->next;///排除删除链表头的特殊情况//cout<<head;else pre->next=temp->next;delete temp;}}cout<<'\n';//return head;
}class S_Manager:virtual public Student,Manager
{public:int SMwage;string SMnum;S_Manager *next;static int SMsum;S_Manager():next(NULL){SMsum++;}~S_Manager(){SMsum--;};void setwage(int wage){SMwage=wage;}void SMsetdata()///输入基础信息{setdata();printManprompt(1);cin>>Mnum>>departmant>>Mwage;SMwage=Mwage;SMnum=Mnum;}void S_Managerprint()///输出{Studentprint();printManprompt(2);int n; cin>>n;switch(n){case 1:if(!Mnum.size())cout<<"没有此项数据\n";else cout<<Mnum<<' ';break;case 2:if(!departmant.size())cout<<"没有此项数据\n";else cout<<departmant<<' ';break;case 3:if(!Mwage)cout<<"没有此项数据\n";else cout<<Mwage<<' ';break;case 4:if(!Mnum.size())cout<<"没有管理员编号数据\n";else cout<<Mnum<<' ';if(!departmant.size())cout<<"没有所属部门数据\n";else cout<<departmant<<' ';if(!Mwage)cout<<"没有管理员工资数据\n";else cout<<Mwage<<' ';break;default:cout<<"没有此输出项\n";}cout<<'\n';cout<<'\n';}void SMreplace(){Stureplacedata();int n;printManprompt(3);cin>>n;string rdata;int Rdata;switch(n){case 1 :cout<<"请输入替换后的管理员编号\n";cin>>rdata;Mnum=rdata;cout<<"替换成功\n";break;case 2:cout<<"请输入替换后的所属部门\n";cin>>rdata;departmant=rdata;cout<<"替换成功\n";break;case 3:cout<<"请输入替换后的工资\n";cin>>Rdata;Mwage=Rdata;cout<<"替换成功\n";break;default:cout<<"没有此项数据\n";}printf("\n");cout<<'\n';}};
int S_Manager:: SMsum=0;string SMfindpromote(int &case1)
{string data;cout<<"请选择按什么身份查询(输入数字):1.学生,2.管理员\n";int n;while(n!=1&&n!=2) cout<<"没有该身份,请重新输入\n",cin>>n;if(n==1) data=Sfindpromote(case1);else data=Mfindpromote(case1);cout<<'\n';return data;
}S_Manager* SMfind(S_Manager* head)
{if(head==NULL) {cout<<"还未创建对象\n";return NULL;}cout<<"请输入查询的方式(输入数字):1.学号,2.姓名,3.管理员编号\n";int n;cin>>n;while(n!=1&&n!=2&&n!=3){cout<<"没有此项查找方式,请重新输入查找方式\n";cin>>n;}string data;if(n==1){cout<<"请输入学号\n";cin>>data;S_Manager* temp=head;while(temp->getSnum()!=data&&temp->next!=NULL)temp=temp->next;if(temp->getSnum()!=data) return NULL;return temp;}else if(n==2){cout<<"请输入姓名\n";cin>>data;S_Manager* temp=head;while(temp->getname()!=data&&temp->next!=NULL)temp=temp->next;if(temp->getname()!=data) return NULL;return temp;}else{cout<<"请输入管理员编号\n";cin>>data;S_Manager* temp=head;while(temp->SMnum!=data&&temp->next!=NULL)temp=temp->next;if(temp->SMnum!=data) return NULL;return temp;}
}/*Teacher *Tfindend(Teacher* head)
{int case1;string data=Tfindpromote(case1);Teacher* temp=Tfind(case1,data,head);return temp;
}*/S_Manager* creatS_Manager(S_Manager* &back1)///head要加引用!!!!!!!!!!!!!,否则地址不会改变
{//int i=1;cout<<"请输入录入信息的学生管理员个数\n";int n;cin>>n;S_Manager *head=NULL;S_Manager *ob1=NULL;S_Manager *ob2=NULL;ob1=new S_Manager();head=ob1;for(int i=0;i<n;i++){cout<<"请输入第"<<i+1<<"个学生管理员的信息\n";ob1->SMsetdata();///注意调用方式,是*(ob1).Tsetdata();或者ob1->Tsetdata();if(i+1<n){ob2=ob1;ob1=new S_Manager;ob2->next=ob1;}}back1=ob1;///用于插入时返回尾指针的位置//cout<<"!!"<<ob1<<endl;back1->next=NULL;ob1->next=NULL;ob2=NULL;ob1=NULL;cout<<'\n';return head;
}void SMinsert(S_Manager* &head)///head要加引用!!!!!!!!!!!!!,否则地址不会改变
{S_Manager* back1=NULL;if(!head){cout<<"还未创建对象,现在开始创建\n";head=creatS_Manager(back1);cout<<"创建完成,是否继续插入信息:1.是,2.否\n";int n; cin>>n;if(n==2) return;}cout<<"请选择信息的插入方式,1.直接插入信息,2.插入到某一学生管理员的信息位置后\n";int n;cin>>n;if(n==2){S_Manager *temp=NULL;temp=SMfind(head);//cout<<temp;if(temp){cout<<"查找成功,开始插入学生管理员信息\n";S_Manager *temphead=creatS_Manager(back1);///创建一个新的链表//cout<<back1->next<<endl;///将新链表连接到原来的链表上back1->next=temp->next;temp->next=temphead;//cout<<temp<<' '<<head->next;//cout<<temp->next;}else {cout<<"查找失败,自动选择直接插入信息模式\n";n=1;}}if(n==1){S_Manager *temp=head;//cout<<head->next;while(temp->next) temp=temp->next;///条件是temp->head,不是!temp->head;//cout<<head;S_Manager *temphead=creatS_Manager(back1);///创建一个新的链表///将新链表连接到原来的链表上temp->next=temphead;}cout<<'\n';
}void delete1(S_Manager* &head)///head要加引用!!!!!!!!!!!!!,否则地址不会改变
{if(!head) {cout<<"还未录入数据\n";return;}string data;int case1;data=SMfindpromote(case1);while(case1!=1&&case1!=2&&case1!=3)cout<<"请重新输入查找方式\n",data=SMfindpromote(case1);S_Manager* temp=head,*pre=NULL;if(case1==1){while(temp->getSnum()!=data&&temp!=NULL)pre=temp,temp=temp->next;if(!temp) {cout<<"没有此人数据\n";return;}else{if(head==temp) head=temp->next;///排除删除链表头的特殊情况,防止指针悬挂else pre->next=temp->next;delete temp;}}else if(case1==2){while(temp->getname()!=data&&temp!=NULL)pre=temp,temp=temp->next;if(!temp) {cout<<"没有此人数据\n";return;}else{if(head==temp) head=temp->next;///排除删除链表头的特殊情况else pre->next=temp->next;delete temp;}}else{while(temp->SMnum!=data&&temp!=NULL)pre=temp,temp=temp->next;if(!temp) {cout<<"没有此人数据\n";return;}else{if(head==temp) head=temp->next;///排除删除链表头的特殊情况else pre->next=temp->next;delete temp;}}cout<<'\n';
}///对链表进行归并排序
void SMsort(S_Manager* &h)///工资排序
{if((h -> next == NULL) || (h -> next -> next == NULL)){return;}S_Manager *head, * pre, * cur, *next, * endd, * temp;head = h;endd = NULL;//从链表头开始将较大值往后沉while(head -> next != endd){for(pre = head, cur = pre -> next, next = cur -> next; next != endd; pre = pre -> next, cur = cur -> next, next = next -> next){//相邻的节点比较if(cur -> SMwage > next -> SMwage ){cur -> next = next -> next;pre -> next = next;next -> next = cur;temp = next;next = cur;cur = temp;}}endd = cur;}cout<<'\n';
}class Teacher:public Person
{string Tnum,subject,institute;int Twage;static int Tsum;
public:Teacher *next;Teacher():next(NULL){Tsum++;};~Teacher(){Tsum--;};///注意调用析构函数的时候人数要--void setwage(int wage){Twage=wage;}int getTwage(){return Twage;}int static  getTsum(){return Tsum;}friend void Tsort(Teacher* &head);friend Teacher* Tfind(Teacher* head);///查找函数friend void delete1(Teacher* &head);///删除函数void printTeaprompt(int case1){if(case1==1) cout<<"请按如下顺序输入";if(case1==2) cout<<"请根据数字选择输出哪一项";if(case1==3) cout<<"请根据数字选择替换哪一项";cout<<"教师信息:1.教工编号,2.所属院系,3.教学科目,4.教师工资";if(case1==2)cout<<",5.全部";if(case1==2||case1==3)cout<<"\n请输入数字";cout<<"\n";cout<<'\n';}void Tsetdata()///输入基础信息{baseread();printTeaprompt(1);cin>>Tnum>>institute>>subject>>Twage;}void Tprint()///输出基本数据{int n;this->baseprint();printTeaprompt(2);cin>>n;switch(n){case 1:if(!Tnum.size())cout<<"没有此项数据\n";else cout<<Tnum<<' ';break;case 2:if(!institute.size())cout<<"没有此项数据\n";else cout<<institute<<' ';break;case 3:if(!subject.size())cout<<"没有此项数据\n";else cout<<subject<<' ';break;case 4:if(!Twage)cout<<"没有此项数据\n";else for(int i=0;i<n;i++)cout<<Twage<<' ';break;case 5:if(!Tnum.size())cout<<"没有教工编号数据\n";else cout<<Tnum<<' ';if(!institute.size())cout<<"没有所属院系数据\n";else cout<<institute<<' ';if(!subject.size())cout<<"没有所教科目数据\n";else cout<<subject<<' ';if(!Twage)cout<<"没有工资数据\n";else cout<<Twage<<' ';break;default:cout<<"没有此输出项\n";}cout<<'\n';cout<<'\n';}void Treplacedata()///数据替换{Preplacedata();int n;printTeaprompt(3);cin>>n;string rdata;int Rdata;switch(n){case 1 :cout<<"请输入替换后的教工编号\n";cin>>rdata;Tnum=rdata;cout<<"替换成功\n";break;case 2:cout<<"请输入替换后的所属院系\n";cin>>rdata;institute=rdata;cout<<"替换成功\n";break;case 3:cout<<"请输入替换后的教学科目\n";cin>>rdata;subject=rdata;cout<<"替换成功\n";break;case 4:cout<<"请输入替换后的工资\n";cin>>Rdata;Twage=Rdata;cout<<"替换成功\n";break;default:cout<<"没有此项数据\n";}printf("\n");cout<<'\n';}};
int Teacher:: Tsum=0;string Tfindpromote(int &case1)
{cout<<"请输入查询的方式(输入数字):1.教工编号,2.姓名\n";int n;cin>>n;while(n!=1&&n!=2){cout<<"没有此项查找方式,请重新输入查找方式\n";cin>>n;}string data;if(n==1){cout<<"请输入教工编号\n";cin>>data;case1=n;}else if(n==2){cout<<"请输入姓名\n";cin>>data;case1=n;}cout<<'\n';return data;
}Teacher* Tfind(Teacher* head)
{if(head==NULL) {cout<<"还未创建该对象";return NULL;}cout<<"请输入查询的方式(输入数字):1.教工编号,2.姓名\n";int n;cin>>n;while(n!=1&&n!=2){cout<<"没有此项查找方式,请重新输入查找方式\n";cin>>n;}string data;if(n==1){cout<<"请输入教工编号\n";cin>>data;Teacher* temp=head;while(temp->Tnum!=data&&temp->next!=NULL)temp=temp->next;///if(temp->Tnum!=data) return NULL;return temp;}else if(n==2){cout<<"请输入姓名\n";cin>>data;Teacher* temp=head;while(temp->getname()!=data&&temp->next!=NULL)temp=temp->next;if(temp->getname()!=data) return NULL;return temp;}else return NULL;
}/*Teacher *Tfindend(Teacher* head)
{int case1;string data=Tfindpromote(case1);Teacher* temp=Tfind(case1,data,head);return temp;
}*/Teacher* creatTeacher(Teacher* &back1)///head要加引用!!!!!!!!!!!!!,否则地址不会改变
{//int i=1;cout<<"请输入录入信息的老师个数\n";int n;cin>>n;Teacher *head=NULL;Teacher *ob1=NULL;Teacher *ob2=NULL;ob1=new Teacher();head=ob1;for(int i=0;i<n;i++){cout<<"请输入第"<<i+1<<"个老师的信息\n";ob1->Tsetdata();///注意调用方式,是*(ob1).Tsetdata();或者ob1->Tsetdata();if(i+1<n){ob2=ob1;ob1=new Teacher;ob2->next=ob1;}}back1=ob1;///用于插入时返回尾指针的位置//cout<<"!!"<<ob1<<endl;back1->next=NULL;ob1->next=NULL;ob2=NULL;ob1=NULL;return head;
}void Tinsert(Teacher* &head)///head要加引用!!!!!!!!!!!!!,否则地址不会改变
{Teacher* back1=NULL;if(!head){cout<<"还未创建对象,现在开始创建\n";head=creatTeacher(back1);cout<<"创建完成,是否继续插入信息:1.是,2.否\n";int n; cin>>n;if(n==2) return;}cout<<"请选择信息的插入方式,1.直接插入信息,2.插入到某一老师的信息位置后\n";int n;cin>>n;if(n==2){Teacher *temp=NULL;temp=Tfind(head);//cout<<temp;if(temp){cout<<"查找成功,开始插入老师信息\n";Teacher *temphead=creatTeacher(back1);///创建一个新的链表//cout<<back1->next<<endl;///将新链表连接到原来的链表上back1->next=temp->next;temp->next=temphead;//cout<<temp<<' '<<head->next;//cout<<temp->next;}else {cout<<"查找失败,自动选择直接插入信息模式\n";n=1;}}if(n==1){Teacher *temp=head;//cout<<head->next;while(temp->next) temp=temp->next;///条件是temp->head,不是!temp->head;//cout<<head;Teacher *temphead=creatTeacher(back1);///创建一个新的链表///将新链表连接到原来的链表上temp->next=temphead;}cout<<'\n';
}void delete1(Teacher* &head)///head要加引用!!!!!!!!!!!!!,否则地址不会改变
{if(!head) {cout<<"还未录入数据\n";return;}string data;int case1;data=Tfindpromote(case1);while(case1!=1&&case1!=2)cout<<"请重新输入查找方式\n",data=Tfindpromote(case1);Teacher* temp=head,*pre=NULL;if(case1==1){while(temp->Tnum!=data&&temp!=NULL)pre=temp,temp=temp->next;if(!temp) {cout<<"没有此人数据\n";return;}else{if(head==temp) head=temp->next;///排除删除链表头的特殊情况,防止指针悬挂else pre->next=temp->next;delete temp;}}else if(case1==2){while(temp->getname()!=data&&temp!=NULL)pre=temp,temp=temp->next;if(!temp) {cout<<"没有此人数据\n";return;}else{if(head==temp) head=temp->next;///排除删除链表头的特殊情况else pre->next=temp->next;delete temp;}}
}///对链表进行归并排序
void Tsort(Teacher* &h)///教师工资排序
{if((h -> next == NULL) || (h -> next -> next == NULL)){return;}Teacher *head, * pre, * cur, *next, * endd, * temp;head = h;endd = NULL;//从链表头开始将较大值往后沉while(head -> next != endd){for(pre = head, cur = pre -> next, next = cur -> next; next != endd; pre = pre -> next, cur = cur -> next, next = next -> next){//相邻的节点比较if(cur -> Twage > next -> Twage){cur -> next = next -> next;pre -> next = next;next -> next = cur;temp = next;next = cur;cur = temp;}}endd = cur;}cout<<'\n';
}
int objpromote()
{cout<<"请选择操作的对象:1.学生,2.老师,3.管理员,4.学生兼管理员\n";int n;cin>>n;while(n!=1&&n!=2&&n!=3&&n!=4) cout<<"无此对象,请重新输入\n",cin>>n;return n;
}int operatepromote(int type)
{cout<<"请选择输入所进行的操作:1.输入信息,2.插入信息,3.替换信息,4.删除对象,5.查找对象并输出信息";if(type!=STUDENT) cout<<",6.根据工资排序,7.查找该对象中工资最高的人";cout<<",10.输出该类对象的人数,0.退出该类对象的操作\n";int n;cin>>n;if(type!=STUDENT){while(n!=1&&n!=2&&n!=3&&n!=4&&n!=5&&n!=6&&n!=7&&n!=0&&n!=10) cout<<"无此操作,请重新输入\n",cin>>n;}else while(n!=1&&n!=2&&n!=3&&n!=4&&n!=5&&n!=0&&n!=10) cout<<"无此操作,请重新输入\n",cin>>n;return n;
}Teacher* findrich(Teacher* head)
{if(!head) {cout<<"还未有老师信息,请先输入信息\n";return NULL;}int Maxn=0;Teacher *temp=head;//cout<<temp->getTwage()<<endl;while(head->next){//cout<<maxn<<endl;if(Maxn < head->getTwage()){Maxn=head->getTwage();temp=head;//cout<<Maxn<<endl;}head=head->next;}if(temp->getTwage()<head->getTwage()) return head;return temp;
}Manager* findrich(Manager* head)
{if(!head) {cout<<"还未有管理员信息,请先输入信息\n";return NULL;}int Maxn=0;Manager *temp=NULL;while(head->next){if(Maxn<head->getMwage())///if后面的' ; '把我害惨了,debug好久{Maxn=head->getMwage();temp=head;}head=head->next;}if(temp->getMwage()<head->getMwage()) return head;return temp;
}S_Manager* findrich(S_Manager* head)
{if(!head) {cout<<"还未有学生管理员信息,请先输入信息\n";return NULL;}int Maxn=0;S_Manager *temp=NULL;while(head->next){if(Maxn<head->SMwage){Maxn=head->SMwage;temp=head;}head=head->next;}if(temp->SMwage<head->SMwage) return head;return temp;
}int findmostrich(Teacher* Thead,Manager* Mhead,S_Manager* SMhead)
{S_Manager* SMtemp=findrich(SMhead);Manager* Mtemp=findrich(Mhead);Teacher* Ttemp=findrich(Thead);if(!SMtemp&&!Ttemp&&!Mtemp) {"还未有工资信息,请先输入信息\n";return 0;}int SMmax=0,Mmax=0,Tmax=0;if(SMtemp) SMmax=SMtemp->SMwage;if(Mtemp) Mmax=Mtemp->getMwage();if(Ttemp) Tmax=Ttemp->getTwage();return max(SMmax,max(Mmax,Tmax));
}int main()
{freopen("in.docx","r",stdin);freopen("out.txt","w",stdout);Teacher *Thead=NULL,*Tback=NULL,*Ttemp=NULL;Student *Shead=NULL,*Sback=NULL,*Stemp=NULL;Manager *Mhead=NULL,*Mback=NULL,*Mtemp=NULL;S_Manager *SMhead=NULL,*SMback=NULL,*SMtemp=NULL;cout<<"欢迎来到学校信息管理系统\n";cout<<"请根据提示选择要进行的操作:\n";while(1)///连续操作{cout<<"请选择是否查找工资最高的人,1.是,2.否\n";int choise;cin>>choise;if(choise==1){S_Manager* SMtemp=findrich(SMhead);Manager* Mtemp=findrich(Mhead);Teacher* Ttemp=findrich(Thead);int maxn=findmostrich(Thead,Mhead,SMhead);if(maxn==0) {cout<<"还未有工资信息,请先输入信息\n";}else if(Mtemp&&Mtemp->getMwage()==maxn){cout<<"查找成功,此人为管理员,是否输出此人信息:1.是,2.否\n";int a;cin>>a;if(a==1) Mtemp->Mprint();}else if(SMtemp&&SMtemp->SMwage==maxn){cout<<"查找成功,此人为学生管理员,是否输出此人信息:1.是,2.否\n";int a;cin>>a;if(a==1) SMtemp->S_Managerprint();}else if(Ttemp&&Ttemp->getTwage()==maxn){cout<<"查找成功,此人为老师,是否输出此人信息:1.是,2.否\n";int a;cin>>a;if(a==1) Ttemp->Tprint();}else if(!SMtemp&&!Ttemp&&!Mtemp) {"还未有信息,请先输入信息\n";}}else{int n;n=objpromote();if(n==1){int m;m=operatepromote(STUDENT);switch(m){case 1:Shead=creatStudent(Sback);break;case 2:Sinsert(Shead);break;case 3:if(!Shead){cout<<"还未创建对象,请先创建对象\n";break;}cout<<"请根据提示输入被替换信息者的信息\n";Stemp=Sfind(Shead);if(!Stemp) {cout<<"查无此人\n";break;}else Stemp->Stureplacedata();break;case 4:cout<<"请根据提示输入被删除信息者的信息\n";//cout<<Shead<<endl;delete1(Shead);break;case 5:Stemp=Sfind(Shead);if(Stemp){cout<<"查找成功,是否输出此人信息:1.是,2.否\n";int n;cin>>n;if(n==1)Stemp->Studentprint();}elsecout<<"查无此人\n";break;case 10:cout<<Student::Ssum<<"人\n";case 0:break;}}if(n==2){int m;m=operatepromote(TEACHER);switch(m){case 1:Thead=creatTeacher(Tback);break;case 2:Tinsert(Thead);break;case 3:if(!Thead){cout<<"还未创建对象,请先创建对象\n";break;}cout<<"请根据提示输入被替换信息者的信息\n";Ttemp=Tfind(Thead);if(!Ttemp) {cout<<"查无此人\n";break;}else Ttemp->Treplacedata();break;case 4:cout<<"请根据提示输入被删除信息者的信息\n";delete1(Thead);break;case 5:Ttemp=Tfind(Thead);////cout<<Ttemp<<endl;if(Ttemp){cout<<"查找成功,是否输出此人信息:1.是,2.否\n";int n;cin>>n;if(n==1)Ttemp->Tprint();//Ttemp->next->Tprint();}elsecout<<"查无此人\n";break;case 6:Tsort(Thead);break;case 7:Ttemp=findrich(Thead);if(Ttemp){cout<<"查找成功,是否输出此人信息:1.是,2.否\n";int n;cin>>n;if(n==1)Ttemp->Tprint();}break;case 10:cout<<Teacher::getTsum();case 0:break;}}if(n==3){int m;m=operatepromote(MANAGER);switch(m){case 1:Mhead=creatManager(Mback);break;case 2:Minsert(Mhead);break;case 3:if(!Mhead){cout<<"还未创建对象,请先创建对象\n";break;}cout<<"请根据提示输入被替换信息者的信息\n";Mtemp=Mfind(Mhead);if(!Mtemp) {cout<<"查无此人\n";break;}else Mtemp->Mreplacedata();break;case 4:cout<<"请根据提示输入被删除信息者的信息\n";delete1(Mhead);break;case 5:Mtemp=Mfind(Mhead);if(Mtemp){cout<<"查找成功,是否输出此人信息:1.是,2.否\n";int n;cin>>n;if(n==1)Mtemp->Mprint();}elsecout<<"查无此人\n";break;case 6:Msort(Mhead);break;case 7:Mtemp=findrich(Mhead);if(Mtemp){cout<<"查找成功,是否输出此人信息:1.是,2.否\n";int n;cin>>n;if(n==1)Mtemp->Mprint();}break;case 10:cout<<Manager::Msum<<"人\n";case 0:break;}}if(n==4){int m;m=operatepromote(S_MANAGER);switch(m){case 1:SMhead=creatS_Manager(SMback);break;case 2:SMinsert(SMhead);break;case 3:if(!SMhead){cout<<"还未创建对象,请先创建对象\n";break;}cout<<"请根据提示输入被替换信息者的信息\n";SMtemp=SMfind(SMhead);SMtemp->SMreplace();break;case 4:cout<<"请根据提示输入被删除信息者的信息\n";delete1(SMhead);break;case 5:SMtemp=SMfind(SMhead);if(SMtemp){cout<<"查找成功,是否输出此人信息:1.是,2.否\n";int n;cin>>n;if(n==1)SMtemp->S_Managerprint();}elsecout<<"查无此人\n";break;case 6:SMsort(SMhead);break;case 7:SMtemp=findrich(SMhead);if(SMtemp){cout<<"查找成功,是否输出此人信息:1.是,2.否\n";int n;cin>>n;if(n==1)SMtemp->S_Managerprint();}break;case 10:cout<<S_Manager::SMsum<<"人\n"<<endl;case 0:break;}}}int conti;cout<<"是否继续操作,1:是,2:否\n";cin>>conti;cout<<"\n";cout<<"\n";cout<<"\n";cout<<"\n";if(conti==2) {cout<<"谢谢使用本系统\n";return 0;}}}

C++学校信息管理系统相关推荐

  1. 学校信息管理系统数据库模型设计

    学校信息管理系统数据库模型设计 一.PD的使用请参考<PowerDesigner的使用> 二.学校表(School) 字段名 数据类型 说明 schoolID int 主键 schoolN ...

  2. [附源码]java毕业设计广州中小学学校信息管理系统

    项目运行 环境配置: Jdk1.8 + Tomcat7.0 + Mysql + HBuilderX(Webstorm也行)+ Eclispe(IntelliJ IDEA,Eclispe,MyEclis ...

  3. mysql学校信息管理系统_Mysql 学校信息管理系统

    1.创建数据库语句: #创建数据库 CREATE DATABASE `schoolDB`; USE `schoolDB`; #创建学生表 CREATE TABLE `student`( `sid` I ...

  4. 赶紧进来看看--用C语言实现学生信息管理系统(1.0静态版)

    本文介绍了用C语言实现学生信息管理系统设计,主要包括对学生信息增删查改.分类统计.排序等功能,文章最后有全部源码展示- C语言实现学生信息管理系统--1.0静态版 一.学生信息管理系统介绍 二.实现学 ...

  5. 全国中小学生通用计算机,全国中小学生学籍信息管理系统官网

    学生信息管理系统是针对学校人事处的大量业务处理工作而开发的管理软件,主要用于学校学生信息管理,总体任务是实现学生信息关系的系统化.科学化.规范化和自动化,其主要任务是用计算机对学生各种信息进行日常管理 ...

  6. springboot学校学校运动会信息管理系统毕业设计-附源码

    摘 要 科技进步的飞速发展引起人们日常生活的巨大变化,电子信息技术的飞速发展使得电子信息技术的各个领域的应用水平得到普及和应用.信息时代的到来已成为不可阻挡的时尚潮流,人类发展的历史正进入一个新时代. ...

  7. C#windows学校人力资源信息管理系统

    中文摘要 为了提高教职工信息的管理效率,本课题使用C#语言和SQL Server数据库系统开发了一个WinForm类型的学校人力资源管理系统对教职工信息进行高效管理,以提升管理质量.本系统包含管理员登 ...

  8. 学校毕业生就业网信息管理系统

    1 简介 今天向大家介绍一个帮助往届学生完成的毕业设计项目,学校毕业生就业网信息管理系统. 计算机毕业生设计,课程设计需要帮助的可以找我 代码 https://pan.baidu.com/s/1Cdx ...

  9. xxx学校/学院/大学信息管理系统

    注意:本程序完全用java语言实现,下面的每个代码段,都需要单独创建一个类,其中老师部分和学生部分大致相同,还有非常大的优化空间,如果觉得存储数据的空间太小,可以自行更改,或者将数组改为集合来进行存储 ...

最新文章

  1. [征求意见]关于增加Java技术区
  2. 分子生物学-肽和多肽
  3. 生产环境JVM内存大小配置
  4. 【跃迁之路】【599天】程序员高效学习方法论探索系列(实验阶段356-2018.09.27)...
  5. 腾讯阿里美团相继搞事,渣本程序员的出路在哪?
  6. php pm.status path,phpfpm开启pm.status_path配置,查看fpm状态参数
  7. 关于SubSonic3.0生成的表名自动加复数(s)的“用户代码未处理SqlException,对象名'xxxs'无效”异常处理...
  8. C语言最后一次作业--总结报告
  9. Golang教程:结构体
  10. SDN介绍(什么是SDN)
  11. 你有旧iPhone吗?快来瓜分苹果1800万赔偿款!
  12. 电子书Epub文件剖析
  13. C# 后台GC 的前因后果
  14. 百度站长俱乐部SEO提问收集-3
  15. Python爬虫——来自新人的叹息
  16. 香港的教育(2)——学前教育
  17. Cesium淹没分析(干货)
  18. 自主学习(active learning)
  19. 教大家如何在官网下载不同版本的postgresql包含之前历史版本--适合linux系统
  20. 计算机系统演练实施方案,农发行沂南县支行开展计算机系统应急演练

热门文章

  1. 防盗报警应用范围及未来市场发展分析
  2. [I T]越便宜越好? 小米、AK47与盛大你该选谁2
  3. 学习Java,达到什么程度,才可以出去找实习工作?
  4. Ulead GIF Animator制作滚动的文字条幅,循环滚动
  5. 如何方便快捷地从杂乱地址中提取省市区?
  6. MyBatis 中的动态 SQL 特性
  7. python二手交易平台代码_使用Python探索二手车市场(含代码)
  8. 手机相机识别实现ar测距(AR尺子)
  9. comp9021 第三课
  10. 全国各省及城市的市场主体、企业数量排名,粤苏鲁浙分列前四