C++實(shí)現(xiàn)宿舍管理查詢系統(tǒng)_第1頁
C++實(shí)現(xiàn)宿舍管理查詢系統(tǒng)_第2頁
C++實(shí)現(xiàn)宿舍管理查詢系統(tǒng)_第3頁
C++實(shí)現(xiàn)宿舍管理查詢系統(tǒng)_第4頁
C++實(shí)現(xiàn)宿舍管理查詢系統(tǒng)_第5頁
已閱讀5頁,還剩5頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

第C++實(shí)現(xiàn)宿舍管理查詢系統(tǒng)stu.r[i]=stu.r[i-1];

for(j=i-2;stu.r[0].idstu.r[j].id;j--)

stu.r[j+1]=stu.r[j];

stu.r[j+1]=stu.r[0];

}

ofstreamoutfile("student.txt",ios::out);

if(!outfile){

//如果文件打開失敗

cout"文件打開失敗"endl;

exit(1);

}

//outfile"學(xué)號"setw(8)"姓名"setw(8)"宿舍號"endl;

outfilestu.lengthendl;

for(i=1;i=stu.length;i++){

outfilestu.r[i].idsetw(8)stu.r[i].namesetw(8)stu.r[i].dormidendl;

}

cout"學(xué)生信息數(shù):"stu.lengthendl;

outfile.close();

coutstu.length;

//創(chuàng)建學(xué)生信息(只能創(chuàng)建一次,不然會被刷新)

voidInitList(SqListstu)

inti;

cout"學(xué)號"setw(8)"姓名"setw(8)"宿舍號"endl;

for(i=1;i=stu.length;i++){

cinstu.r[i].idstu.r[i].namestu.r[i].dormid;

}

InsertSort(stu);

//增加學(xué)生信息

voidAddstudent(SqListstu)

intn;

inti=stu.length+1;

cout"輸入增加學(xué)生人數(shù)"endl;

cinn;

cout"學(xué)號"setw(8)"姓名"setw(8)"宿舍號"endl;

stu.length=stu.length+n;

for(i;i=stu.length;i++)

cinstu.r[i].idstu.r[i].namestu.r[i].dormid;

InsertSort(stu);

//查詢學(xué)生信息

voidFindstudent(SqListstu)

stringa,b,c;

stringname,id,dormid;

cout"1.學(xué)號查詢

2.姓名查詢

3.宿舍號查詢"endl;

cout"請輸入你的查詢選擇(1~3)"endl;

inti;

intn;

cinn;

if(n1n3)

{

cout"您輸入有誤,請重新輸入:"endl;

Findstudent(stu);

}

if(1==n)

{

cout"請輸入學(xué)生學(xué)號:"endl;

cinid;

ifstreaminfile("student.txt",ios::in);//定義輸入文件流對象,以輸入方式打開磁盤文件"student.txt"

infilestu.length;

for(i=1;i=stu.length;i++){

infilestu.r[i].idstu.r[i].namestu.r[i].dormid;

}

infile.close();

for(i=1;i=stu.length;i++)

{

infilestu.r[i].idstu.r[i].namestu.r[i].dormid;

if(stu.r[i].id==id)

coutstu.r[i].idsetw(8)stu.r[i].namesetw(8)stu.r[i].dormidendl;

}

infile.close();//關(guān)閉磁盤文件

}

if(2==n)

{

cout"請輸入學(xué)生姓名:"endl;

cinname;

ifstreaminfile("student.txt",ios::in);//定義輸入文件流對象,以輸入方式打開磁盤文件"student.txt"

infilestu.length;

for(i=1;i=stu.length;i++){

infilestu.r[i].idstu.r[i].namestu.r[i].dormid;

}

infile.close();

for(i=1;i=stu.length;i++)

{

infilestu.r[i].idstu.r[i].namestu.r[i].dormid;

if(stu.r[i].name==name)

coutstu.r[i].idsetw(8)stu.r[i].namesetw(8)stu.r[i].dormidendl;

}

infile.close();//關(guān)閉磁盤文件

}

if(3==n)

{

cout"請輸入學(xué)生宿舍號:"endl;

cindormid;

ifstreaminfile("student.txt",ios::in);//定義輸入文件流對象,以輸入方式打開磁盤文件"student.txt"

infilestu.length;

for(i=1;i=stu.length;i++){

infilestu.r[i].idstu.r[i].namestu.r[i].dormid;

}

infile.close();

for(i=1;i=stu.length;i++)

{

infilestu.r[i].idstu.r[i].namestu.r[i].dormid;

if(stu.r[i].dormid==dormid)

coutstu.r[i].idsetw(8)stu.r[i].namesetw(8)stu.r[i].dormidendl;

}

}

//修改學(xué)生信息

voidRenewstudent(SqListstu)

intn;

stringid,name,dormid;

cout"1.姓名

2.宿舍號"endl;

cout"請輸入您的選擇(1~2):"endl;

cinn;

cout"請輸入需要修改學(xué)生的學(xué)號"endl;

cinid;

if(n!=1n!=2)

{

cout"輸入有誤,請重新輸入:"endl;

Renewstudent(stu);

}

if(1==n)

{

cout"請輸入修改姓名"endl;

cinname;

inti=0;

ifstreaminfile("student.txt",ios::in);

infilestu.length;

for(i=1;i=stu.length;i++){

infilestu.r[i].idstu.r[i].namestu.r[i].dormid;

}

infile.close();

for(i=1;i=stu.length;i++)//先找到再修改

{

if(stu.r[i].id==id)

{

stu.r[i].name=name;

InsertSort(stu);

return;

}

}

}

if(2==n)

{

inti;

cout"請輸入修改宿舍號"endl;

cindormid;

ifstreaminfile("student.txt",ios::in);

infilestu.length;

for(i=1;i=stu.length;i++){

infilestu.r[i].idstu.r[i].namestu.r[i].dormid;

}

infile.close();

for(i=1;i=stu.length;i++)//先找到再修改

{

if(stu.r[i].id==id)

{

stu.r[i].dormid=dormid;

InsertSort(stu);

return;

}

}

}

//顯示宿舍信息

voidShowstudent(SqListstu)

stringa,b,c;

inti;

cout"學(xué)生的信息如下:"endl;

cout"**********************************"endl;

ifstreaminfile("student.txt",ios::in);

if(!infile){

//如果文件打開失敗

cout"文件打開失敗"endl;

exit(1);

}

/*infileabc;//從磁盤文件讀入

coutasetw(8)bsetw(8)cendl;//在顯示器上顯示*/

infilestu.length;

for(i=1;i=stu.length;i++){

infilestu.r[i].idstu.r[i].namestu.r[i].dormid;

coutstu.r[i].idsetw(8)stu.r[i].namesetw(8)stu.r[i].dormidendl;

}

infile.close();

//刪除宿舍信息

voidDeletstudent(SqListstu)

int

i,j;

stringa,b,c,id;

cout"請輸入刪除學(xué)生學(xué)號"endl;

cinid;

ifstreaminfile("student.txt",ios::in);//定義輸入文件流對象,以輸入方式打開磁盤文件"student.txt"

infilestu.length;

for(i=1;i=stu.length;i++){

infilestu.r[i].idstu.r[i].namestu.r[i].dormid;

}

infile.close();

for(i=1;i=stu.length;i++)//先找到再刪除

{

if(stu.r[i].id==id)

{

for(j=i;jstu.length;j++)

stu.r[j]=stu.r[j+1];

stu.length--;

InsertSort(stu);

return;

}

}

//主函數(shù)

intmain()

SqListstu;

intn;

for(;;)

{

cout"**************************宿舍管理查詢軟件**************************"endl;

cout"1.創(chuàng)建學(xué)生信息"endl;

//InitList

cout"2.增加學(xué)生信息"endl;

//Addstudent

cout"3.查詢學(xué)生信息"endl;

//Findstudent

cout"4.顯示學(xué)生信息"endl;

//Showstudent

cout"5.修改學(xué)生信息"endl;

//Renewstudent

cout"6.刪除學(xué)生信息"endl;

//Deletstudent

cout"0.退出系統(tǒng)"endl;

cout"*******************************************************************"endl;

cout"請輸入你需要的操作(0~6):"endl;

cinn;

switch(n)

{

case1:

cout"輸入學(xué)生人數(shù)"endl;

cinstu.length;

InitList(stu);

cout"###########################################"endl;

break;

case2:

Addstudent(stu);

cout"###########

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論