📄 stuinfomanager.cpp
字号:
}
}
void StuInfoManager::removeNote(bool isToRemove)
{
if(empty())
{ cout<<"当前没有任何记录."<<endl;
return;
}
if(!isToRemove && toRemvNodes == 0)
{
cout<<"当前没有被做了删除标记的项目"<<endl;
return;
}
char choi[5];
char pattern[20];
int type;
while (true){
cout<<"请输入更改的方式\n"
<<"1.按学号\n"
<<"2.按姓名\n"
<<"3.按名次\n";
cin.getline(choi,5);
if(choi[0] == '\0')
break;
if(choi[0] =='1')
{cout<<"请输入要查询的学生的学号:";
type = 0;
}else if(choi[0] =='2')
{cout<<"请输入要查询学生的姓名:";
type=1;
}else
{cout<<"请输入要查询学生的名次";
type=2;
}
cin.getline(pattern,20);
bool gotMatch=false;
Iterator it = findRecord(pattern,type,first());
Iterator it_end = pastEnd();
while (it!=it_end)
{
if((!isToRemove && !(*it)->toBeDeleted)||
(isToRemove && (*it)->toBeDeleted))
{
it = findRecord(pattern,type,++it);
continue;
}
gotMatch = true ;
cout<<" 找到一个匹配的记录:\n";
dispTable();
dispRecord(*it);
cout<<"确定要改变这条信息标示吗?(y/n)";
cin.getline(choi,5);
if(choi[0]!='n' && choi[0]!='N')
(*it)->toBeDeleted =!(*it)->toBeDeleted;
if(isToRemove)
toRemvNodes++;
else
toRemvNodes--;
it= findRecord(pattern,type,++it);
}
if (!gotMatch)
cout<<"没有找到匹配的记录"<<endl;
else
{if (toRemvNodes != 0)
cout<<"当前有"<<toRemvNodes
<<"条记录被做了删除标记"<<endl;
else
cout<<"现在没有记录 "<<endl;
}
}
}
void StuInfoManager::modifyRecord(){
if(empty())
{cout<<"没有可供修改的资料"<<endl;
return;
}
char choi[5];
char pattern[20];
char name[20];
int type;
string str;
while(true)
{cout<<"请输入如何找到欲修改的资料"
<<"1.按学号\n"
<<"2.按姓名\n"
<<"3.按名次\n";
cin.getline(choi,5);
if(choi[0] == '\0') break;
if(choi[0] == '1')
{cout<<"请输入要查询的学生的学号;";
type=0;}else if(choi[0] == '2')
{cout<<"请输入要查询的学生的姓名;";
type=1;}else
{cout<<"请输入要查询的学生的名次";
type=2;
}
cin.getline(pattern,20);
Iterator it = findRecord(pattern,type,first());
Iterator it_end = pastEnd();
if(it == it_end)
{cout<<"没有匹配的记录."<<endl;
continue;
}
while (it!=it_end)
{ cout<<"寻找一个匹配的记录\n";
dispTable();
dispRecord(*it);
cout<<"确定要修改这条记录吗?(Y/n)";
cin.getline(choi,5);
if(choi[0]!='n'&& choi[0]!='N')
{ int ncount = 0;
int tmpi =(*it)->index;
cout<<"下面请重新输入该学生信息\n";
cout<<"请输入学号";
cin>>(*it)->number;
cin.ignore();
cout<<"请输入姓名:";
cin.getline(name,20);
(*it)->name = name;
printf("请输入性别(1为男, 0为女):");
cin>>str;
cin.ignore();
if(str[0]=='0')
(*it)->gender ="女";
else
(*it)->gender ="男 ";
float sum=0;
for (int j=0;j<NUM_SUBJECT;j++)
{
cout<<"请输入"<<subject_[j]<<"成绩:";
cin>>(*it)->score[j];
sum += (*it)->score[j];
}
cin.ignore();
(*it)->sum = sum;
(*it)->average = sum/NUM_SUBJECT;
ncount = 0;
Iterator it1;
for (it1=first(); it1!=it_end;it1++)
{if(it1 == it)continue;
if((*it)->index>tmpi&& (*it1)->sum>=sum)
(*it)->index--;
else if((*it)->index<=tmpi&& (*it1)->sum<sum)
(*it1)->index++;
if((*it)->sum>sum)
ncount++;
}
(*it)->index = ncount+1;
isModified = true ;
}
it = findRecord(pattern,type,++it);//取下一条匹配的记录
}
cout<<"已找完所有的记录\n"<<endl;
}
}
void StuInfoManager::sortRecords()
{ if(empty()){
cout<<"没有可供排序的记录"<<endl;
return;
}
string str;
cout<<"请你输入要进行的操作:"<<endl
<<"1.按名字的上升排列:"<<endl
<<"2.按名字的下降排列:"<<endl
<<"3.按学号进行升序排列:"<<endl
<<"4.按学号的降序进行排列:"<<endl
<<"5.按名次的升序进行排列:"<<endl
<<"6.按名次的降序进行排列:"<<endl
<<"7.不进行任何操作:"<<endl;
cin>>str;
cin.ignore();
if(str[0]<'1'||str[0]>'6') return;
int i,j;
int numStus = size();
for(i=0; i<numStus-1;i++)
{
for(j=i+1;j<numStus;j++)
{ if((str[0]=='1' && recVec[i]->number>recVec[j]->number)||
(str[0]=='2'&& recVec[i]->number<recVec[j]->number)||
(str[0]=='3'&&recVec[i]->name>recVec[j]->name) ||
(str[0]=='4'&&recVec[i]->name<recVec[j]->name) ||
(str[0]=='5'&&recVec[i]->index>recVec[j]->index )||
(str[0]=='6'&&recVec[i]->index<recVec[j]->index ))
swap(recVec[i],recVec[j]);
}
}
cout<<"排序已经完成"<<endl;
isModified = true ;
}
void StuInfoManager :: saveRecords()
{
if(empty()){
cout<<"没有记录程序"<<endl;
return;
}
char name[40];
string fname;
cout<<"请输入要存入的文件名:"<<endl;
cin.getline(name,40);
fname = name;
if(fname.empty())
fname = "sname";
ofstream of(fname.c_str(),ios_base::out);
if(!of)
{cout<<"不能存入文件"<<endl;
return;
}
StuInfoVec::saveRecords(of);
of.close();
cout<<size()<<"条记录已经存入文件"<<endl;
isModified = false ;
}
void StuInfoManager::loadRecords()
{
char choi[5];
if(!empty())
{cout<<"请选择是否覆盖现有的记录(y),还是继续读取:"<<endl
<<"记录添加到现有记录之后(n)"<<endl
<<"直接回车则覆盖现有记录"<<endl;
cin.getline(choi,5);
if(choi[0]=='n'||choi[0]=='N')
{isModified = true;
}
else
{clear();
}
}
string fname;
char fnamel[40];
cout<<"请输入要读取的文件名:";
cin.getline(fnamel,40);
fname= fnamel;
if(fname.empty())
fname = "sname";
ifstream ifs(fname.c_str(),ios_base::in);
if(!ifs){
cout<<"打不开文件请从新选择"<<endl;
return ;
}
int num = StuInfoVec::loadRecords(ifs);
ifs.close();
cout<<"取入"<<num<<"条记录.\n"
<<"现在一共有"<<size()<<"条记录"<<endl;
}
void StuInfoManager::quit(){
clear();
cout<<"谢谢使用本系统,下次再见"<<endl;
delete this;
system("pause");
exit(0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -