




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、精選優(yōu)質(zhì)文檔-傾情為你奉上程序設(shè)計報告( 2014 / 2015 學(xué)年 第 1 學(xué)期)題 目:南郵圖書館管理系統(tǒng) 專 業(yè) 組長 學(xué)號姓名 組員 學(xué)號姓名 指 導(dǎo) 教 師 指 導(dǎo) 單 位 日 期 成員分工組長()負(fù)責(zé)圖書的所有相關(guān)信息內(nèi)容存為文件部分代碼編寫。并使界面友好,輸入信息符合邏輯。組員()負(fù)責(zé)顯示所有即將到期的圖書(歸還日期在三天之內(nèi));按借閱次數(shù)對所有圖書進(jìn)行排序部分代碼編寫組員()負(fù)責(zé)圖書館管理系統(tǒng)所擁有功能的定義。評分細(xì)則評分項優(yōu)秀良好中等差遵守機(jī)房規(guī)章制度上機(jī)時的表現(xiàn)學(xué)習(xí)態(tài)度程序準(zhǔn)備情況程序設(shè)計能力團(tuán)隊合作精神課題功能實現(xiàn)情況算法設(shè)計合理性用戶界面設(shè)計報告書寫認(rèn)真程度內(nèi)容詳實程
2、度文字表達(dá)熟練程度回答問題準(zhǔn)確度簡短評語 教師簽名: 年 月 日評分等級 備注評分等級共五種:優(yōu)秀、良好、中等、及格、不及格題目:南郵圖書管理系統(tǒng)一、 課題內(nèi)容和要求該系統(tǒng)要求建立一個南郵圖書館管理系統(tǒng),并具有排序、查找、計算、顯示等功能。通過此課題,熟練掌握文件、數(shù)組、指針的各種操作,以及一些算法思想的應(yīng)用。(1)圖書的信息應(yīng)包括:索引號,名稱,館藏地址(三牌樓、仙林)、類別(人文、科技、外語等),數(shù)量,價格,入庫日期,歸還日期,借閱次數(shù),借閱狀態(tài)(可借、不可借)。(2)需要實現(xiàn)的功能1) 對已圖書信息進(jìn)行更新操作,包括添加和刪除一種書的信息、修改圖書信息(例如圖書被借閱,書的數(shù)目減1,借閱
3、次數(shù)加1,如果數(shù)量為0則狀態(tài)為不可借);2)通過按圖書的名稱查詢圖書信息;3)顯示所有即將到期的圖書(歸還日期在三天之內(nèi));4)按借閱次數(shù)對所有圖書進(jìn)行排序;5)將圖書的所有相關(guān)信息內(nèi)容存為文件。(3)界面友好,輸入信息符合邏輯。 二、 需求分析在整個系統(tǒng)中一共主要有三個部分:圖書借閱、圖書管理和圖書搜索。其中圖書借閱包含借出時間、歸還時間、是否歸還(1) 可根據(jù)ID賬號找到某本書的索引值,從而獲取圖書信息,進(jìn)行借閱,系統(tǒng)將自動添加可借閱時間,并將信息記錄(2) 可分頁顯示借書記錄,借閱信息(3) 分頁顯示即將到期的圖書圖書管理部分包含圖書列表,添加書,刪除圖書信息(1) 將所有圖書進(jìn)行排序,
4、入庫,并記錄圖書信息(2) 添加一本書,刪除圖書信息(可刪除一本或者刪除全部索引值為一個的全部圖書信息)(3) 修改圖書信息,可根據(jù)索引值找到圖書并進(jìn)行修改(4) 分頁顯示所有圖書列表搜索圖書(1) 可用索引值搜索書本信息,以以及圖書在數(shù)組中的位置(2) 也可根據(jù)圖書名搜索圖書所在數(shù)組位置,返回圖書信息3、 概要設(shè)計 1) 主要結(jié)構(gòu)體:在library這整個類中,由mainscreen()這個函數(shù)進(jìn)入brrowbook()、bookmager()、searchbook()這三個函數(shù)分別提供借書、管理圖書、搜索圖書三種功能在借書功能包含借書與還書,而管理圖書中則包含添加、刪除、修改、查看等功能。
5、 而在本程序中每一本書都賦予了對應(yīng)的ID和索引值,而ID是唯一的,當(dāng)添加成功時,系統(tǒng)會自動添加入庫時間,每個singlebook結(jié)構(gòu)體都用來存儲圖書的基本信息以及相應(yīng)的入庫時間,而borrowtable則存儲圖書借閱的信息。booklist則用來存儲所有圖書的信息。而圖書的存儲信息頁按照要求存儲在相應(yīng)的文件dat中。主程序2)主要函數(shù)流程圖: 圖書管理搜索圖書圖書借閱搜索圖書信息刪除圖書查看所有圖書修改圖書信息添加圖書歸還借閱圖1程序流程圖圖書借閱選擇用戶進(jìn)入選擇借書 輸入圖書ID圖書名稱是否借閱是否可借閱是否余量不足禁止借閱余量不足結(jié) 束借閱完成借閱圖書 圖2歸還圖書 歸還圖書輸入IDgiv
6、eBackResult=booklist.giveBackBook(singlebook.getSuoyin(id)giveBackResult!=0?Borrowtable.giveback(id)還書時出現(xiàn)錯誤還 書 成功結(jié) 束 圖3添加圖書 添 加 圖 書輸入索引SY和IDsearchBookPosWithSY=-1t.ID=allBooks;data.push_back(t);allBooks+;數(shù) 目Count+=1結(jié) 束書名=booklist.bookinfo(sy).name圖4刪除圖書刪 除 圖 書單本OR多本輸入ID得到圖書索引刪除圖書信息輸入索引值刪除所有索引值為SY的圖書
7、結(jié) 束 圖5修改圖書修 改 圖 書輸入書的索引SYBooklist.searchBookPosWithSY(sy)!=-1顯示索引值為SY的圖書信息修改?修改圖書信息沒有此書結(jié) 束圖6四、源程序代碼 #include <iostream>#include <vector>#include <ctime>/(把日期和時間轉(zhuǎn)換成字符串該類的對象表示的時間是基于格林威治標(biāo)準(zhǔn)時間的)#include <cstdlib>/(常用的函數(shù)庫)#include <fstream>#include <sstream>#include <
8、;algorithm>/(演算法,提供了大量基于迭代器的非成員模板函數(shù))using namespace std;int min(int a,int b)if (a<b)return a;return b;struct data_booklist int ID; /書本ID string Suoyin; /書本索引 (string類是字符串,不可任意改變,需要返回一個新的string類對象) string Name; /書本名稱 int Address; /書本地址 string BookClass; /書本類別 int Count; /數(shù)目 int Price; /價格 bool
9、BorrowAble; /是否允許借閱 int BorrowedCount;/借閱次數(shù);int cmpBorrowedCount(data_booklist a,data_booklist b);int cmpID(data_booklist a,data_booklist b);/(給排序函數(shù)sort提供比較大小的方法)class BOOKLISTprivate: vector<data_booklist> data; int allBooks;public: BOOKLIST(); /BOOKLIST(); int searchBookPosWithSY(string sy);
10、/根據(jù)索引查找書在數(shù)組中的位置 data_booklist bookInfo(string sy);/根據(jù)索引查找書本信息 void addNewBook(data_booklist t); /添加新書 void removeAllBook(string sy);/刪除所有索引為sy的書 int searchBookPosWithName(string name);/根據(jù)圖書名搜索書在數(shù)組中的位置 data_booklist searchBookWithName(string name);/根據(jù)圖書名返回書的信息 void updateBookInfo(string sy,data_bookl
11、ist t);/更改索引為 sy的圖書信息 int borrowBook(string sy);/借書時對表的修改,返回0表示借閱成功,1數(shù)量不足,2禁止借閱 int giveBackBook(string sy);/還書時對表的修改 void sortBooks(int option);/對圖書排序 0=按借閱次數(shù) 1=按ID void save();/保存 void removeOneBook(string sy);/刪除一本索引為sy的書 void showBooks(int page);/分頁顯示書本信息;int cmpBorrowedCount(data_booklist a,dat
12、a_booklist b) if (a.BorrowedCount>b.BorrowedCount) return 1; return 0;int cmpID(data_booklist a,data_booklist b) if (a.ID>b.ID) return 0; return 1;BOOKLIST:BOOKLIST() ifstream booklistFile("booklist.dat");/嘗試從文件加載數(shù)據(jù) if (booklistFile) booklistFile>>allBooks; for (int i = 0; i &l
13、t; allBooks; +i) data_booklist p; booklistFile>>p.ID; booklistFile>>p.Suoyin; booklistFile>>p.Name; booklistFile>>p.Address; booklistFile>>p.BookClass; booklistFile>>p.Count; booklistFile>>p.Price; booklistFile>>p.BorrowAble; booklistFile>>p.Borr
14、owedCount; data.push_back(p); booklistFile.close(); else allBooks = 0; int BOOKLIST:searchBookPosWithSY(string sy) for (int i = 0;i < allBooks; +i) if (datai.Suoyin=sy) return i; return -1;data_booklist BOOKLIST:bookInfo(string sy) return datasearchBookPosWithSY(sy);void BOOKLIST:addNewBook(data_
15、booklist t) int pos = searchBookPosWithSY(t.Suoyin); if (pos=-1)/(-1是沒找到,pos是記錄的意思) t.ID=allBooks;data.push_back(t); allBooks+;else datapos.Count += 1; void BOOKLIST:removeAllBook(string sy) int pos = searchBookPosWithSY(sy); data.erase(data.begin()+pos);/(erase為刪除數(shù)據(jù),begin是date的開始) allBooks-;int BOO
16、KLIST:searchBookPosWithName(string name) for (int i = 0; i < allBooks; +i) if (datai.Name=name) return i; return -1;data_booklist BOOKLIST:searchBookWithName(string name) int p = searchBookPosWithName(name); if (p >= 0) return datap; else data_booklist t; t.Count = 0; t.Name = name; return t;
17、void BOOKLIST:updateBookInfo(string sy,data_booklist t) int p = searchBookPosWithSY(sy); if (p>=0) datap = t;int BOOKLIST:borrowBook(string sy) int p = searchBookPosWithSY(sy); if (p<0|datap.Count=0) return 1; if (datap.BorrowAble) datap.Count-; datap.BorrowedCount+; return 0; else return 2; i
18、nt BOOKLIST:giveBackBook(string sy) int p = searchBookPosWithSY(sy); if (p>=0) datap.Count+; return 0; return 1;void BOOKLIST:sortBooks(int option) if (option=0) sort(data.begin(),data.begin()+allBooks,cmpBorrowedCount);/(sort是排序函數(shù)) else sort(data.begin(),data.begin()+allBooks,cmpID);void BOOKLIS
19、T:save() ofstream booklistFile("booklist.dat");/(這是一個booklist的文件所以輸出時也要與文件相關(guān)用booklistfile) booklistFile<<allBooks<<endl; for (int i = 0; i < allBooks; +i) booklistFile<<datai.ID<<endl; booklistFile<<datai.Suoyin<<endl; booklistFile<<datai.Name&l
20、t;<endl; booklistFile<<datai.Address<<endl; booklistFile<<datai.BookClass<<endl; booklistFile<<datai.Count<<endl; booklistFile<<datai.Price<<endl; booklistFile<<datai.BorrowAble<<endl; booklistFile<<datai.BorrowedCount<<endl;
21、 booklistFile.close();void BOOKLIST:removeOneBook(string sy) int pos = searchBookPosWithSY(sy); if (pos>-1)/(pos 是便是記錄的位置-1表示沒找到) if (datapos.Count>0) datapos.Count-; void BOOKLIST:showBooks(int page) if (page<0) return ; int perPage = 15; cout<<"No.t索引t書名t地址t類別t數(shù)目t價格t可供借閱t借閱次數(shù)&q
22、uot;<<endl; if (page*perPage-allBooks<perPage) for (int i=(page-1)*perPage;i<min(page-1)*perPage+perPage,allBooks);i+)/(page是要顯示的數(shù)目perpage是每頁的顯示數(shù)目) cout<<datai.ID<<"t"<<datai.Suoyin<<"t"<<datai.Name<<"t"/(page*perpage 是表示第
23、某頁的起始) if (datai.Address=0) cout<<"三牌樓t" else cout<<"仙林t" cout<<datai.BookClass<<"t"<<datai.Count<<"t"<<datai.Price<<"t" if (datai.BorrowAble) cout<<"Yes" else cout<<"No"
24、 cout<<"tt"<<datai.BorrowedCount<<endl; struct data_singlebook/(struct是各種數(shù)據(jù)的結(jié)構(gòu)體) int ID; string Suoyin; time_t ruku;class SINGLEBOOKprivate: vector<data_singlebook> data;/(vector可以實現(xiàn)變成長的數(shù)組) int allBooks;public: SINGLEBOOK(); /SINGLEBOOK(); void addBook(int id,string
25、 sy,time_t t);/添加單本書 void removeBook(int id);/根據(jù)ID刪除一本書 void removeAllBook(string sy);/根據(jù)索引刪除所有書 void save();/保存 string getSuoyin(int id);/獲取指定ID的圖書的索引 void showBooks(int page);/分頁顯示圖書;SINGLEBOOK:SINGLEBOOK() ifstream singlebookFile("singlebook.dat");/嘗試從文件加載 if (singlebookFile) singlebook
26、File>>allBooks; for (int i=0;i<=allBooks;i+) data_singlebook p; singlebookFile>>p.ID; singlebookFile>>p.Suoyin; singlebookFile>>p.ruku; data.push_back(p); singlebookFile.close(); else allBooks = 0; void SINGLEBOOK:addBook(int id,string sy,time_t t)cout<<sy<<end
27、l;data_singlebook p; p.ID = id; p.Suoyin = sy; p.ruku = t; data.push_back(p); allBooks+;void SINGLEBOOK:removeBook(int id) int p; for (int i=0;i<allBooks;i+) if (datai.ID=id) p = i; data.erase(data.begin()+p); break; allBooks-;void SINGLEBOOK:removeAllBook(string sy) int p; for (int i=0;i<data
28、.size();i+) if (datai.Suoyin=sy) data.erase(data.begin()+i); i-; allBooks = data.size();void SINGLEBOOK:save() ofstream singlebookFile("singlebook.dat");/(單本書的文件) singlebookFile<<allBooks<<endl; for (int i=0;i<allBooks;i+) singlebookFile<<datai.ID<<endl; singlebo
29、okFile<<datai.Suoyin<<endl; singlebookFile<<datai.ruku<<endl; singlebookFile.close();string SINGLEBOOK:getSuoyin(int id) for (int i = 0; i < allBooks; +i) if(datai.ID=id) return datai.Suoyin; return "No Such Book"void SINGLEBOOK:showBooks(int page) system("c
30、ls"); cout<<"IDt索引t入庫n" int perPage = 15; for (int i=(page-1)*perPage;i<min(page-1)*perPage+perPage,allBooks);i+) cout<<datai.ID<<"t"<<datai.Suoyin<<"t" tm* t = localtime(&datai.ruku); int y = t->tm_year-100; int m = t->tm
31、_mon+1; int d = t->tm_mday; stringstream ss; ss<<t->tm_year-100<<"-"<<t->tm_mon+1<<"-"<<t->tm_mday; string sRuku = ss.str(); cout<<sRuku<<endl; struct data_borrowtable int id; time_t date;/借出時間 time_t guihuan;/歸還時間 bool giveba
32、ck;/是否歸還;class BORROWTABLEprivate: vector<data_borrowtable> data; int records;int allowDays;public: BORROWTABLE(); void save();/保存 void borrow(int id);/根據(jù)ID借書 ,系統(tǒng)自動添加時間 void giveback(int id);/還書 ,系統(tǒng)自動添加時間 void showEmergencyBooks(BOOKLIST &b,SINGLEBOOK &s);/顯示即將到期的書,從b和s中獲取圖書信息 void sho
33、wTable(int page,BOOKLIST &b,SINGLEBOOK &s);/分頁顯示借書記錄 string getName(int id,BOOKLIST &b,SINGLEBOOK &s);/獲取指定ID的圖書名 string getSY(int id,SINGLEBOOK &s);/獲取指定圖書的索引 void setAllowDays(int d);/設(shè)置允許借閱天數(shù) int getAllowDays();BORROWTABLE:BORROWTABLE() ifstream borrowTableFile("borrowTab
34、le.dat");/嘗試從文件加載數(shù)據(jù) if (borrowTableFile) borrowTableFile>>records; borrowTableFile>>allowDays; for (int i=0;i<records;i+) data_borrowtable p; borrowTableFile>>p.id; borrowTableFile>>p.date; borrowTableFile>>p.giveback; borrowTableFile>>p.guihuan; data.push
35、_back(p); borrowTableFile.close(); else records = 0; allowDays = 30; void BORROWTABLE:save() ofstream borrowTableFile("borrowTable.dat"); if (borrowTableFile) borrowTableFile<<records<<endl; borrowTableFile<<allowDays<<endl; for (int i=0;i<records;i+) borrowTable
36、File<<datai.id<<endl; borrowTableFile<<datai.date<<endl; borrowTableFile<<datai.giveback<<endl; borrowTableFile<<datai.guihuan<<endl; borrowTableFile.close(); void BORROWTABLE:borrow(int id)data_borrowtable p; p.giveback = false; p.id = id; p.date = ti
37、me(NULL); data.push_back(p); records+;void BORROWTABLE:giveback(int id) for (int i=0;i<records;i+) if (datai.id=id && datai.giveback=false) datai.giveback = true; datai.guihuan = time(NULL); return ; void BORROWTABLE:showEmergencyBooks(BOOKLIST &b,SINGLEBOOK &s) system("cls&q
38、uot;); time_t now = time(NULL); cout<<"即將到期圖書:"<<endl; cout<<"IDt"<<"書名t"<<"日期t"<<endl; for (int i=0;i<records;i+) if (now-datai.date>3600*24*(allowDays-3) tm* t = localtime(&datai.date); int y = t->tm_year-100;
39、 int m = t->tm_mon+1; int d = t->tm_mday; string givedBack; if (datai.giveback) givedBack = "Yes" else givedBack = "No" cout<<datai.id<<"t"<<b.bookInfo(s.getSuoyin(datai.id).Name<<"t"<<y<<"-"<<m<<
40、"-"<<d<<"t"<<givedBack<<endl; void BORROWTABLE:showTable(int page,BOOKLIST &b,SINGLEBOOK &s) system("cls"); cout<<"IDt"<<"書名t"<<"日期t歸還t"<<endl; int perPage = 15; if (page*perPage - rec
41、ords<perPage) for (int i=(page-1)*perPage;i<min(page-1)*perPage+perPage,records);i+) tm* t = localtime(&datai.date); int y = t->tm_year-100; int m = t->tm_mon+1; int d = t->tm_mday; string givedBack; if (datai.giveback) tm* q = localtime(&datai.guihuan); stringstream ss; ss<
42、;<q->tm_year-100<<"-"<<q->tm_mon+1<<"-"<<q->tm_mday; givedBack = ss.str(); else givedBack = "No" cout<<datai.id<<"t"<<b.bookInfo(s.getSuoyin(datai.id).Name<<"t"<<y<<"-"
43、<<m<<"-"<<d<<"t"<<givedBack<<endl; string BORROWTABLE:getName(int id,BOOKLIST &b,SINGLEBOOK &s) for (int i=0;i<records;i+) if (datai.id=id) data_booklist t = b.bookInfo(s.getSuoyin(datai.id); return t.Name; return "Not Found&quo
44、t;string BORROWTABLE:getSY(int id,SINGLEBOOK &s) return s.getSuoyin(id);void BORROWTABLE:setAllowDays(int d)allowDays = d;int BORROWTABLE:getAllowDays()return allowDays;class LIBRARYprivate: BOOKLIST booklist;/ 總圖書列表 SINGLEBOOK singlebook;/單獨(dú)的圖書信息 BORROWTABLE borrowtable;/圖書借閱記錄public: void main
45、screen();/功能選擇 void borrowbook();/借書 void bookmanaage();/圖書管理 void searchbook();/圖書搜索;void LIBRARY:mainscreen() int option; do system("cls"); cout<<" 1.管理借閱 "<<endl; cout<<" 2.管理書 "<<endl; cout<<" 3.搜索書 "<<endl; cout<<
46、" 4.退出 "<<endl; cout<<" "<<endl; cout<<" "<<endl; cout<<" "<<endl; cout<<" 請選擇 "<<endl; cout<<" "<<endl; cout<<" "<<endl; cout<<" "<&
47、lt;endl; cin>>option; switch(option) case 1:borrowbook();break; case 2:bookmanaage();break; case 3:searchbook();break; case 4:break; default:cout<<"請在1-3間選擇"<<endl; while (option!=4);void LIBRARY:borrowbook() int option; int page = 1; do system("cls"); cout<<"允許借閱天數(shù):"<<borrowtable.getAllowD
溫馨提示
- 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)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 課題申報項目書框架
- 聽力焦慮課題申報書
- 課題申報書審稿意見
- 上海班級管理課題申報書
- 課題申報書署名權(quán)
- 智能制造相關(guān)課題申報書
- 債務(wù)物品抵消合同范本
- 倉庫白酒購買合同范本
- 已申報課題的申報書
- 反滲透膜銷售合同范例
- JTG-3830-2018公路工程建設(shè)項目概算預(yù)算編制辦法
- 設(shè)備維護(hù)服務(wù)方案(2篇)
- GB/T 10781.4-2024白酒質(zhì)量要求第4部分:醬香型白酒
- 醫(yī)院檢驗科實驗室生物安全程序文件SOP
- 生物質(zhì)顆粒廠建設(shè)項目可行性研究報告
- 春新教科版四年級科學(xué)下冊《電路》單元解讀
- 《電力信息系統(tǒng)信息安全檢查規(guī)范》
- 三創(chuàng)賽獲獎-非遺文化創(chuàng)新創(chuàng)業(yè)計劃書
- 2024年4月時政熱點(diǎn)(一)
- 2023年考研數(shù)學(xué)一真題
- 2020年8月自考00371公安決策學(xué)試題及答案含解析
評論
0/150
提交評論