




版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領
文檔簡介
第C++實現(xiàn)小型圖書管理系統(tǒng)本文實例為大家分享了C++實現(xiàn)小型圖書管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
因為課程設計的原因,需要實現(xiàn)一個小型圖書管理系統(tǒng)
包含功能:
問題描述:
設計一個系統(tǒng),對圖書信息進行管理,信息描述:有關該系統(tǒng)基本信息的描述,如:圖書名稱、圖書編號、單價、作者、存在狀態(tài)、借書人姓名、性別、學號等。
基本要求:
基本功能:
1、新進圖書基本信息的輸入。
2、圖書基本信息的查詢。
3、對撤消圖書信息的刪除。
4、為借書人辦理注冊。
5、辦理借書手續(xù)(非注冊會員不能借書)。
6、辦理還書手續(xù)。
7、統(tǒng)計圖書庫存、已借出圖書數(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++)
//因為一共五個第一個temp已經(jīng)是del_book所以這里取得是四個
{
inputtemp;
}
inputtemp;
if(temp!="0")
{
cout"書籍狀態(tài)不對";
in.close();
return;
}
flag=true;
cout"\n找到了喔,應該刪除成功了\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讀者學號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,以后要寫進文本
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"請輸入需要歸還的書籍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++)
//因為一共三個第一個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++)
//因為一共五個第一個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找到了喔,應該還書成功了\n";
voidCountBook()
{
cout"\n圖書館書籍情況";
BookMes();
cout"圖書館一共有:"all_stock"本書\n\n\n";
cout"\n圖書館書籍外借情況";
BorrowMes();
cout"圖書館目前外借:"out_stock"本書\n\n";
cout"\n\n圖書館當前在館書籍還有:"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)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 主攻中級審計師考試試題及答案輔導
- 外語聽力提升方案試題及答案
- 黑龍江省齊齊哈爾市2024-2025學年高三下學期第三次模擬考試數(shù)學試題(原卷版)
- 牢牢記住的無人機駕駛員執(zhí)照考試試題及答案
- 2024-2025學年度陽江市第三中學高三數(shù)學英才班練習學生版2025年4月16日版
- 2025年護師復方藥物應用規(guī)范試題及答案
- 安全生產(chǎn)理論與管理考核試題及答案
- 消防知識技能培訓方案設計試題及答案
- 民航安全審查流程的試題及答案
- 明確復習方向2025年建造師試題及答案
- 《建設工程施工合同(示范文本)》(GF-2017-0201)條款
- 新版人教版七年級下冊地理課件 第九章 東半球其他的地區(qū)和國家 第四節(jié) 澳大利亞
- 《康復評定技術》課件-第五章 運動控制
- 《水門事件簡介》課件
- 《建筑CAD 》課程標準
- 《抖音競品分析》課件
- 醫(yī)院藥學 課件全套 陳菲 模塊1-12 醫(yī)院藥學認知-臨床藥學進展
- 醫(yī)保知識及政策培訓課件
- 印染行業(yè)安全培訓
- 2024年中考二輪專題復習道德與法治主觀題答題技巧(小論文)之演講稿
- 華中師范大學第一附中2025屆高考沖刺押題(最后一卷)數(shù)學試卷含解析
評論
0/150
提交評論