




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
第C++實(shí)現(xiàn)小型圖書管理系統(tǒng)本文實(shí)例為大家分享了C++實(shí)現(xiàn)小型圖書管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
因?yàn)檎n程設(shè)計(jì)的原因,需要實(shí)現(xiàn)一個小型圖書管理系統(tǒng)
包含功能:
問題描述:
設(shè)計(jì)一個系統(tǒng),對圖書信息進(jìn)行管理,信息描述:有關(guān)該系統(tǒng)基本信息的描述,如:圖書名稱、圖書編號、單價、作者、存在狀態(tài)、借書人姓名、性別、學(xué)號等。
基本要求:
基本功能:
1、新進(jìn)圖書基本信息的輸入。
2、圖書基本信息的查詢。
3、對撤消圖書信息的刪除。
4、為借書人辦理注冊。
5、辦理借書手續(xù)(非注冊會員不能借書)。
6、辦理還書手續(xù)。
7、統(tǒng)計(jì)圖書庫存、已借出圖書數(shù)量。
需要創(chuàng)建三個文本文件:record.txtbook.txtreader.txt
operating.h的頭文件:
#includeiostream
#includefstream
#includestring
#includetime.h
#includesstream
#includevector
#includeiomanip
usingnamespacestd;
intall_stock=0;
intout_stock=0;
inttimes=0;
voidoutData(vectorstringres,intn)
//n為txt中每行數(shù)據(jù)個數(shù)
for(inti=0;ires.size();i+=n){
for(intj=0;jj++)
coutsetw(12)res[i+j]"";
coutendl;
}
voidBookEntry()
doubleprice;
stringbookname,writer;
fstreamout;
out.open("book.txt",ios::app);
if(!out)
{
cerr"打開文件失敗!"endl;
}
time_ttt=time(NULL);//這句返回的只是一個時間cuo
cout"請輸入書籍名稱"endl;
cinbookname;
cout"請輸入書籍作者"endl;
cinwriter;
cout"請輸入書籍價格"endl;
while(!(cinprice)
||price=0)
{
cin.clear();
cin.ignore(100,'\n');
cout"請輸入正確的價格"endl;
}
outtt""bookname""writer""price"""0""\n";
out.close();
voidBookMes()
fstreamin;
stringline;
//用于存放分割后的字符串
vectorstringres;
stringtemp;//暫存字符串
in.open("book.txt",ios::in);
if(!in)
{
cerr"打開文件失敗!"endl;
}
all_stock=0;
while(getline(in,line))
{
all_stock++;
//coutlineendl;
//將字符串讀到input中
stringstreaminput(line);//將line切割通過input存入temp,然后存入res中
while(inputtemp)
{
res.push_back(temp);
}
}
//0書籍編號1書籍名稱2作者3價格4書籍狀態(tài)
//輸出res
coutendlsetw(12)"書籍編號"""setw(12)"書籍名稱"""setw(12)"作者"""setw(12)"價格"""setw(12)"在館0,不在1""\n";
outData(res,5);
in.close();
voidDelBook()
stringdel_book;
stringline;
vectorstring
stringtemp;
boolflag=false;
fstreamin;
in.open("book.txt",ios::in);
if(!in)
{
cerr"打開錯誤文件"endl;
}
cout"請輸入需要刪除的圖書ID"endl;
cindel_book;
while(getline(in,line))
{
//coutlineendl;
//將字符串讀到input中
stringstreaminput(line);//將line切割通過input存入temp,然后存入res中
times=0;
while(inputtemp)
{
if(del_book==temptimes==0)
{
for(inti=0;ii++)
//因?yàn)橐还参鍌€第一個temp已經(jīng)是del_book所以這里取得是四個
{
inputtemp;
}
inputtemp;
if(temp!="0")
{
cout"書籍狀態(tài)不對";
in.close();
return;
}
flag=true;
cout"\n找到了喔,應(yīng)該刪除成功了\n";
continue;
}
res.push_back(temp);
times++;
}
}
//outData(res,5);
in.close();
if(!flag)
{
cout"\n錯誤的書籍ID\n";
return;
}
fstreamout;
out.open("book.txt",ios::out);
if(!out)
{
cerr"打開文件失敗!"endl;
}
for(intj=0;jres.size();j+=5)
{
line=res[j]+""+res[j+1]+""+res[j+2]+""+res[j+3]+""+res[j+4]+"\n";
outline;
}
out.close();
voidReaderEntry()
stringreadername,sex_str;
intsex;
fstreamout;
out.open("reader.txt",ios::app);
if(!out)
{
cerr"打開文件失敗!"endl;
}
time_treaderid=time(NULL);//這句返回的只是一個時間cuo
cout"請輸入讀者姓名"endl;
cinreadername;
do
{
cout"請輸入讀者性別:0為女,1為男"endl;
while(!(cinsex))
{
cin.clear();
cin.ignore(100,'\n');
cout"請輸入正確的0或1"endl;
}
}while(sex!=0sex!=1);
if(sex==1)
{
sex_str="男";
}elseif(sex==0){
sex_str="女";
}else{
out.close();
return;
}
outreaderid""readername""sex_str"\n";
out.close();
/*讀者信息*/
voidReaderMes()
fstreamin;
stringline;
//用于存放分割后的字符串
vectorstringres;
stringtemp;//暫存字符串
in.open("reader.txt",ios::in);
if(!in)
{
cerr"打開文件失敗!"endl;
}
while(getline(in,line))
{
//coutlineendl;
//將字符串讀到input中
stringstreaminput(line);//將line切割通過input存入temp,然后存入res中
while(inputtemp)
res.push_back(temp);
}
//0讀者學(xué)號1讀者姓名2讀者性別
//輸出res
coutendlsetw(12)"讀者編號"""setw(12)"讀者"""setw(12)"性別""\n";
outData(res,3);
in.close();
/*借閱書籍*/
voidBorrowBook()
stringbook[5];
stringreaderid;
stringreadername;
stringline;
vectorstring//取書籍狀況,并且更新
stringtemp;
boolflag_book=false;//用于判斷書籍是否存在
讀者是否存在
boolflag_reader=false;
/*取book的圖書情況,并判斷是否在館*/
fstreamin;
in.open("book.txt",ios::in);
if(!in)
{
cerr"打開錯誤文件"endl;
}
cout"請輸入需要借的圖書ID"endl;
cinbook[0];
while(getline(in,line))
{
//coutlineendl;
//將字符串讀到input中
stringstreaminput(line);//將line切割通過input存入temp,然后存入res中
times=0;
while(inputtemp)
{
if(book[0]==temptimes==0)
{
res.push_back(temp);
for(inti=0;ii++)
//從書籍名稱開始取,一直取到價錢
{
inputtemp;//讀取了書籍編號,要及時寫入res,以后要寫進(jìn)文本
book[1+i]=temp;
res.push_back(temp);
}
inputtemp;
//取書籍狀態(tài),如果0在館如果1不在館
if(temp=="0")
{
book[4]="1";
temp="1";
res.push_back(temp);
flag_book=true;
}else{
cout"\n書籍不在館\n";
in.close();
return;
}
continue;
//繼續(xù)取
}
res.push_back(temp);
times++;
}
}
in.close();
if(!flag_book)
{
cout"錯誤的書籍ID"endl;
return;
}
in.open("reader.txt",ios::in);
if(!in)
{
cerr"打開錯誤文件"endl;
}
cout"\n請輸入讀者ID\n";
cinreaderid;
while(getline(in,line))
{
//coutlineendl;
//將字符串讀到input中
stringstreaminput(line);//將line切割通過input存入temp,然后存入res中
times=0;
while(inputtemp)
{
if(readerid==temptimes==0)
{
inputtemp;
readername=temp;
flag_reader=true;
break;
}
times++;
}
}
if(!flag_reader)
{
cout"錯誤的讀者ID"endl;
in.close();
return;
}
in.close();
fstreamout;
out.open("record.txt",ios::app);
if(!out)
{
cerr"打開錯誤文件"endl;
}
line=book[0]+""+book[1]+""+readername+'\n';
outline;
cout"\n辦理借書成功\n";
out.close();
out.open("book.txt",ios::out);
if(!out)
{
cerr"打開文件失敗!"endl;
}
for(intj=0;jres.size();j+=5)
{
line=res[j]+""+res[j+1]+""+res[j+2]+""+res[j+3]+""+res[j+4]+"\n";
outline;
}
out.close();
voidBorrowMes()
fstreamin;
stringline;
//用于存放分割后的字符串
vectorstringres;
stringtemp;//暫存字符串
in.open("record.txt",ios::in);
if(!in)
{
cerr"打開文件失敗!"endl;
}
out_stock=0;
while(getline(in,line))
{
out_stock++;
//coutlineendl;
//將字符串讀到input中
stringstreaminput(line);//將line切割通過input存入temp,然后存入res中
while(inputtemp)
res.push_back(temp);
}
//0書籍編號1書籍名稱2讀者姓名
//輸出res
coutendlsetw(12)"書籍編號"""setw(12)"書籍名稱"""setw(12)"讀者""\n";
outData(res,3);
in.close();
voidRtnBook()
stringrtn_book;
stringline;
vectorstring
stringtemp;
boolflag=false;
fstreamin;
in.open("record.txt",ios::in);
//先打開record查看是否有借這本書
if(!in)
{
cerr"打開錯誤文件"endl;
}
cout"請輸入需要?dú)w還的書籍ID"endl;
cinrtn_book;
while(getline(in,line))
{
//coutlineendl;
//將字符串讀到input中
stringstreaminput(line);//將line切割通過input存入temp,然后存入res中
times=0;
while(inputtemp)
{
if(rtn_book==temptimes==0)//如果有的話
{
flag=true;
for(inti=0;ii++)
//因?yàn)橐还踩齻€第一個temp已經(jīng)是del_book所以這里取得是兩個
{
inputtemp;//將刪除的東西不輸出到向量中
}
continue;
}
res.push_back(temp);
times++;
}
}
//outData(res,3);
in.close();
if(!flag)
{
cout"該圖書不存在或者沒有被外借"endl;
return;
}
fstreamout;
out.open("record.txt",ios::out);//record已經(jīng)刪除成功
if(!out)
{
cerr"打開文件失敗!"endl;
}
for(intj=0;jres.size();j+=3)
{
line=res[j]+""+res[j+1]+""+res[j+2]
+"\n";
outline;
}
out.close();
vectorstringres_book;
in.open("book.txt",ios::in);//開始取被修改的書籍
if(!in)
{
cerr"打開錯誤文件"endl;
}
while(getline(in,line))
{
//coutlineendl;
//將字符串讀到input中
stringstreaminput(line);//將line切割通過input存入temp,然后存入res中
times=0;
while(inputtemp)
{
if(rtn_book==temptimes==0)
{
res_book.push_back(temp);
for(inti=0;ii++)
//因?yàn)橐还参鍌€第一個temp已經(jīng)是rtn_book所以這里取得是四個
{
inputtemp;
res_book.push_back(temp);
}
inputtemp;//最后一個取得是書籍狀態(tài),需要修改書籍狀態(tài)
temp="0";
res_book.push_back(temp);
continue;
}
res_book.push_back(temp);
times++;
}
}
//outData(res,5);
in.close();
out.open("book.txt",ios::out);//再存入文本中;
if(!out)
{
cerr"打開文件失敗!"endl;
}
for(intj=0;jres_book.size();j+=5)
{
line=res_book[j]+""+res_book[j+1]+""+res_book[j+2]+""+res_book[j+3]+""+res_book[j+4]+"\n";
outline;
}
out.close();
cout"\n找到了喔,應(yīng)該還書成功了\n";
voidCountBook()
{
cout"\n圖書館書籍情況";
BookMes();
cout"圖書館一共有:"all_stock"本書\n\n\n";
cout"\n圖書館書籍外借情況";
BorrowMes();
cout"圖書館目前外借:"out_stock"本書\n\n";
cout"\n\n圖書館當(dāng)前在館書籍還有:"all_stock-out_stock"本書\n";
}
main.cpp的主函數(shù)
#include"operating.h"
intmain()
intorder;
do
{
order=-1;
cout"\n";
cout"----------------------------------------------------------\n";
cou
溫馨提示
- 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)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 智慧課堂與學(xué)生心理發(fā)展的關(guān)聯(lián)研究
- 教育心理學(xué)的跨學(xué)科應(yīng)用以科技助力情感智商的培養(yǎng)
- 教育科技前沿激發(fā)學(xué)生創(chuàng)新思維的實(shí)踐案例
- 教育創(chuàng)新驅(qū)動下的自動駕駛與物聯(lián)網(wǎng)教學(xué)研究
- 基于智能分析的教學(xué)管理信息系統(tǒng)應(yīng)用推廣研究
- 中醫(yī)傳承教育與現(xiàn)代醫(yī)療體系的融合
- 抖音商戶主播直播中控場能力評估制度
- 全球鈾礦資源分布與2025年核能產(chǎn)業(yè)安全與環(huán)保研究報告
- Baumycin-A1-生命科學(xué)試劑-MCE
- 福建省福州市金山中學(xué)2024-2025學(xué)年化學(xué)九上期末達(dá)標(biāo)測試試題含解析
- 中醫(yī)執(zhí)業(yè)醫(yī)師歷年真題及解答
- 鎮(zhèn)江市鑫泰絕緣材料有限公司新型絕緣材料生產(chǎn)項(xiàng)目環(huán)評資料環(huán)境影響
- 商業(yè)領(lǐng)域的數(shù)字化轉(zhuǎn)型與人才培養(yǎng)的深度融合研究報告
- 2025年木板式家具行業(yè)深度研究報告
- 2024-2025學(xué)年人教版PEP六年級下學(xué)期期末試卷(含答案含聽力原文無音頻)
- 2025屆陜西省西安西工大附中物理八下期末質(zhì)量檢測試題含解析
- 2025-2030年中國聚脲涂料行業(yè)市場現(xiàn)狀供需分析及投資評估規(guī)劃分析研究報告
- 2025年中考數(shù)學(xué)模擬試卷及答案(共五套)
- 一級建造師考試安全管理試題及答案
- 《成人糖尿病患者的高血糖危象:共識報告》-學(xué)習(xí)與應(yīng)用
- 2024年浙江省三支一扶考試真題
評論
0/150
提交評論