




版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、#include#defineDEBUG0/宏定義決定測(cè)試代碼是否編譯0為不編譯非0則編譯constcharbook_path20=books.txt;constcharreader_path20=readers.txt;/文件讀寫(xiě)聲明voidread_from_files_to_vector();voidwrite_all_to_files();#ifDEBUGvoidscan_readers()for(reader&s:readers)wcouts;#endifintmain()/完成操作后需要在控制臺(tái)按5中退出才會(huì)保存到文件wcin.imbue(china);wcout.imbue(ch
2、ina);read_from_files_to_vector();#ifDEBUGcoutsizeofreaders=readers.size()endl;coutsizeofbooks=books.size()endl;scan_book();scan_readers();#endifstringpassword=123456;/密碼已改cout歡迎使用中南大學(xué)網(wǎng)絡(luò)在線(xiàn)圖書(shū)系統(tǒng)endl;/這里可以添加你們小組的名單或一些裝飾的字符cout請(qǐng)選擇登錄方式endl;cout1管理員登陸2讀者登陸a;cleanScreen();if(a=1)stringstr;for(intj=0;j=4;j+)
3、cout請(qǐng)輸入管理密碼,你有(4-j)次機(jī)會(huì)str;if(password=str)break;elsecout密碼錯(cuò)誤!請(qǐng)重新輸入endl;if(j=4)return0;cleanScreen();cout歡迎來(lái)到圖書(shū)管理系統(tǒng)endl;cout成功登陸!你有以下操作可供選擇endl;coutendl;/操作循環(huán)cout1瀏覽圖書(shū)信息endl;cout2圖書(shū)信息修改endl;cout3圖書(shū)信息添加endl;cout4圖書(shū)信息刪除endl;cout5保存信息并退出系統(tǒng)endl;cout請(qǐng)選擇操作選項(xiàng)編號(hào)b;cleanScreen();while(b!=5)switch(b)case1:scan_
4、book();break;case2:modify_book();break;case3:add_book();break;case4:delete_book();break;default:cout輸入錯(cuò)誤,請(qǐng)重新輸入;break;coutendl;cout請(qǐng)進(jìn)行下一次操作endl;cout1瀏覽圖書(shū)信息endl;cout2圖書(shū)信息修改endl;cout3圖書(shū)信息添加endl;cout4圖書(shū)信息刪除endl;cout5退出系統(tǒng)endl;cout請(qǐng)選擇操作選項(xiàng)編號(hào)b;cleanScreen();write_all_to_files();return0;elseif(a=2)intreaderI
5、ndex=0;/記錄讀者下標(biāo)/輸入學(xué)號(hào)登陸cout請(qǐng)輸入學(xué)號(hào)endl;wchar_tstudentnumber20;for(intm=0;m=9;m+)cout請(qǐng)輸入學(xué)號(hào),你有(9-m)次機(jī)會(huì)studentnumber;intt;for(t=0;treaders.size();t+)if(wcscmp(studentnumber,readerst.cardnum)=0)readerIndex=t;break;/判斷跳出循環(huán)原因if(treaders.size()break;elsecout登錄賬號(hào)不存在,請(qǐng)重新輸入學(xué)號(hào)endl;continue;if(m=9)return0;cleanScre
6、en();cout歡迎來(lái)到讀者自助系統(tǒng)endl;wcoutL歡迎你,readersreaderIL!你有以下操作可供選擇endl;coutendl;/操作循環(huán)cout1圖書(shū)瀏覽endl;cout2圖書(shū)查詢(xún)endl;cout3圖書(shū)借閱endl;cout4圖書(shū)返還endl;cout5退出系統(tǒng)endl;cout請(qǐng)選擇操作選項(xiàng)c;cleanScreen();while(c!=5)switch(c)case1:scan_book();break;case2:search_book();break;case3:borrow_book(readerIndex);break;case4:re
7、turn_book(readerIndex);break;default:cout輸入錯(cuò)誤!請(qǐng)重新輸入endl;break;coutendl;cout請(qǐng)進(jìn)行下一次操作endl;cout1圖書(shū)瀏覽endl;cout2圖書(shū)查詢(xún)endl;cout3圖書(shū)借閱endl;cout4圖書(shū)返還endl;cout5退出系統(tǒng)endl;cout請(qǐng)選擇操作選項(xiàng)c;cleanScreen();write_all_to_files();return0;return0;/main函數(shù)結(jié)束/寫(xiě)入/讀取文件voidwrite_all_to_files()wofstreamoutfile;outfile.imbue(locale
8、(chs);/寫(xiě)入書(shū)本文件outfile.open(book_path);outfilebooks.size()n;for(inti=0;ibooks.size();i+)outfilebooksi;outfile.close();outfile.clear();/寫(xiě)入讀者文件,由于程序中沒(méi)有針對(duì)讀者的刪改(備用,將0改為1后即可編譯這段代碼)#if0outfile.open(path:reader_path);outfilereaders.size()n;for(inti=0;ireaders.size();i+)outfilesize;while(!infile.eof()&size!=0
9、)infilebb;books.push_back(bb);size-;infile.close();infile.clear();/讀取讀者數(shù)據(jù)infile.open(reader_path);infilesize;while(!infile.eof()&size!=0)infilerr;readers.push_back(rr);size-;infile.close();return;#includeclasses.hlocalechina(chs);/usechinacharacter/*voidprintout_book(book&b)(coutb.idnb.titlenb.first
10、authornb.publishernb.birthdaynb.locationnb.pricenb.numberendl;*/這個(gè)函數(shù)我用重載運(yùn)算符的函數(shù)代替了/對(duì)應(yīng)全局變量的定義vectorbooks;vectorreaders;/book重載操作符函數(shù)定義wistream&operator(wistream&in,book&b)(cout請(qǐng)輸入書(shū)號(hào)b.id;cout請(qǐng)輸入書(shū)名b.title;cout請(qǐng)輸入作者名b.firstauthor;cout請(qǐng)輸入出版社b.publisher;cout”請(qǐng)輸入印刷日期(年月)b.birthday;cout請(qǐng)輸入所屬類(lèi)別b.location;cout請(qǐng)
11、輸入價(jià)格b.price;cout請(qǐng)輸入數(shù)量b.number;returnin;)wostream&operator(wostream&out,book&b)(outb.idb.titleb.firstauthorb.publisherb.birthday.yearb.birthday.monthb.locationb.priceb.number(wifstream&in,book&b)(inb.idb.titleb.firstauthorb.publisherb.birthday.yearb.birthday.monthb.locationb.priceb.number;returnin;)w
12、ofstream&operator(wofstream&out,book&b)(outb.idb.titleb.firstauthorb.publisherb.birthdayb.locationb.priceb.number(wistream&in,reader&r)(/由于沒(méi)有對(duì)reader的操作,這個(gè)函數(shù)尚未被使用cout請(qǐng)輸入讀者姓名;cout請(qǐng)輸入性別(男為0,女為1)r.s;cout請(qǐng)輸入卡號(hào)r.cardnum;cout請(qǐng)輸入學(xué)位(學(xué)士為0,碩士為1,博士為2)r.e;r.already=0;已借書(shū)本數(shù)默認(rèn)為0returnin;)wostream&operator(wo
13、stream&out,reader&r)(outr.cardnum;;outr.s;outr.e;outr.already(wifstream&in,reader&r)(r.sr.er.already;returnin;)wofstream&operator(wofstream&out,reader&r)(r.sr.er.alreadyn;returnout;)/main函數(shù)中調(diào)用定義voidscan_book()/建立瀏覽函數(shù)(for(inti=0;ibooks.size();i+)(wcoutbooks
14、i;)voidsearch_book()/建立搜索函數(shù)(intg;cout你有以下查詢(xún)方式可供選擇cout你有以下查詢(xún)方式可供選擇*endl;cout1cout1按書(shū)名查詢(xún)endl;cout2按編號(hào)查詢(xún)endl;cout3按作者查詢(xún)endl;cout請(qǐng)選擇查詢(xún)方式CCcout請(qǐng)選擇查詢(xún)方式CC11g;cing;switch(g)case1:wchar_tname20;cout請(qǐng)輸入書(shū)名CCCcout請(qǐng)輸入書(shū)名CCC11name;for(intr=0;rwcinname;for(intr=0;rbooks.size();r+)if(wcscmp(booksr.title,name)=0)wcou
15、tbooksr;return;cout查無(wú)此書(shū)endl;return;break;intstr;cout*請(qǐng)輸入圖書(shū)編號(hào)*str;for(intl=0;lbooks.size();l+)if(booksl.id=str)wcoutbooksl;return;cout查無(wú)此書(shū)endl;return;break;wchar_tauth10;cout請(qǐng)輸入圖書(shū)作者auth;for(intp=0;pwchar_tauth10;cout請(qǐng)輸入圖書(shū)作者auth;for(intp=0;pbooks.size();p+)if(wcscmp(booksp.firstauthor,auth)=0)wcoutboo
16、ksp;return;cout查無(wú)此書(shū)endl;return;break;default:cout查無(wú)此書(shū)=5)cout抱歉,你的借書(shū)數(shù)已滿(mǎn),不可再借endl;return;intlog;cout*請(qǐng)輸入要借出圖書(shū)的登陸號(hào)CC11log;for(inti=0;i0)inty;cout確認(rèn)借出書(shū)籍嗎?確認(rèn)請(qǐng)輸入1取消請(qǐng)輸入0y;if(y=1)cout借閱成功!;-(booksi.number);+(readerst.already);return;elsereturn;elsecout圖書(shū)已借完endl;return;cout圖書(shū)不存在!endl;return;voidreturn_book(i
17、ntt)/建立還書(shū)函數(shù)intlog;cout*請(qǐng)輸入要?dú)w還的圖書(shū)的登陸號(hào)*log;for(inti=0;ibooks.size();i+)if(log=booksi.id)cout圖書(shū)歸還成功endl;+booksi.number;-readerst.already;return;cout圖書(shū)不存在于本圖書(shū)館無(wú)需歸還!endl;return;voidmodify_book()/建立修改函數(shù)intlog;cout*請(qǐng)輸入要修改的圖書(shū)編號(hào)*log;for(inti=0;ibooks.size();i+)if(log=booksi.id)cout需修改圖書(shū)信息如下endl;wcoutbooksi;cout*請(qǐng)輸入修改后的信息*booksi;return;cout圖書(shū)不存在無(wú)法修改endl;return;voiddelete_book()intlog;cout*cout*請(qǐng)輸入要?jiǎng)h除的圖書(shū)編號(hào)log;/迭代器實(shí)現(xiàn)刪除指定圖書(shū)vector:iteratoritor2;for(vector:iteratoriter=books.begin();iter!=books.end();)if
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 租車(chē)公司調(diào)車(chē)合同范本
- 服裝零售業(yè)務(wù)風(fēng)險(xiǎn)控制與合規(guī)性檢查考核試卷
- 印刷機(jī)高效節(jié)能技術(shù)的市場(chǎng)應(yīng)用潛力考核試卷
- 變頻電源相關(guān)行業(yè)投資規(guī)劃報(bào)告
- 辦公設(shè)備耗材更換與維護(hù)考核試卷
- 勘探設(shè)備在寶玉石礦勘查中的精細(xì)工藝考核試卷
- PA6T相關(guān)行業(yè)投資規(guī)劃報(bào)告
- 木材采運(yùn)的質(zhì)量控制管理體系考核試卷
- 懸掛式離子風(fēng)機(jī)相關(guān)行業(yè)投資規(guī)劃報(bào)告范本
- 加氣柱相關(guān)項(xiàng)目投資計(jì)劃書(shū)
- 2024.8.1十七個(gè)崗位安全操作規(guī)程手冊(cè)(值得借鑒)
- 缺血性心臟病麻醉
- 電影《白日夢(mèng)想家》課件
- 丙戊酸鈉與中樞神經(jīng)系統(tǒng)損傷保護(hù)的研究進(jìn)展
- 小紅書(shū)的運(yùn)營(yíng)技巧培訓(xùn)
- 員工上下班交通安全培訓(xùn)課件
- 2024年全國(guó)職業(yè)院校技能大賽中職組(短視頻制作賽項(xiàng))考試題庫(kù)-下(多選、判斷題)
- 《ISO 41001-2018 設(shè)施管理- 管理體系 要求及使用指南》專(zhuān)業(yè)解讀與應(yīng)用指導(dǎo)材料之9:“6 策劃-6.2 設(shè)施管理目標(biāo)及其實(shí)現(xiàn)的策劃”(雷澤佳編制-2024)
- 圍手術(shù)期患者安全管理規(guī)范及制度
- 《電力機(jī)車(chē)制動(dòng)系統(tǒng)檢查與維護(hù)》-課件-項(xiàng)目4-CCBⅡ制動(dòng)機(jī)檢查與操作
- 上海市英語(yǔ)小學(xué)六年級(jí)上學(xué)期試題及解答參考(2024年)
評(píng)論
0/150
提交評(píng)論