?? 3號(hào)文件.cpp
字號(hào):
}
else cout<<"您所查詢的信息不存在"<<endl;
}
if(a==2)
{
cout<<"請(qǐng)輸入姓名:";
string s;
cin>>s;
vector<Record*>::iterator i,j,k;
i=recVec.begin();k=recVec.end();
j=findRecord(i,s,0);
if(j!=k)
{
dispTable();
dispRecord(j);
cout<<"是否確定修改記錄.(yes/no)";
string s;
cin>>s;
while((s!="yes")&&(s!="no"))
{
cout<<"是否確定修改記錄.(yes/no)";
cin>>s;
}
if(s=="yes")
{
cout<<"請(qǐng)輸入學(xué)生的信息:"<<endl;
cout<<"學(xué)號(hào):";cin>>(*j)->number;
cout<<"姓名:";cin>>(*j)->name;
cout<<"性別:";cin>>(*j)->gender;
cout<<subject_[0]<<"成績(jī):";cin>>(*j)->score[0];
cout<<subject_[1]<<"成績(jī):";cin>>(*j)->score[1];
cout<<subject_[2]<<"成績(jī):";cin>>(*j)->score[2];
cout<<subject_[3]<<"成績(jī):";cin>>(*j)->score[3];
cout<<subject_[4]<<"成績(jī):";cin>>(*j)->score[4];
(*j)->sum=0;
for(int i=0;i<=4;i++)
(*j)->sum+=(*j)->score[i];
(*j)->average=(*j)->sum/5;
getIndex();
}
}
else cout<<"您所查詢的信息不存在"<<endl;
}
if(a==3)
{
cout<<"請(qǐng)輸入名次:";
int s;
cin>>s;
vector<Record*>::iterator i,j,k;
i=recVec.begin();k=recVec.end();
j=findRecord(i," ",s);
if(j!=k)
{
dispTable();
dispRecord(j);
cout<<"是否確定修改記錄.(yes/no)";
string s;
cin>>s;
while((s!="yes")&&(s!="no"))
{
cout<<"是否確定修改記錄.(yes/no)";
cin>>s;
}
if(s=="yes")
{
cout<<"請(qǐng)輸入學(xué)生的信息:"<<endl;
cout<<"學(xué)號(hào):";cin>>(*j)->number;
cout<<"姓名:";cin>>(*j)->name;
cout<<"性別:";cin>>(*j)->gender;
cout<<subject_[0]<<"成績(jī):";cin>>(*j)->score[0];
cout<<subject_[1]<<"成績(jī):";cin>>(*j)->score[1];
cout<<subject_[2]<<"成績(jī):";cin>>(*j)->score[2];
cout<<subject_[3]<<"成績(jī):";cin>>(*j)->score[3];
cout<<subject_[4]<<"成績(jī):";cin>>(*j)->score[4];
(*j)->sum=0;
for(int i=0;i<=4;i++)
(*j)->sum+=(*j)->score[i];
(*j)->average=(*j)->sum/5;
getIndex();
}
}
else cout<<"您所查詢的信息不存在"<<endl;
}
} //修改記錄
virtual void sortRecords()
{
int a;
cout<<"1.按學(xué)號(hào)排序"<<endl;
cout<<"2.按姓名排序"<<endl;
cout<<"3.按名次排序"<<endl;
cout<<"請(qǐng)選擇排序方法:";cin>>a;
while((a!=1)&&(a!=2)&&(a!=3))
{
cout<<"請(qǐng)選擇排序方法:";
cin>>a;
}
if(a==1)
{
cout<<"1.按升序排序"<<endl;
cout<<"2.按降序排序"<<endl;
cout<<"請(qǐng)選擇排序方法:";int b;cin>>b;
while(b!=1&&b!=2)
{
cout<<"請(qǐng)選擇排序方法:";
cin>>b;
}
if(b==1)
{
int o=recVec.size();
if(o==0){cout<<"錯(cuò)誤,無(wú)記錄."<<endl;return;}
vector<Record*>::iterator i,a,b,q,j;
vector<Record*> v(1);j=v.begin();
a=recVec.begin();b=recVec.end()-1;
for(;a<b;b--)/////////////從末尾記起,提高效率
for(i=a,q=i+1;i<b;i++,q++)
if((*i)->number>(*q)->number)
{
(*j)=(*q);
(*q)=(*i);
(*i)=(*j);//////////基本的排序函數(shù)方法,
}displayRecords();
}
if(b==2)
{
int o=recVec.size();
if(o==0){cout<<"錯(cuò)誤,無(wú)記錄."<<endl;return;}
vector<Record*>::iterator i,a,b,q,j;
vector<Record*> v(1);j=v.begin();
a=recVec.begin();b=recVec.end()-1;
for(;a<b;b--)
for(i=a,q=i+1;i<b;i++,q++)
if((*i)->number<(*q)->number)
{
(*j)=(*q);
(*q)=(*i);//跟剛才的倒過(guò)來(lái)
(*i)=(*j);//////////基本的排序函數(shù)方法
}displayRecords();
}
}
if(a==2)
{
cout<<"1.按升序排序"<<endl;
cout<<"2.按降序排序"<<endl;
cout<<"請(qǐng)選擇排序方法:";int c;cin>>c;
while((c!=1)&&(c!=2))
{
cout<<"請(qǐng)選擇排序方法:";
cin>>c;
}
if(c==1)
{
int o=recVec.size();
if(o==0){cout<<"錯(cuò)誤,無(wú)記錄."<<endl;return;}
vector<Record*>::iterator i,a,b,q,j;
vector<Record*> v(1);j=v.begin();
a=recVec.begin();b=recVec.end()-1;
for(;a<b;b--)
for(i=a,q=i+1;i<b;i++,q++)
if((*i)->name>(*q)->name)
{
(*j)=(*q);
(*q)=(*i);
(*i)=(*j);
}displayRecords();
}
if(c==2)
{
int o=recVec.size();
if(o==0){cout<<"錯(cuò)誤,無(wú)記錄."<<endl;return;}
vector<Record*>::iterator i,a,b,q,j;
vector<Record*> v(1);j=v.begin();
a=recVec.begin();b=recVec.end()-1;
for(;a<b;b--)
for(i=a,q=i+1;i<b;i++,q++)
if((*i)->name<(*q)->name)
{
(*j)=(*q);
(*q)=(*i);
(*i)=(*j);
}displayRecords();
}
}
if(a==3)
{
cout<<"1.按升序排序"<<endl;
cout<<"2.按降序排序"<<endl;
cout<<"請(qǐng)選擇排序方法:";int d;cin>>d;
while((d!=1)&&(d!=2))
{
cout<<"請(qǐng)選擇排序方法:";
cin>>d;
}
if(d==1)
{
int o=recVec.size();
if(o==0){cout<<"錯(cuò)誤,無(wú)記錄."<<endl;return;}
vector<Record*>::iterator i,a,b,q,j;
vector<Record*> v(1);j=v.begin();
a=recVec.begin();b=recVec.end()-1;
for(;a<b;b--)
for(i=a,q=i+1;i<b;i++,q++)
if((*i)->index<(*q)->index)
{
(*j)=(*q);
(*q)=(*i);
(*i)=(*j);
}displayRecords();
}
if(d==2)
{
int o=recVec.size();
if(o==0){cout<<"錯(cuò)誤,無(wú)記錄."<<endl;return;}
vector<Record*>::iterator i,a,b,q,j;
vector<Record*> v(1);j=v.begin();
a=recVec.begin();b=recVec.end()-1;
for(;a<b;b--)
for(i=a,q=i+1;i<b;i++,q++)
if((*i)->index>(*q)->index)
{
(*j)=(*q);
(*q)=(*i);
(*i)=(*j);
}displayRecords();
}
}
} //記錄排序
virtual void saveRecords()//////////考查輸入輸出流
{
string filename;
cout<<"請(qǐng)輸入文件名:";
cin>>filename;///////filename是一個(gè)抽象的名字
ofstream outfile;
outfile.open(filename.c_str());
StuInfoVec::saveRecords(outfile);
} //保存記錄saveRecords()成員函數(shù)讓用戶輸入文件名,
//然后建立文件輸出流,再調(diào)用StuInfoVec類的saveRecords()成員函數(shù)完成。
virtual void loadRecords()
{
string s;
cout<<"從文件中讀取的記錄覆蓋當(dāng)前學(xué)生信息,還是追加到當(dāng)前學(xué)生信息的末尾.(yes/no)";
cin>>s;
while((s!="yes")&&(s!="no"))
{
cout<<"從文件中讀取的記錄覆蓋當(dāng)前學(xué)生信息,還是追加到當(dāng)前學(xué)生信息的末尾.(yes/no)";
cin>>s;
}
if(s=="yes")clear();/////////覆蓋前先清空記錄
cout<<"請(qǐng)輸入文件名:";
cin>>s;
ifstream infile;
infile.open(s.c_str());
if(!infile){cout<<"文件不存在."<<endl;return;}
StuInfoVec::loadRecords(infile);
}
virtual void quit()
{
delete this;
exit(0);
}
virtual void clear()
{
vector<Record*>::iterator a,b,i;int o;
o=recVec.size();
if(o==0){cout<<"錯(cuò)誤,無(wú)記錄."<<endl;return;}
displayRecords();
a=recVec.begin();b=recVec.end();
for(i=a;i<b;i++)
if((*i)->toBeDeleted==true)toRemvNodes++;
if(toRemvNodes!=0)
{
string s;
cout<<"以下"<<toRemvNodes<<"條記錄做了刪除標(biāo)記."<<endl;;
vector<Record*>::iterator i,j,k;
i=recVec.begin();k=recVec.end();
j=findRecord(i);
if(j!=k)
{
dispTable();
while(j!=k){dispRecord(j);j++;j=findRecord(j);}
}
cout<<"是否刪除。(yes/no):";
cin>>s;
while((s!="yes")&&(s!="no"))
{
cout<<"是否刪除。(yes/no):";
cin>>s;
}
if(s=="yes")
{
StuInfoVec::removePerform();
}
}
isModified=true;
if(isModified==true)
{
string s;
cout<<"記錄已經(jīng)被改動(dòng)是否進(jìn)行保存(yes/no):";
cin>>s;
while((s!="yes")&&(s!="no"))
{
cout<<"記錄已經(jīng)被改動(dòng)是否進(jìn)行保存(yes/no):";
cin>>s;
}
if(s=="yes")saveRecords();
}
cout<<"是否確定清除記錄.(yes/no):";
string l;
cin>>l;
while((l!="yes")&&(l!="no"))
{
cout<<"是否確定清除記錄.(yes/no):";
cin>>l;
}
if(l=="yes")StuInfoVec::clear();
}
char menuSelect()
{
cout<<"主菜單:"<<endl;
cout<<"(1)顯示記錄."<<endl;
cout<<"(2)查詢記錄."<<endl;
cout<<"(3)增加記錄."<<endl;
cout<<"(4)刪除記錄."<<endl;
cout<<"(5)更改記錄."<<endl;
cout<<"(6)整理記錄."<<endl;
cout<<"(7)保存記錄."<<endl;
cout<<"(8)讀取記錄."<<endl;
cout<<"(9)清除記錄."<<endl;
cout<<"(10)結(jié)束程序."<<endl;
cout<<"請(qǐng)選擇操作:";
int i;cin>>i;
while(i>10||i<1)
{cout<<"請(qǐng)選擇操作:";cin>>i;}
switch(i)
{
case 1:displayRecords();break;
case 2:queryRecord();break;
case 3:addRecord();break;
case 4:removeRecord();break;
case 5:modifyRecord();break;
case 6:sortRecords();break;
case 7:saveRecords();break;
case 8:loadRecords();break;
case 9:clear();break;
case 10:quit();break;
}
}
void dispTable()
{
cout<<"學(xué)號(hào) 姓名 性別 語(yǔ)文 數(shù)學(xué) 英語(yǔ) 物理 化學(xué) 總分 平均分 名次"<<endl;
}
void dispRecord(vector<Record*>::iterator i)//////////////位置吻合?
{
cout<<(*i)->number;
cout<<" "<<(*i)->name;
cout<<" "<<(*i)->gender;
cout<<" "<<(*i)->score[0]<<" ";
cout<<(*i)->score[1]<<" ";
cout<<(*i)->score[2]<<" ";
cout<<(*i)->score[3]<<" ";
cout<<(*i)->score[4]<<" ";
cout<<(*i)->sum<<" ";
cout<<(*i)->average<<" ";
cout<<(*i)->index<<endl;
}
void getIndex()
{
vector<Record*>::iterator i,c,a,b;int ncount=0;
a=recVec.begin();b=recVec.end();
for(i=a;i<b;i++)
{
for(c=a;c<b;c++)
if((*i)->sum<(*c)->sum)ncount++;
(*i)->index=ncount+1;ncount=0;
}
}
int getIndex(float sum)
{
vector<Record*>::iterator i,a,b;int ncount=0;
a=recVec.begin();b=recVec.end();
for(i=a;i<b;i++)
{
if(((*i)->sum)<sum)(*i)->index+=1;
if(((*i)->sum)>sum)ncount++;
return ncount; }
ncount++;
}
};
char* StuInfoManager::subject_[5]={"語(yǔ)文","數(shù)學(xué)","英語(yǔ)","物理","化學(xué)"};
int main()
{
StuInfoManager s;
return 0;
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -