




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、高級語言程序設(shè)計課程設(shè)計報告設(shè)計題目圖書管理系統(tǒng)專業(yè)計算機(jī)科學(xué)與技術(shù)班級姓名學(xué)號2007年6月5日目錄1. 設(shè)計目標(biāo)32. 設(shè)計思想33. 類及對象設(shè)計44. 程序源代碼55. 調(diào)試記錄166.總結(jié)18共19頁2頁2圖書管理系統(tǒng)1設(shè)計目標(biāo)設(shè)計一個小型的圖書管理系統(tǒng),用鏈表來存儲讀者的基本信息(包括姓名、讀者編號、讀者借書情況等) ,完成借書、還書、圖書維護(hù)、讀者維護(hù)、離開等功能。2設(shè)計思想( 1)設(shè)計 class Reader 讀者信息庫,實現(xiàn)對讀者信息的描敘; class RDatabase讀者類庫實現(xiàn)建立讀者的個人資料;class Book圖書類,實現(xiàn)對圖書的描述,圖書的編號,書名,借出,
2、還入等;classBDatabase 圖書庫類,實現(xiàn)對圖書的維護(hù),查找,刪除等。以下是函數(shù)功能表:函數(shù)功能char *getname()獲取姓名int gettag()獲取刪除標(biāo)記int getno()獲取讀者編號void setname(char na)設(shè)置姓名以及編號void addreader(int n,char *na)增加讀者void delbook()設(shè)置刪除標(biāo)記void borrowbook(int bookid)借書操作int retbook(int bookid)還書操作void disp()讀出讀者信息BDatabase()構(gòu)造函數(shù),將 book.txt 讀到 book
3、中int addbook(int n,char *na)增加圖書Book *query(int bookid)查找圖書void bookdata()圖書庫維護(hù)BDatabase()析構(gòu)函數(shù),將 book 寫到 book.txt 文件共19頁3頁3( 2)用類的成員函數(shù)對鏈表的數(shù)據(jù)進(jìn)行操作,其功能如上表所列。( 3)設(shè)計菜單來實現(xiàn)功能設(shè)計1、借書2、還書3、圖書維護(hù)4、讀者維護(hù)0、離開3設(shè)計類及對象(1)本程序定義了三個類,定義如下:class Readerprivate:char *getname() return name; /獲取姓名int gettag() return tag; /獲取
4、刪除標(biāo)記int getno() return no; /獲取讀者編號void setname(char na) /設(shè)置姓名void delbook() tag=1; /設(shè)置刪除標(biāo)記 1: 已刪 0: 未刪void addreader(int n,char *na)/增加讀者int retbook(int bookid)/還書操作void disp()/讀出讀者信息;class RDatabaseprivate:int top; /讀者記錄指針Reader readMaxr;/讀者記錄public:RDatabase() / 構(gòu)造函數(shù),將 reader.txt 讀到 read 中 void cl
5、ear()/ 刪除所有讀者信息int addreader(int n,char *na)/添加讀者時先查找是否存在Reader *query(int readerid)/按編號查找void disp() /輸出所有讀者信息void readerdata();/讀者庫維護(hù)RDatabase() /析構(gòu)函數(shù),將read 寫到 reader.txt文件中;class Bookprivate:char *getname() return name; /獲取姓名int getno() return no; /獲取圖書編號int gettag() return tag; /獲取刪除標(biāo)記共19頁4頁4voi
6、d setname(char na)/設(shè)置書名void delbook() tag=1;/刪除圖書void addbook(int n,char *na)/增加圖書int borrowbook()/借書操作void retbook()/還書操作void disp()/輸出圖書class BDatabaseprivate:BDatabase()/構(gòu)造函數(shù),將book.txt讀到 book 中void clear()/全刪int addbook(int n,char *na)/增加圖書Book *query(int bookid)/查找圖書void bookdata();/圖書庫維護(hù)BDataba
7、se()/析構(gòu)函數(shù),將 book 寫到 book.txt文件中 ;( 2 )分 別利 用類 class Reader 、 class RDatabase、 class Book 、 class BDatabase 定義了各自的對象 Book bookMaxb 、 RDatabase ReaderDB; Reader *r; BDatabase BookDB; Book *b; 對其函數(shù)進(jìn)行調(diào)用實現(xiàn)各種功能。( 3)主函數(shù)實現(xiàn),調(diào)用各種函數(shù)。4程序源代碼#include <iostream>#include <iomanip>#include <string>
8、#include <fstream>/輸入 / 輸出文件流類using namespace std;const int Maxr=100;/最多的讀者const int Maxb=100;/最多的圖書const int Maxbor=5;/每位讀者最多借五本書/ 讀者類 , 實現(xiàn)對讀者的信息的描述class Readerprivate:int tag; /刪除標(biāo)記 1: 已刪 0: 未刪int no; /讀者編號char name10; /讀者姓名int borbookMaxbor;/所借圖書public:Reader() char *getname() return name;
9、/獲取姓名int gettag() return tag; /獲取刪除標(biāo)記共19頁5頁5int getno() return no; /獲取讀者編號void setname(char na) /設(shè)置姓名strcpy(name,na);void delbook() tag=1; /設(shè)置刪除標(biāo)記 1: 已刪 0: 未刪void addreader(int n,char *na)/增加讀者tag=0;no=n;strcpy(name,na);for(int i=0;i<Maxbor;i+)borbooki=0;void borrowbook(int bookid)/借書操作for(int i=
10、0;i<Maxbor;i+)if (borbooki=0)borbooki=bookid;return;int retbook(int bookid)/還書操作for(int i=0;i<Maxbor;i+)if(borbooki=bookid)borbooki=0;return 1;return 0;void disp()/讀出讀者信息cout << setw(5) << no <<setw(10) << name<<"借書編號: "共19頁6頁6for(int i=0;i<Maxbor;i+)
11、if(borbooki!=0)cout << borbooki << "|"cout << ""<<endl;/ 讀者類庫,實現(xiàn)建立讀者的個人資料 class RDatabaseprivate:int top; /讀者記錄指針Reader readMaxr;/讀者記錄public:RDatabase() /構(gòu)造函數(shù),將 reader.txt讀到 read 中Reader s;top=-1;fstream file("reader.txt",ios:in);/打開一個輸入文件while (
12、1)file.read(char *)&s,sizeof(s);if (!file)break;top+;readtop=s;file.close(); /關(guān)閉 reader.txtvoid clear()/刪除所有讀者信息top=-1;int addreader(int n,char *na)/添加讀者時先查找是否存在Reader *p=query(n);if (p=NULL)top+;readtop.addreader(n,na);return 1;共19頁7頁7return 0;Reader *query(int readerid)/按編號查找for (int i=0;i<
13、=top;i+)if (readi.getno()=readerid &&readi.gettag()=0)return &readi;return NULL;void disp() /輸出所有讀者信息for (int i=0;i<=top;i+)readi.disp();void readerdata();/讀者庫維護(hù)RDatabase() /析構(gòu)函數(shù),將 read 寫到 reader.txt文件中fstream file("reader.txt",ios:out);for (int i=0;i<=top;i+)if (readi.ge
14、ttag()=0)file.write(char *)&readi,sizeof(readi);file.close();void RDatabase:readerdata()char choice;char rname20;int readerid;Reader *r;while (choice!='0')cout <<"nnttt讀 者 維 護(hù)nnntt1 新 增nntt2 更改 nntt3 刪 除nntt4 查 找nntt5 顯 示 nntt6 全 刪nntt0 退出"<<endl;cin >> choice
15、;switch (choice)共19頁8頁8case '1':cout << "輸入讀者編號 :"cin >> readerid;cout << "輸入讀者姓名 :"cin >> rname;addreader (readerid,rname);break;case '2':cout << "輸入讀者編號 :"cin >> readerid;r=query(readerid);if (r=NULL)cout << &q
16、uot;該讀者不存在 "<<endl;break;cout << "輸入新的姓名 :"cin >> rname;r->setname(rname);break;case '3':cout << "輸入讀者編號 :"cin >> readerid;r=query(readerid);if (r=NULL)cout <<"該讀者不存在 " << endl;break;r->delbook();break;case
17、39;4':cout << "讀入讀者編號 :"cin >> readerid;r=query(readerid);if (r=NULL)cout <<" 該讀者不存在 "<< endl;break;r->disp();break;case '5':disp();共19頁9頁9break;case '6':clear();break;default:cout<<"輸入錯誤,請從新輸入:"break;/ 圖書類,實現(xiàn)對圖書的描述,圖
18、書的編號,書名,借出,還入等 class Bookprivate:int tag;/刪除標(biāo)記 1: 已刪 0: 未刪int no;/圖書編號char name20;/書名int onshelf;/是否再架 1: 再架 2: 已借public:Book()char *getname() return name; /獲取姓名int getno() return no; /獲取圖書編號int gettag() return tag; /獲取刪除標(biāo)記void setname(char na)/設(shè)置書名strcpy(name,na);void delbook() tag=1;/刪除圖書void addb
19、ook(int n,char *na)/增加圖書tag=0;no=n;strcpy(name,na);onshelf=1;int borrowbook()/借書操作if (onshelf=1)onshelf=0;共 19頁 10頁10return 1;return 0;void retbook()/還書操作onshelf=1;void disp()/輸出圖書cout << setw(6) << no << setw(18) << name << setw(10)<<(onshelf=1? "在架 ":&
20、quot; 已借 ") <<endl;/ 圖書庫類,實現(xiàn)對圖書的維護(hù),查找,刪除等 class BDatabaseprivate:int top; /圖書記錄指針Book bookMaxb; /圖書記錄public:BDatabase()/構(gòu)造函數(shù),將 book.txt讀到 book 中Book b;top=-1;fstream file("book.txt",ios:in);while (1)file.read(char *)&b,sizeof(b);if (!file) break;top+;booktop=b;file.close();v
21、oid clear()/全刪top=-1;共 19頁 11頁11int addbook(int n,char *na)/增加圖書Book *p=query(n);if (NULL=p)top+;booktop.addbook(n,na);return 1;return 0;Book *query(int bookid)/查找圖書for (int i=0;i<=top;i+)if (booki.getno()=bookid &&booki.gettag()=0)return &booki;return NULL;void bookdata();/圖書庫維護(hù)void
22、disp()for (int i=0;i<=top;i+)if (booki.gettag()=0)booki.disp();BDatabase()/析構(gòu)函數(shù),將 book 寫到 book.txt文件中fstream file("book.txt",ios:out);for (int i=0;i<=top;i+)if (booki.gettag()=0)file.write(char *)&booki,sizeof(booki);file.close();void BDatabase:bookdata()char choice;char bname40;
23、int bookid;Book *b;while (choice!='0')共 19頁 12頁12cout <<"nnnttt圖 書 維 護(hù) "<<endl<<endl;cout<<"tt1新 增 n tt2更 改 ntt3刪 除 ntt4查 找 ntt5顯示 ntt6全 刪ntt0退 出 "<<endl;cin >> choice;switch (choice)case '1':cout << "輸入圖書編號 :"&l
24、t;<endl;cin >> bookid;cout << "輸入圖書書名 :"<<endl;cin >> bname;addbook(bookid,bname);break;case '2':cout << "輸入圖書編號 :"<<endl;cin >> bookid;b=query(bookid);if (b=NULL)cout << "該圖書不存在 "<<endl;break;cout <<
25、; "輸入新的書名 :"<<endl;cin >> bname;b->setname(bname);break;case '3':cout <<"讀入圖書編號 :"<<endl;cin >> bookid;b=query(bookid);if (b=NULL)cout <<"該圖書不存在 " << endl;break;b->delbook();break;case '4':cout << &qu
26、ot;讀入圖書編號 :"<<endl;cin >> bookid;b=query(bookid);if (b=NULL)共 19頁 13頁13cout <<"該圖書不存在 "<< endl;break;b->disp();break;case '5':disp();break;case '6':clear();break;default:cout<<"輸入錯誤,請從新輸入 :"/main()函數(shù)的實現(xiàn),程序的主界面的引導(dǎo)void main()cha
27、r choice;int bookid,readerid;RDatabase ReaderDB;Reader *r;BDatabase BookDB;Book *b;while(choice!='0')cout <<endl<<endl<<"ttt圖 書 管 理 系 統(tǒng)nnn"cout<<"ttt1借書 nnttt2還書nnttt3圖書維 護(hù)nnttt4讀 者 維 護(hù)nnttt0離 開 "<<endl;cin >> choice;switch (choice)case
28、 '1':cout <<"借書 讀者編號 :"cin >>readerid;cout <<"圖書編號: "cin >>bookid;r=ReaderDB.query(readerid);/按編號查找共 19頁 14頁14if (NULL=r)cout <<"不存在該讀者,不能借書"<< endl;break;b=BookDB.query(bookid);if (b=NULL)cout <<"不存在該圖書,不能借書"<< endl;break;if (b->borrowbook()=0)cout << "該圖書已借出,不能借書"<< endl;break;r->borrowbook(b->
溫馨提示
- 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)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 戀愛答辯活動方案
- 悅鮮活促銷活動方案
- 情人節(jié)籃球鞋活動方案
- 感恩父母教育活動方案
- 感恩節(jié)美國商場活動方案
- 慈城古鎮(zhèn)元宵活動方案
- 成人打球活動方案
- 戒煙小手拉大手活動方案
- 戰(zhàn)略發(fā)布會活動方案
- 戶外互換物品活動方案
- 2025年育嬰師職業(yè)資格考試試題及答案
- 2023年三種人試題附答案
- 北京市八十中學(xué)2025屆八年級英語第二學(xué)期期中經(jīng)典試題含答案
- 2024年 金澤鎮(zhèn)專職村務(wù)工作者招錄考試真題試題含答案
- 哇哈哈品牌管理制度
- 2025年內(nèi)蒙古自治區(qū)包頭市東河區(qū)第二中學(xué)英語八年級第二學(xué)期期末復(fù)習(xí)檢測模擬試題含答案
- 2025年四川省達(dá)州市中考英語真題(原卷版)
- 2024年證券市場基本法律法規(guī)真題及答案
- 湖南省2025年高考公安院校公安專業(yè)考生檔案審核表
- 2025年第十屆“學(xué)憲法、講憲法”網(wǎng)絡(luò)知識競賽題庫(含答案)
- 歷史●湖北卷丨2021年湖北省普通高中學(xué)業(yè)水平選擇性考試歷史試卷及答案
評論
0/150
提交評論