📄 search.cpp
字号:
#include "StuClass.h"
//查询学生档案函数
void Search1() //按姓名查询档案
{
char sname[10];
ifstream file("Student.dat");
Student one;
file.seekg(0);
system("cls");
cout<<endl;
cout<<" **********姓名查询********** "<<endl;
cout<<endl;
cout<<endl;
cout<<"请输入您要查询的学生姓名:";
cin>>sname;
system("cls");
cout<<endl;
cout<<" 查询结果 "<<endl;
cout<<"-------------------------------------------------------------------------------"<<endl;
cout<<setiosflags(ios::left)
<<setw(7)<<"序号"<<setw(16)<<"学号"<<setw(11)<<"姓名"<<setw(7)<<"年龄"<<setw(7)<<"性别"
<<setw(10)<<"宿舍"<<setw(13)<<"电话"<<endl;
cout<<"-------------------------------------------------------------------------------"<<endl;
file.read((char *)&one,sizeof(one));
int l=0;
while (file)
{
if(Comparison(one.getname(),sname)==1)
{
one.Display();
l++;
}
file.read((char*)&one,sizeof(one));
};
cout<<"-------------------------------------------------------------------------------"<<endl;
cout<<"总共搜索到"<<l<<"个姓名为"<<sname<<"的学生清单.";
file.close();
for(int j=1;j<=17-l;j++)
cout<<endl;
cout<<"按任意键返回查询系统继续查询......"<<endl;
getch();
}
void Search2() //按学号查询档案
{
char sname[10];
ifstream file("Student.dat");
Student one;
file.seekg(0);
system("cls");
cout<<endl;
cout<<" **********学号查询********** "<<endl;
cout<<endl;
cout<<endl;
cout<<"请输入您要查询的学生学号:";
cin>>sname;
system("cls");
cout<<endl;
cout<<" 查询结果 "<<endl;
cout<<"-------------------------------------------------------------------------------"<<endl;
cout<<setiosflags(ios::left)
<<setw(7)<<"序号"<<setw(16)<<"学号"<<setw(11)<<"姓名"<<setw(7)<<"年龄"<<setw(7)<<"性别"
<<setw(10)<<"宿舍"<<setw(13)<<"电话"<<endl;
cout<<"-------------------------------------------------------------------------------"<<endl;
file.read((char *)&one,sizeof(one));
int l=0;
while (file)
{
if(Comparison(one.getregnum(),sname)==1)
{
one.Display();
l++;
}
file.read((char*)&one,sizeof(one));
};
cout<<"-------------------------------------------------------------------------------"<<endl;
cout<<"总共搜索到"<<l<<"个学号为"<<sname<<"的学生清单.";
file.close();
for(int j=1;j<=17-l;j++)
cout<<endl;
cout<<"按任意键返回查询系统继续查询......"<<endl;
getch();
}
void Search3() //按年龄查询档案
{
char sname[10];
ifstream file("Student.dat");
Student one;
file.seekg(0);
system("cls");
cout<<endl;
cout<<" **********年龄查询********** "<<endl;
cout<<endl;
cout<<endl;
cout<<"请输入您要查询的学生年龄:";
cin>>sname;
cout<<endl;
cout<<endl;
system("cls");
cout<<endl;
cout<<" 查询结果 "<<endl;
cout<<"-------------------------------------------------------------------------------"<<endl;
cout<<setiosflags(ios::left)
<<setw(7)<<"序号"<<setw(16)<<"学号"<<setw(11)<<"姓名"<<setw(7)<<"年龄"<<setw(7)<<"性别"
<<setw(10)<<"宿舍"<<setw(13)<<"电话"<<endl;
cout<<"-------------------------------------------------------------------------------"<<endl;
file.read((char *)&one,sizeof(one));
int l1=1,l2=1;
while (file)
{
if(Comparison(one.getage(),sname)==1)
{
one.Display();
l1++; ++l2;
if(l2==19)
{
cout<<"-------------------------------------------------------------------------------"<<endl;
cout<<"请按任意键继续输出......"<<endl;
getch();
l2=1;
system("cls");
cout<<endl;
cout<<" 查询结果 "<<endl;
cout<<"-------------------------------------------------------------------------------"<<endl;
cout<<setiosflags(ios::left)
<<setw(7)<<"序号"<<setw(16)<<"学号"<<setw(11)<<"姓名"<<setw(7)<<"年龄"<<setw(7)<<"性别"
<<setw(10)<<"宿舍"<<setw(13)<<"电话"<<endl;
cout<<"-------------------------------------------------------------------------------"<<endl;
}
}
file.read((char*)&one,sizeof(one));
};
cout<<"-------------------------------------------------------------------------------"<<endl;
cout<<"总共搜索到"<<l1-1<<"个年龄为"<<sname<<"的学生清单.";
file.close();
for(int j=1;j<=18-l2;j++)
cout<<endl;
cout<<"按任意键返回查询系统继续查询......"<<endl;
getch();
}
void Search4() //按性别查询档案
{
char sname[10];
ifstream file("Student.dat");
Student one;
file.seekg(0);
system("cls");
cout<<endl;
cout<<" **********性别查询********** "<<endl;
cout<<endl;
cout<<endl;
cout<<"请输入您要查询的学生性别:";
cin>>sname;
cout<<endl;
cout<<endl;
system("cls");
cout<<endl;
cout<<" 查询结果 "<<endl;
cout<<"-------------------------------------------------------------------------------"<<endl;
cout<<setiosflags(ios::left)
<<setw(7)<<"序号"<<setw(16)<<"学号"<<setw(11)<<"姓名"<<setw(7)<<"年龄"<<setw(7)<<"性别"
<<setw(10)<<"宿舍"<<setw(13)<<"电话"<<endl;
cout<<"-------------------------------------------------------------------------------"<<endl;
file.read((char *)&one,sizeof(one));
int l1=1,l2=1;
while (file)
{
if(Comparison(one.getsex(),sname)==1)
{
one.Display();
++l1;++l2;
if(l2==18)
{
cout<<"-------------------------------------------------------------------------------"<<endl;
cout<<"请按任意键继续输出......"<<endl;
getch();
l2=1;
system("cls");
cout<<endl;
cout<<" 查询结果 "<<endl;
cout<<"-------------------------------------------------------------------------------"<<endl;
cout<<setiosflags(ios::left)
<<setw(7)<<"序号"<<setw(16)<<"学号"<<setw(11)<<"姓名"<<setw(7)<<"年龄"<<setw(7)<<"性别"
<<setw(10)<<"宿舍"<<setw(13)<<"电话"<<endl;
cout<<"-------------------------------------------------------------------------------"<<endl;
}
}
file.read((char*)&one,sizeof(one));
};
cout<<"-------------------------------------------------------------------------------"<<endl;
cout<<"总共搜索到"<<l1-1<<"个性别为"<<sname<<"的学生清单.";
file.close();
for(int j=1;j<=18-l2;j++)
cout<<endl;
cout<<"按任意键返回查询系统继续查询......"<<endl;
getch();
}
void Search5() //按电话查询档案
{
char sname[10];
ifstream file("Student.dat");
Student one;
file.seekg(0);
system("cls");
cout<<endl;
cout<<" **********电话查询********** "<<endl;
cout<<endl;
cout<<endl;
cout<<"请输入您要查询的学生电话:";
cin>>sname;
system("cls");
cout<<endl;
cout<<" 查询结果 "<<endl;
cout<<"-------------------------------------------------------------------------------"<<endl;
cout<<setiosflags(ios::left)
<<setw(7)<<"序号"<<setw(16)<<"学号"<<setw(11)<<"姓名"<<setw(7)<<"年龄"<<setw(7)<<"性别"
<<setw(10)<<"宿舍"<<setw(13)<<"电话"<<endl;
cout<<"-------------------------------------------------------------------------------"<<endl;
file.read((char *)&one,sizeof(one));
int l=0;
while (file)
{
if(Comparison(one.gettelnum(),sname)==1)
{
one.Display();
l++;
}
file.read((char*)&one,sizeof(one));
};
cout<<"-------------------------------------------------------------------------------"<<endl;
cout<<"总共搜索到"<<l<<"个电话为"<<sname<<"的学生清单.";
file.close();
for(int j=1;j<=17-l;j++)
cout<<endl;
cout<<"按任意键返回查询系统继续查询......"<<endl;
getch();
}
void Search6() //按宿舍查询档案
{
char sname[10];
ifstream file("Student.dat");
Student one;
file.seekg(0);
system("cls");
cout<<endl;
cout<<" **********宿舍查询********** "<<endl;
cout<<endl;
cout<<endl;
cout<<"请输入您要查询的学生宿舍:";
cin>>sname;
system("cls");
cout<<endl;
cout<<" 查询结果 "<<endl;
cout<<"-------------------------------------------------------------------------------"<<endl;
cout<<setiosflags(ios::left)
<<setw(7)<<"序号"<<setw(16)<<"学号"<<setw(11)<<"姓名"<<setw(7)<<"年龄"<<setw(7)<<"性别"
<<setw(10)<<"宿舍"<<setw(13)<<"电话"<<endl;
cout<<"-------------------------------------------------------------------------------"<<endl;
file.read((char *)&one,sizeof(one));
int l=0;
while (file)
{
if(Comparison(one.getbedroom(),sname)==1)
{
one.Display();
l++;
}
file.read((char*)&one,sizeof(one));
};
cout<<"-------------------------------------------------------------------------------"<<endl;
cout<<"总共搜索到"<<l<<"个宿舍为"<<sname<<"的学生清单.";
file.close();
for(int j=1;j<=17-l;j++)
cout<<endl;
cout<<"按任意键返回查询系统继续查询......"<<endl;
getch();
}
void SearchMenu() //学生档案查询主界面
{
system("cls");
cout<<" "<<endl;
cout<<" ★学生档案查询系统★ "<<endl;
cout<<" "<<endl;
cout<<" **************************** "<<endl;
cout<<" $ $ "<<endl;
cout<<" $ 〖1. 按姓名查询 〗 $ "<<endl;
cout<<" $ $ "<<endl;
cout<<" $ 〖2. 按学号查询 〗 $ "<<endl;
cout<<" $ $ "<<endl;
cout<<" $ 〖3. 按年龄查询 〗 $ "<<endl;
cout<<" $ $ "<<endl;
cout<<" $ 〖4. 按性别查询 〗 $ "<<endl;
cout<<" $ $ "<<endl;
cout<<" $ 〖5. 按电话查询 〗 $ "<<endl;
cout<<" $ $ "<<endl;
cout<<" $ 〖6. 按宿舍查询 〗 $ "<<endl;
cout<<" $ $ "<<endl;
cout<<" $ 〖7. 退出查询 〗 $ "<<endl;
cout<<" $ $ "<<endl;
cout<<" **************************** "<<endl;
cout<<" "<<endl;
}
void Search() //学生档案查询主函数
{
char select;
SearchMenu();
do
{
cout<<" 输入选择的功能(1-7): "<<endl;
select=getch();
cout<<endl;
cout<<endl;
cout<<endl;
cout<<endl;
cout<<endl;
switch(select)
{
case '1':Search1(); SearchMenu(); break; //选择1时执行『按姓名查询』
case '2':Search2(); SearchMenu(); break; //选择2时执行『按学号查询』
case '3':Search3(); SearchMenu(); break; //选择3时执行『按年龄查询』
case '4':Search4(); SearchMenu(); break; //选择4时执行『按性别查询』
case '5':Search5(); SearchMenu(); break; //选择5时执行『按电话查询』
case '6':Search6(); SearchMenu(); break; //选择6时执行『按宿舍查询』
}
}while(select>='1' && select<='6');
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -