




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
第C++實(shí)現(xiàn)小型圖書管理系統(tǒng)本文實(shí)例為大家分享了C++實(shí)現(xiàn)小型圖書管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
因?yàn)檎n程設(shè)計(jì)的原因,需要實(shí)現(xiàn)一個(gè)小型圖書管理系統(tǒng)
包含功能:
問(wèn)題描述:
設(shè)計(jì)一個(gè)系統(tǒng),對(duì)圖書信息進(jìn)行管理,信息描述:有關(guān)該系統(tǒng)基本信息的描述,如:圖書名稱、圖書編號(hào)、單價(jià)、作者、存在狀態(tài)、借書人姓名、性別、學(xué)號(hào)等。
基本要求:
基本功能:
1、新進(jìn)圖書基本信息的輸入。
2、圖書基本信息的查詢。
3、對(duì)撤消圖書信息的刪除。
4、為借書人辦理注冊(cè)。
5、辦理借書手續(xù)(非注冊(cè)會(huì)員不能借書)。
6、辦理還書手續(xù)。
7、統(tǒng)計(jì)圖書庫(kù)存、已借出圖書數(shù)量。
需要?jiǎng)?chuàng)建三個(gè)文本文件: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ù)個(gè)數(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"打開(kāi)文件失敗!"endl;
}
time_ttt=time(NULL);//這句返回的只是一個(gè)時(shí)間cuo
cout"請(qǐng)輸入書籍名稱"endl;
cinbookname;
cout"請(qǐng)輸入書籍作者"endl;
cinwriter;
cout"請(qǐng)輸入書籍價(jià)格"endl;
while(!(cinprice)
||price=0)
{
cin.clear();
cin.ignore(100,'\n');
cout"請(qǐng)輸入正確的價(jià)格"endl;
}
outtt""bookname""writer""price"""0""\n";
out.close();
voidBookMes()
fstreamin;
stringline;
//用于存放分割后的字符串
vectorstringres;
stringtemp;//暫存字符串
in.open("book.txt",ios::in);
if(!in)
{
cerr"打開(kāi)文件失敗!"endl;
}
all_stock=0;
while(getline(in,line))
{
all_stock++;
//coutlineendl;
//將字符串讀到input中
stringstreaminput(line);//將line切割通過(guò)input存入temp,然后存入res中
while(inputtemp)
{
res.push_back(temp);
}
}
//0書籍編號(hào)1書籍名稱2作者3價(jià)格4書籍狀態(tài)
//輸出res
coutendlsetw(12)"書籍編號(hào)"""setw(12)"書籍名稱"""setw(12)"作者"""setw(12)"價(jià)格"""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"打開(kāi)錯(cuò)誤文件"endl;
}
cout"請(qǐng)輸入需要?jiǎng)h除的圖書ID"endl;
cindel_book;
while(getline(in,line))
{
//coutlineendl;
//將字符串讀到input中
stringstreaminput(line);//將line切割通過(guò)input存入temp,然后存入res中
times=0;
while(inputtemp)
{
if(del_book==temptimes==0)
{
for(inti=0;ii++)
//因?yàn)橐还参鍌€(gè)第一個(gè)temp已經(jīng)是del_book所以這里取得是四個(gè)
{
inputtemp;
}
inputtemp;
if(temp!="0")
{
cout"書籍狀態(tài)不對(duì)";
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錯(cuò)誤的書籍ID\n";
return;
}
fstreamout;
out.open("book.txt",ios::out);
if(!out)
{
cerr"打開(kāi)文件失敗!"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"打開(kāi)文件失敗!"endl;
}
time_treaderid=time(NULL);//這句返回的只是一個(gè)時(shí)間cuo
cout"請(qǐng)輸入讀者姓名"endl;
cinreadername;
do
{
cout"請(qǐng)輸入讀者性別:0為女,1為男"endl;
while(!(cinsex))
{
cin.clear();
cin.ignore(100,'\n');
cout"請(qǐng)輸入正確的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"打開(kāi)文件失敗!"endl;
}
while(getline(in,line))
{
//coutlineendl;
//將字符串讀到input中
stringstreaminput(line);//將line切割通過(guò)input存入temp,然后存入res中
while(inputtemp)
res.push_back(temp);
}
//0讀者學(xué)號(hào)1讀者姓名2讀者性別
//輸出res
coutendlsetw(12)"讀者編號(hào)"""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"打開(kāi)錯(cuò)誤文件"endl;
}
cout"請(qǐng)輸入需要借的圖書ID"endl;
cinbook[0];
while(getline(in,line))
{
//coutlineendl;
//將字符串讀到input中
stringstreaminput(line);//將line切割通過(guò)input存入temp,然后存入res中
times=0;
while(inputtemp)
{
if(book[0]==temptimes==0)
{
res.push_back(temp);
for(inti=0;ii++)
//從書籍名稱開(kāi)始取,一直取到價(jià)錢
{
inputtemp;//讀取了書籍編號(hào),要及時(shí)寫入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"錯(cuò)誤的書籍ID"endl;
return;
}
in.open("reader.txt",ios::in);
if(!in)
{
cerr"打開(kāi)錯(cuò)誤文件"endl;
}
cout"\n請(qǐng)輸入讀者ID\n";
cinreaderid;
while(getline(in,line))
{
//coutlineendl;
//將字符串讀到input中
stringstreaminput(line);//將line切割通過(guò)input存入temp,然后存入res中
times=0;
while(inputtemp)
{
if(readerid==temptimes==0)
{
inputtemp;
readername=temp;
flag_reader=true;
break;
}
times++;
}
}
if(!flag_reader)
{
cout"錯(cuò)誤的讀者ID"endl;
in.close();
return;
}
in.close();
fstreamout;
out.open("record.txt",ios::app);
if(!out)
{
cerr"打開(kāi)錯(cuò)誤文件"endl;
}
line=book[0]+""+book[1]+""+readername+'\n';
outline;
cout"\n辦理借書成功\n";
out.close();
out.open("book.txt",ios::out);
if(!out)
{
cerr"打開(kāi)文件失敗!"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"打開(kāi)文件失敗!"endl;
}
out_stock=0;
while(getline(in,line))
{
out_stock++;
//coutlineendl;
//將字符串讀到input中
stringstreaminput(line);//將line切割通過(guò)input存入temp,然后存入res中
while(inputtemp)
res.push_back(temp);
}
//0書籍編號(hào)1書籍名稱2讀者姓名
//輸出res
coutendlsetw(12)"書籍編號(hào)"""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);
//先打開(kāi)record查看是否有借這本書
if(!in)
{
cerr"打開(kāi)錯(cuò)誤文件"endl;
}
cout"請(qǐng)輸入需要?dú)w還的書籍ID"endl;
cinrtn_book;
while(getline(in,line))
{
//coutlineendl;
//將字符串讀到input中
stringstreaminput(line);//將line切割通過(guò)input存入temp,然后存入res中
times=0;
while(inputtemp)
{
if(rtn_book==temptimes==0)//如果有的話
{
flag=true;
for(inti=0;ii++)
//因?yàn)橐还踩齻€(gè)第一個(gè)temp已經(jīng)是del_book所以這里取得是兩個(gè)
{
inputtemp;//將刪除的東西不輸出到向量中
}
continue;
}
res.push_back(temp);
times++;
}
}
//outData(res,3);
in.close();
if(!flag)
{
cout"該圖書不存在或者沒(méi)有被外借"endl;
return;
}
fstreamout;
out.open("record.txt",ios::out);//record已經(jīng)刪除成功
if(!out)
{
cerr"打開(kāi)文件失敗!"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);//開(kāi)始取被修改的書籍
if(!in)
{
cerr"打開(kāi)錯(cuò)誤文件"endl;
}
while(getline(in,line))
{
//coutlineendl;
//將字符串讀到input中
stringstreaminput(line);//將line切割通過(guò)input存入temp,然后存入res中
times=0;
while(inputtemp)
{
if(rtn_book==temptimes==0)
{
res_book.push_back(temp);
for(inti=0;ii++)
//因?yàn)橐还参鍌€(gè)第一個(gè)temp已經(jīng)是rtn_book所以這里取得是四個(gè)
{
inputtemp;
res_book.push_back(temp);
}
inputtemp;//最后一個(gè)取得是書籍狀態(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"打開(kāi)文件失敗!"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. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 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ì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 代理裝卸合同范例
- 醫(yī)療AI與教育創(chuàng)新培養(yǎng)跨界人才
- 醫(yī)療保健行業(yè)的區(qū)塊鏈金融應(yīng)用-以DeFi和NFT為例
- 業(yè)主出租商鋪合同范例
- 色素性紫癜性皮病的臨床護(hù)理
- 化學(xué)必修二前三章知識(shí)點(diǎn)總結(jié)模版
- 保護(hù)個(gè)人信息合同范例
- 小學(xué)二年級(jí)線上語(yǔ)文教學(xué)總結(jié)模版
- 公司租賃設(shè)備合同范例
- 塞罕壩精神學(xué)習(xí)心得體會(huì)模版
- GB/T 3961-1993纖維增強(qiáng)塑料術(shù)語(yǔ)
- 醫(yī)學(xué)藥物基因檢測(cè)專題培訓(xùn)課件
- 學(xué)校項(xiàng)目工程監(jiān)理規(guī)劃
- 杭州市高層次人才分類認(rèn)定申請(qǐng)表-
- 高考語(yǔ)文答題思維導(dǎo)圖
- 教練技術(shù)三階段講義
- 2001船舶修理價(jià)格本中文
- 設(shè)備檢維修作業(yè)票填寫模板
- 危大工程動(dòng)態(tài)管控表
- 湖北省高等學(xué)校教學(xué)成果獎(jiǎng)推薦書、申請(qǐng)簡(jiǎn)表
- 商場(chǎng)重大危險(xiǎn)源評(píng)估標(biāo)準(zhǔn)
評(píng)論
0/150
提交評(píng)論