




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)
文檔簡介
第C++詳細(xì)實現(xiàn)完整圖書管理功能目錄圖書管理系統(tǒng)功能概覽:
登錄,注冊學(xué)生,老師借書,查看自己當(dāng)前借書情況,還書。管理員增加書,查看當(dāng)前借閱情況,查看當(dāng)前所有借閱人,圖書信息。
代碼概覽:
各個模塊主要負(fù)責(zé)功能
COperationManagement.h負(fù)責(zé)登錄,注冊,管理員,將圖書,初始化操作,將借閱信息等從文件中讀取出來,放入容器中,便于操作,不用一直對文件進行I/O.
CBook.h用于對書抽象,并實現(xiàn)了的重載,便于文件讀入,讀出
CUser.h工具人,作為老師,學(xué)生的父類
CStudent.h對學(xué)生進行的抽象
CTeacher.h對老師進行的抽象
CAdministrator.h對管理的抽象
CManagementBooks.h用戶所有的相關(guān)操作的中間執(zhí)行者,有設(shè)計模式中代理的思想
源.cpp界面的的實現(xiàn)與系統(tǒng)入口
說明:代碼100%完整,如果大家不想CV,也可以私聊我發(fā)你完整代碼,還有就是文件讀入建議大家都直接放在相應(yīng)項目里面,不然就寫絕對路徑。有問題歡迎大家在評論區(qū)提問,喜歡就點個贊咯!
全部代碼與講解:
1.源.cpp
#includeiostream
#include"CBook.h"
#include"CStudent.h"
#include"CManagementBooks.h"
#include"CTeacher.h"
#includefstream
#include"CAdministrator.h"
#include"COperationManagement.h"
usingnamespacestd;
intmain()
CManagementBooksmb;
CUser*user=nullptr;
COperationManagementom;
om.init(mb);
cout"*****歡迎來到圖書館*****"endl;
cout"注意事項"endl;
cout"1.學(xué)生最多共可借三本書,老師最多共可借五本"endlendl;
cout"請選擇您的登錄方式1:老師2:學(xué)生3:管理員"endl;
intt;
cint;
if(t==1)
user=newCTeacher;
elseif(t==2)
user=newCStudent;
elseif(t==3)
CAdministratoradmin;
om.adminLogin(admin);
admin.showInfo();
om.adminOperation(admin,mb);
return0;
cout"您是否已有賬號?(y/n):"endl;
stringc;
cinc;
if(c=="y")
cout"請登錄:"endl;
om.login(user,t);
user-showInfo();
else
cout"來注冊一個吧!"endl;
om.Register(user,t);
om.userOperation(user,mb);
deleteuser;
return0;
}
實現(xiàn)效果:
2.COperationManagement.cpp
#include"COperationManagement.h"
voidCOperationManagement::login(CUser*user,intt)
ifstreamreadFile;
ifstreamreadFile1;
if(t==1)
readFile.open("teacherLogin.txt");
readFile1.open("teacher.txt");
else
readFile1.open("student.txt");
readFile.open("studentLogin.txt");
if(!readFile.is_open())
cout"登錄數(shù)據(jù)讀取錯誤"endl;
if(!readFile1.is_open())
cout"用戶數(shù)據(jù)讀取錯誤"endl;
cout"請輸入您的學(xué)工號:"endl;
stringaccount,password;
cinaccount;
intflag=0;
while(!readFile.eof())
stringact;
readFileact;
if(act==account)
cout"請輸入密碼:"endl;
cinpassword;
stringpwd;
readFilepwd;
if(pwd==password)
cout"登錄成功"endl;
flag=1;
while(!readFile1.eof())
readFile1user;
if(user-getId()==act)
break;
break;
else
cout"密碼錯誤,請重新登錄"endl;
login(user,t);
if(!flag)
cout"學(xué)工號錯誤,請重輸入"endl;
login(user,t);
readFile.close();
readFile1.close();
voidCOperationManagement::Register(CUser*user,intt)
ofstreamwriteFile;
ofstreamwriteFile1;
if(t==1)
writeFile1.open("teacher.txt",ios::app);
writeFile.open("teacherLogin.txt",ios::app);
else
writeFile1.open("student.txt",ios::app);
writeFile.open("studentLogin.txt",ios::app);
stringpwd,act;
cout"請輸入您的學(xué)工號作為注冊賬號:"endl;
cinact;
cout"請輸入您的注冊密碼:"endl;
cinpwd;
writeFileendlact""pwd;
cout"請完善您的相應(yīng)信息:"endl;
stringname,department,gender;
cout"您的姓名:"endl;
cinname;
cout"您的性別:"endl;
cingender;
cout"您所在的院系:"endl;
cindepartment;
writeFile1endlact""name""gender""department;//這里不能用user,因為在登錄時才用,并且并沒有初始化
writeFile.close();
writeFile1.close();
cout"注冊成功!趕緊登錄進入圖書管吧!"endl;
login(user,t);
voidCOperationManagement::userOperation(CUser*user,CManagementBooksmb)
while(1)
cout"請選擇您的操作1.借書2.查看自己當(dāng)前借書情況3.還書4.退出"endl;
intt;
cint;
if(t==1)
cout"當(dāng)前圖書館情況如下:"endl;
mb.showCurrentAllBook();
cout"是否有您想要借閱的圖書(y/n)"endl;
strings;
cins;
if(s=="y")
user-borrowBookFromLibrary(mb);
elseif(t==2)
mb.checkBorrowedBook(user-getId());
elseif(t==3)
user-returnBook(mb);
elseif(t==4)
cout"退出成功"endl;
break;
else
cout"暫無此操作,請按提示操作"endl;
voidCOperationManagement::adminLogin(CAdministratoradmin)
ifstreamreadFile("adminLogin.txt");
ifstreamreadFile1("admin.txt");
cout"請輸入您的工號:"endl;
stringaccount,password;
cinaccount;
intflag=0;
while(!readFile.eof())
stringact;
readFileact;
if(act==account)
cout"請輸入密碼:"endl;
cinpassword;
stringpwd;
readFilepwd;
if(pwd==password)
cout"登錄成功,歡迎您"endl;
flag=1;
while(!readFile1.eof())
readFile1admin;
if(admin.getId()==act)
break;
break;
else
cout"密碼錯誤,請重新登錄"endl;
adminLogin(admin);
if(!flag)
cout"學(xué)工號錯誤,請重輸入"endl;
adminLogin(admin);
readFile.close();
readFile1.close();
voidCOperationManagement::init(CManagementBooksmb)
mb.initBooks();
mb.initOutBook();
voidCOperationManagement::adminOperation(CAdministratoradmin,CManagementBooksmb)
while(1)
cout"請選擇您的操作1.增加書2.查看當(dāng)前借閱情況3.查看當(dāng)前所有圖書信息情況4.查看借閱人詳細(xì)信息5.退出"endl;
intt;
cint;
if(t==1)
admin.addBook(mb);
elseif(t==2)
mb.checekOutBook();
elseif(t==3)
mb.showAllBooksInfo();
elseif(t==4)
stringid;
cout"請輸入您要查看借閱人的學(xué)工號:"endl;
cinid;
mb.viewBorrowerDetails(id);
elseif(t==5)
cout"退出成功"endl;
break;
else
cout"暫無此操作,請按提示操作"endl;
}
登錄效果:
其余功能大家可以自行測試。
CUser.cpp
#include"CUser.h"
#includeiostream
#includefstream
#include"CManagementBooks.h"
usingnamespacestd;
CUser::CUser()
m_name="陳1";
voidCUser::setId(stringid)
m_id=id;
voidCUser::setName(stringname)
m_name=name;
voidCUser::setGender(stringgender)
m_gender=gender;
voidCUser::setDepartment(stringdepartment)
m_department=department;
CUser::~CUser()
voidCUser::returnBook(CManagementBooksmb)
intall=mb.checkBorrowedBook(m_id);
if(all==0)
cout"您暫未借書,無需歸還"endl;
else
cout"請輸入您要歸還的書名:"endl;
stringbookName;
cinbookName;
if(mb.checkTrueBorrow(m_id,bookName))
mb.Return(m_id,bookName);
cout"還書成功"endl;
else
cout"您并未借閱此書"endl;
stringCUser::getId()
returnm_id;
stringCUser::getName()
returnm_name;
stringCUser::getGender()
returnm_gender;
stringCUser::getDepartment()
returnm_department;
std::ostreamoperator(std::ostreamos,constCUser*user)
osendluser-m_id""user-m_name""user-m_gender""user-m_department;
returnos;
std::istreamoperator(std::istreamis,CUser*user)
isuser-m_iduser-m_nameuser-m_genderuser-m_department;
returnis;
}
CTeacher.cpp
#include"CTeacher.h"
#includefstream
CTeacher::CTeacher()
m_name="劉X";
voidCTeacher::borrowBookFromLibrary(CManagementBooksmb)
intall=mb.checkBorrowedBook(m_id);
if(all5)
stringname;
cout"請輸入您要借的書名:"endl;
cinname;
if(mb.borrow(name))
ofstreamwriteFile("borrowedBook.txt",ios::app);
mb.setMapValue(m_id,name);
writeFileendlm_id""name;
writeFile.close();
else
cout"您已經(jīng)超過了最大可借閱數(shù)"endl;
voidCTeacher::showInfo()
cout"姓名:"m_name"""學(xué)號:"m_id"""性別:"m_gender"""院系:"m_departmentendl;
}
CStudent.cpp
#include"CStudent.h"
#includefstream
usingnamespacestd;
CStudent::CStudent()
m_class="軟件";
voidCStudent::showInfo()
cout"姓名:"m_name"""學(xué)號:"m_id"""性別:"m_gender"""院系:"m_department"""班級:"m_classendl;
voidCStudent::borrowBookFromLibrary(CManagementBooksmb)
intall=mb.checkBorrowedBook(m_id);
if(all3)
stringname;
cout"請輸入您要借的書名:"endl;
cinname;
if(mb.borrow(name))
ofstreamwriteFile("borrowedBook.txt",ios::app);
mb.setMapValue(m_id,name);
writeFileendlm_id""name;
writeFile.close();
else
cout"您已經(jīng)超過了最大可借閱數(shù)"endl;
voidCStudent::setClass(stringClass)
m_class=Class;
stringCStudent::getClass()
returnm_class;
}
CManagementBooks.cpp
#include"CManagementBooks.h"
usingnamespacestd;
voidCManagementBooks::showCurrentAllBook()
for(inti=0;im_allBookNum;i++)
cout"書名:"m_books[i].getName()"""剩余數(shù)量"m_books[i].getNum()endl;
CManagementBooks::CManagementBooks()
m_allBookNum=0;
voidCManagementBooks::addBook(CBookbook)
intflag=0;
for(inti=0;im_allBookNum;i++)
if(m_books[i].getName()==book.getName())
flag=1;
m_books[i].setNum(m_books[i].getNum()+book.getNum());
ofstreamwriteFile("library.txt",ios::out);
for(inti=0;im_allBookNum;i++)
writeFilem_books[i];
writeFile.close();
break;
if(!flag)
ofstreamwriteFile("library.txt",ios::app);
m_books.push_back(book);
m_allBookNum++;
writeFilebook;
writeFile.close();
intCManagementBooks::getAllBookNum()
returnm_allBookNum;
voidCManagementBooks::showAllBooksInfo()
for(inti=0;im_allBookNum;i++)
m_books[i].showInfo();
boolCManagementBooks::borrow(stringname)
for(inti=0;im_allBookNum;i++)
if(m_books[i].getName()==name)
if(m_books[i].getNum()=1)
m_books[i].setNum(m_books[i].getNum()-1);
cout"借書成功"endl;
ofstreamwriteFile("library.txt");
for(inti=0;im_allBookNum;i++)
writeFilem_books[i];
writeFile.close();
returntrue;
else
cout"此書數(shù)量不足"endl;
returnfalse;
cout"很抱歉,暫無此書"endl;
returnfalse;
voidCManagementBooks::Return(stringid,stringbookName)
CBookbook;
book.setName(bookName);
addBook(book);
ofstreamwriteFile("borrowedBook.txt",ios::out);
for(autoiter=m_outBookMap.begin();iter!=m_outBookMap.end();++iter)
if(iter-first==iditer-second==bookName)
m_outBookMap.erase(iter);
break;
for(automap:m_outBookMap)
writeFileendlmap.first""map.second;
writeFile.close();
voidCManagementBooks::initOutBook()
ifstreamreadFile("borrowedBook.txt");
if(!readFile.is_open())
cout"查看全體借書情況數(shù)據(jù)讀取出錯"endl;
else
while(!readFile.eof())
stringstudentId,bookName;
readFilestudentIdbookName;
m_outBookMap.insert(pairstring,string(studentId,bookName));
readFile.close();
voidCManagementBooks::checekOutBook()
for(automap:m_outBookMap)
cout"借閱人學(xué)工號:"map.first"""借閱書名:"map.secondendl;
voidCManagementBooks::initBooks()
ifstreamreadFile;
readFile.open("library.txt");
if(!readFile.is_open())
cout"圖書數(shù)據(jù)讀取錯誤"endl;
readFile.close();
return;
while(!readFile.eof())
CBookbook;
readFilebook;
m_allBookNum++;
m_books.push_back(book);
readFile.close();
intCManagementBooks::checkBorrowedBook(stringuserId)
intflag=0;
for(automap:m_outBookMap)
if(userId==map.first)
if(!flag)
cout"您已經(jīng)借的全部圖書如下:"endl;
flag++;
else
flag++;
coutmap.second"";
if(!flag)
cout"您目前沒有借書"endl;
cout"共:"flag"本";
coutendl;
returnflag;
voidCManagementBooks::viewBorrowerDetails(stringid)
ifstreamreadFile("teacher.txt");
ifstreamreadFile1("student.txt");
intflag=0;
if(!readFile1.is_open()||!readFile.is_open())
cout"用戶數(shù)據(jù)讀取錯誤"endl;
while(!readFile1.eof())
stringact1,name,department,gender;
readFile1act1namegenderdepartment;
if(id==act1)
cout"用戶類別:""學(xué)生""""用戶姓名:"name"""用戶性別:"gender"""用戶所在部門:"departmentendl;
flag=1;
if(!flag)
while(!readFile.eof())
stringact1,name,department,gender;
readFileact1namegenderdepartment;
if(id==act1)
flag=1;
cout"用戶類別:""老師""""用戶姓名:"name"""用戶性別:"gender"""用戶所在部門:"departmentendl;
if(!flag)
cout"無此用戶!"endl;
readFile.close();
readFile1.close();
boolCManagementBooks::checkTrueBorrow(stringid,stringbookName)
for(automap:m_outBookMap)
if(map.first==idmap.second==bookName)
returntrue;
returnfalse;
voidCManagementBooks::setMapValue(stringuserId,stringbookName)
m_outBookMap.insert(pairstring,string(userId,bookName));
}
CBook.cpp
#include"CBook.h"
#includeiostream
#includefstream
usingnamespacestd;
CBook::CBook()
stringb="";
stringrandStr="0123456789X";
for(inti=0;i=12;i++)
if(i==1||i==5||i==11)
b+='-';
else
if(i==12)
b+=randStr[rand()%11];
else
b+=randStr[rand()%10];
m_num=1;
m_name="等待戈多";
m_author="李XX";
m_isbn=b;
m_page=rand();
m_pressInfo="XX出版社";
m_price=rand();
voidCBook::setNum(intnum)
m_num=num;
intCBook::getNum()
returnm_num;
voidCBook::setName(stringname)
m_name=name;
stringCBook::getName()
returnm_name;
voidCBook::setIsbn(stringisbn)
m_isbn=isbn;
stringCBook::getIsbn()
returnm_isbn;
voidCBook::setPressInfo(stringperssInfo)
m_pressInfo=perssInfo;
stringCBook::getPressInfo()
returnm_pressInfo;
voidCBook::setPrice(doubleprice)
m_price=price;
doubleCBook::getPrice()
returnm_price;
voidCBook::setPage(intpage)
m_page=page;
intCBook::getPage()
returnm_page;
voidCBook::setAuthor(stringauthor)
m_author=author;
stringCBook::getAuthor()
returnm_author;
voidCBook::checkIsnb()
intsum=0;
for(inti=0,j=1;im_isbn.size();i++){
if(m_isbn[i]!='-'i!=12){
sum+=(m_isbn[i]-'0')*j;
j++;
sum%=11;
charc='X';
if(sum10)c=sum+'0';
if(m_isbn[12]==c)puts("ThisbookisbnareRight!");
elseputs("Thisbookisbnarewrong!");
boolCBook::isBorrowed()
if(m_num=1)
m_num--;
returntrue;
returnfalse;
voidCBook::showInfo()
cout"作者:"m_author"""isbn號碼:"m_isbn"""書本名稱:"m_name""
"總頁數(shù):"m_page"""出版社:"m_pressInfo"""價格:"m_price
"""剩余本數(shù):"m_numendl;
std::ostreamoperator(std::ostreamos,constCBookbook)
osendlbook.m_name""book.m_isbn""book.m_pressInfo""book.m_price""book.m_page""bo
溫馨提示
- 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)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 專業(yè)角度解讀醫(yī)療行業(yè)中的防騙和評估體系
- 醫(yī)療大數(shù)據(jù)的匿名化處理與隱私保護策略
- 醫(yī)療機器人輔助治療的倫理問題及應(yīng)對策略研究
- 石油個人實習(xí)總結(jié)模版
- 區(qū)塊鏈與供應(yīng)鏈金融深度融合的機遇與挑戰(zhàn)
- 從數(shù)據(jù)共享到智能決策-解析區(qū)塊鏈在金融領(lǐng)域的應(yīng)用與價值
- 醫(yī)療器械生產(chǎn)企業(yè)的內(nèi)部質(zhì)量審核與改進策略
- 創(chuàng)新技術(shù)助力打造可靠的醫(yī)療數(shù)據(jù)安全防護體系
- 專利代工合同范例
- 信貸詐騙合同范例
- 2024年宿遷市融媒體中心招聘考試真題
- 《業(yè)績分析報告實例》課件
- 統(tǒng)編版(2024)七年級下冊道德與法治期中測試卷(含答案)
- 財務(wù)會計考試試題及答案
- 架橋機安拆安全監(jiān)理細(xì)則
- 部編版八年級歷史下冊-第16課 獨立自主的和平外交(教學(xué)設(shè)計4)
- 7.1 自由平等的真諦 課件- 2024-2025學(xué)年八年級道德與法治下冊 統(tǒng)編版
- 2025年內(nèi)蒙古中煤蒙大新能源化工有限公司招聘筆試參考題庫附帶答案詳解
- 插畫版權(quán)授權(quán)協(xié)議書
- 安裝鋼結(jié)構(gòu)平臺合同協(xié)議
- 地理西亞+課件-2024-2025學(xué)年七年級地理下冊人教版
評論
0/150
提交評論