📄 search.cpp
字号:
/************************************
查找
*************************************/
#include "Function.h"
Unit * InfoManager::CopyMale(Unit * head, int & count)
{
count=0;
if (!head)
{
cout<<"无查询结果"<<endl;
return NULL;
}
Unit *p=head;
Unit *i=NULL;
while (p)
{
if (p->Sex==0)
{
++count;
Unit *q;
q=new Unit (p->Name, p->PWD, p->Sex, p->Old, p->Class, p->ID, p->Math, p->Chinese, p->English, p->Authority);
q->next=NULL;
if (i) //追加记录
{
Unit *s;
s=i;
while (s->next) //s移到表尾
{
s=s->next;
}
s->next=q; //将新节点插入
}
else //空表情况
{
//直接插入
i=q;
}
}
p=p->next;
}
return i;
}
Unit * InfoManager::CopyFemale(Unit * head, int & count)
{
count=0;
if (!head)
{
cout<<"无查询结果"<<endl;
return NULL;
}
Unit *p=head;
Unit *i=NULL;
while (p)
{
if (p->Sex==1)
{
++count;
Unit *q;
q=new Unit (p->Name, p->PWD, p->Sex, p->Old, p->Class, p->ID, p->Math, p->Chinese, p->English, p->Authority);
q->next=NULL;
if (i) //追加记录
{
Unit *s;
s=i;
while (s->next) //s移到表尾
{
s=s->next;
}
s->next=q; //将新节点插入
}
else //空表情况
{
//直接插入
i=q;
}
}
p=p->next;
}
return i;
}
void InfoManager::SearchByID()
{
Unit *p1=NULL;
Unit *p2=NULL;
long ID;
char choice;
do
{
cout<<"\n\n\t请输入要查找的ID: ";
p1=head_stu;
p2=head_tea;
cin>>ID;
cout<<endl;
while (p1)
{
if (p1->ID==ID) break;
else p1=p1->next;
}
while (p2)
{
if (p2->ID==ID) break;
else p2=p2->next;
}
if (!p1&&!p2)
{
cout<<"\t不存在此用户!是否重新查找?[Y/N]";
do
{
cin>>choice;
if (toupper(choice)=='Y') break;
else if (toupper(choice)=='N') return;
else cout<<"\t输入错误!是否重新查找?[Y/N]"<<endl;
} while (1);
}
else
{
cout<<"所查询的用户信息为:"<<endl;
if (p1->ID=ID) InfoManager::Show_Sgl_Stu(p1);
else InfoManager::Show_Sgl_Tea (p2);
break;
}
} while (1);
}
Unit * InfoManager::SearchByOld(Unit * p, int & count)
{
if (!p)
{
cout<<"无查询结果"<<endl;
return NULL;
}
int low, high;
count=0;
Unit *temp=NULL;
count = 0;
cout<<"按年龄查询\n"<<endl;
cout<<"\n\n\t请输入要查寻年龄的范围: "<<endl;
cout<<"下限:";
cin>>low;
cout<<"上限:";
cin>>high;
cout<<endl;
while (p)
{
if (p->Old>=low&&p->Old<=high)
{
++count;
Unit *q;
q=new Unit (p->Name, p->PWD, p->Sex, p->Old, p->Class, p->ID, p->Math, p->Chinese, p->English, p->Authority);
q->next=NULL;
if (temp) //追加记录
{
Unit *s;
s=temp;
while (s->next) //s移到表尾
{
s=s->next;
}
s->next=q; //将新节点插入
}
else //空表情况
{
//直接插入
temp=q;
}
}
p=p->next;
}
return temp;
}
Unit * InfoManager::SearchByClass(Unit * p, int & count)
{
if (!p)
{
cout<<"无查询结果"<<endl;
return NULL;
}
int low, high;
Unit *temp=NULL;
count = 0;
cout<<"按班级查询\n"<<endl;
cout<<"\n\n\t请输入要查寻班级的范围: "<<endl;
cout<<"下限:";
cin>>low;
cout<<"上限:";
cin>>high;
cout<<endl;
while (p)
{
if (p->Class>=low&&p->Class<=high)
{
++count;
Unit *q;
q=new Unit (p->Name, p->PWD, p->Sex, p->Old, p->Class, p->ID, p->Math, p->Chinese, p->English, p->Authority);
q->next=NULL;
if (temp) //追加记录
{
Unit *s;
s=temp;
while (s->next) //s移到表尾
{
s=s->next;
}
s->next=q; //将新节点插入
}
else //空表情况
{
//直接插入
temp=q;
}
}
p=p->next;
}
return temp;
}
void InfoManager::SearchByName()
{
string cName;
Unit *p1=NULL;
Unit *p2=NULL;
char choice;
do
{
cout<<"请输入要查找的姓名: ";
p1=head_stu;
p2=head_tea;
cin>>cName;
cout<<endl;
while (p1)
{
if (p1->Name==cName) break;
else p1=p1->next;
}
if (!p1)
{
while (p2)
{
if (p2->Name==cName) break;
else p2=p2->next;
}
}
if (!p1&&!p2)
{
cout<<"\t不存在此用户!是否重新查找?[Y/N]";
do
{
cin>>choice;
if (toupper(choice)=='Y') break;
else if (toupper(choice)=='N') return;
else cout<<"\t输入错误!是否重新查找?[Y/N]"<<endl;
} while (1);
}
else
{
cout<<"所查询的用户信息为:"<<endl;
if (p1) InfoManager::Show_Sgl_Stu(p1);
else InfoManager::Show_Sgl_Tea (p2);
break;
}
} while (1);
}
Unit * InfoManager::SearchByChinese(Unit * p, int & count)
{
if (!p)
{
cout<<"无查询结果"<<endl;
return NULL;
}
int low, high;
Unit *temp=NULL;
count = 0;
cout<<"按语文成绩查询\n"<<endl;
cout<<"\n\n\t请输入要查寻成绩的范围: "<<endl;
cout<<"下限:";
cin>>low;
cout<<"上限:";
cin>>high;
cout<<endl;
while (p)
{
if (p->Chinese>=low&&p->Chinese<=high)
{
++count;
Unit *q;
q=new Unit (p->Name, p->PWD, p->Sex, p->Old, p->Class, p->ID, p->Math, p->Chinese, p->English, p->Authority);
q->next=NULL;
if (temp) //追加记录
{
Unit *s;
s=temp;
while (s->next) //s移到表尾
{
s=s->next;
}
s->next=q; //将新节点插入
}
else //空表情况
{
//直接插入
temp=q;
}
}
p=p->next;
}
return temp;
}
Unit * InfoManager::SearchByMath(Unit * p, int & count)
{
if (!p)
{
cout<<"无查询结果"<<endl;
return NULL;
}
int low, high;
Unit *temp=NULL;
count = 0;
cout<<"按数学成绩查询\n"<<endl;
cout<<"\n\n\t请输入要查寻成绩的范围: "<<endl;
cout<<"下限:";
cin>>low;
cout<<"上限:";
cin>>high;
cout<<endl;
while (p)
{
if (p->Math>=low&&p->Math<=high)
{
++count;
Unit *q;
q=new Unit (p->Name, p->PWD, p->Sex, p->Old, p->Class, p->ID, p->Math, p->Chinese, p->English, p->Authority);
q->next=NULL;
if (temp) //追加记录
{
Unit *s;
s=temp;
while (s->next) //s移到表尾
{
s=s->next;
}
s->next=q; //将新节点插入
}
else //空表情况
{
//直接插入
temp=q;
}
}
p=p->next;
}
return temp;
}
Unit * InfoManager::SearchByEnglish(Unit * p, int & count)
{
if (!p)
{
cout<<"无查询结果"<<endl;
return NULL;
}
int low, high;
Unit *temp=NULL;
count = 0;
cout<<"按英语成绩查询\n"<<endl;
cout<<"\n\n\t请输入要查寻成绩的范围: "<<endl;
cout<<"下限:";
cin>>low;
cout<<"上限:";
cin>>high;
cout<<endl;
while (p)
{
if (p->English>=low&&p->English<=high)
{
++count;
Unit *q;
q=new Unit (p->Name, p->PWD, p->Sex, p->Old, p->Class, p->ID, p->Math, p->Chinese, p->English, p->Authority);
q->next=NULL;
if (temp) //追加记录
{
Unit *s;
s=temp;
while (s->next) //s移到表尾
{
s=s->next;
}
s->next=q; //将新节点插入
}
else //空表情况
{
//直接插入
temp=q;
}
}
p=p->next;
}
return temp;
}
Unit * InfoManager::SearchByTotal(Unit * p, int & count)
{
if (!p)
{
cout<<"无查询结果"<<endl;
return NULL;
}
int low, high;
Unit *temp=NULL;
count = 0;
cout<<"按总分查询\n"<<endl;
cout<<"\n\n\t请输入要查寻总分的范围: "<<endl;
cout<<"下限:";
cin>>low;
cout<<"上限:";
cin>>high;
cout<<endl;
while (p)
{
if (p->Total>=low&&p->Total<=high)
{
++count;
Unit *q;
q=new Unit (p->Name, p->PWD, p->Sex, p->Old, p->Class, p->ID, p->Math, p->Chinese, p->English, p->Authority);
q->next=NULL;
if (temp) //追加记录
{
Unit *s;
s=temp;
while (s->next) //s移到表尾
{
s=s->next;
}
s->next=q; //将新节点插入
}
else //空表情况
{
//直接插入
temp=q;
}
}
p=p->next;
}
return temp;
}
Unit * InfoManager::SearchByAverage(Unit * p, int & count)
{
if (!p)
{
cout<<"无查询结果"<<endl;
return NULL;
}
int low, high;
Unit *temp=NULL;
count = 0;
cout<<"按平均成绩查询\n"<<endl;
cout<<"\n\n\t请输入要查寻平均成绩的范围: "<<endl;
cout<<"下限:";
cin>>low;
cout<<"上限:";
cin>>high;
cout<<endl;
while (p)
{
if (p->Average>=low&&p->Average<=high)
{
++count;
Unit *q;
q=new Unit (p->Name, p->PWD, p->Sex, p->Old, p->Class, p->ID, p->Math, p->Chinese, p->English, p->Authority);
q->next=NULL;
if (temp) //追加记录
{
Unit *s;
s=temp;
while (s->next) //s移到表尾
{
s=s->next;
}
s->next=q; //将新节点插入
}
else //空表情况
{
//直接插入
temp=q;
}
}
p=p->next;
}
return temp;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -