圖書管理系統(tǒng)(含源代碼)c語言 數(shù)據(jù)結(jié)構(gòu)課程設(shè)計(jì)報(bào)告_第1頁
圖書管理系統(tǒng)(含源代碼)c語言 數(shù)據(jù)結(jié)構(gòu)課程設(shè)計(jì)報(bào)告_第2頁
圖書管理系統(tǒng)(含源代碼)c語言 數(shù)據(jù)結(jié)構(gòu)課程設(shè)計(jì)報(bào)告_第3頁
圖書管理系統(tǒng)(含源代碼)c語言 數(shù)據(jù)結(jié)構(gòu)課程設(shè)計(jì)報(bào)告_第4頁
圖書管理系統(tǒng)(含源代碼)c語言 數(shù)據(jù)結(jié)構(gòu)課程設(shè)計(jì)報(bào)告_第5頁
已閱讀5頁,還剩20頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、算法與數(shù)據(jù)結(jié)構(gòu)課程設(shè)計(jì)實(shí)驗(yàn)報(bào)告設(shè)計(jì)題目:圖書管理 專業(yè): 計(jì)算機(jī)科學(xué)與技術(shù) 班級(jí): 學(xué)生姓名: 學(xué)號(hào): 指導(dǎo)教師: 2011 年 7 月煙臺(tái)大學(xué)計(jì)算機(jī)學(xué)院一 題目要求1 目的要求本課程設(shè)計(jì)任務(wù)的目的是要求學(xué)生按照分析、設(shè)計(jì)、編碼、調(diào)試和測(cè)試的軟件開發(fā)過程獨(dú)立完成管理系統(tǒng)設(shè)計(jì),以及C語言算法的掌握,并能最終實(shí)現(xiàn)本系統(tǒng)的功能要求,通過這個(gè)程序可以學(xué)習(xí)到以前調(diào)試短程序沒有的的經(jīng)驗(yàn)。2、題目要求實(shí)現(xiàn)圖書管理信息系統(tǒng)的設(shè)計(jì)。要求實(shí)現(xiàn)圖書添加、顯示全部圖書、查詢、借閱和歸還。主要考查利用文件的操作!二 總體設(shè)計(jì)圖書數(shù)據(jù):書號(hào),書名,圖書ID,圖書狀態(tài),借閱次數(shù)1. 借書模塊:輸入圖書ID如果存在提示借閱成

2、功,如果沒有或已借出提示借閱失敗2.還書模塊:輸入圖書ID進(jìn)行還書操作3.圖書管理:對(duì)書庫中書進(jìn)行管理 新書入庫 對(duì)庫存量進(jìn)行統(tǒng)計(jì)和查詢4.查詢模塊:對(duì)書庫中書進(jìn)行查詢 根據(jù)圖書ID進(jìn)行查詢?nèi)?編碼實(shí)現(xiàn)定義圖書結(jié)構(gòu)體struct Bookint id;/圖書的編號(hào)char name20;/圖書名字int type;/圖書類型int status; /圖書現(xiàn)在狀態(tài)int count; / 圖書借出的次數(shù);定義圖書類型 typedef struct Book Book;Book dataMax;int all = 0;/ 添加圖書類型,用戶信息顯示 char BookTypes32 =文學(xué),中文社

3、科,自然科學(xué),計(jì)算機(jī),報(bào)刊/雜志,;添加圖書狀態(tài) char BookStatus32 =在架上,已借出,;圖書管理菜單char BookMenu32 = 添加圖書,列出圖書,查找圖書,借書,還書,退出,; 實(shí)現(xiàn)程序?qū)ξ募淖x取 void Read() int i=0;int j=0;ifstream in(Libra.txt,ios:out);ini;all=i;if(i0&i=Max)for(j=1;dataj.typedataj.statusdataj.count;in.close();對(duì)寫入信息進(jìn)行保存void Save()int i=0;ofstr

4、eam outfile; /在Libra.txt文件中輸入數(shù)據(jù)outfile.open(Libra.txt,ios:trunc); outfileall0;all-) i+;outfiledatai.idt;t;outfiledatai.typet;outfiledatai.statust;outfiledatai.countn;coutendl你已成功保存數(shù)據(jù)!endlendl;outfile.close();/exit(1);Main函數(shù)int main()int ch = 0,i,loop = 1;while(loop)Read();print_menu

5、(BookMenu);scanf(%d,&ch);if (ch 6)printf(n沒有所輸選項(xiàng),請(qǐng)確定所輸入選項(xiàng)為1-6中的選項(xiàng)!n);printf(n); switch(ch)case 1:/添加圖書信息PutInfor();break;case 2:Read();Printall();break;case 3:system(cls);Read();searchBook();break;case 4:system(cls);Read();Borrow();break;case 5:system(cls);Read();Return();break;case 6:loop=0;break;d

6、efault:break; printf(n-分割線-nn);return 0;四 調(diào)試與測(cè)試主菜單生成的文件內(nèi)信息五 心得體會(huì)首先,寫程序應(yīng)先確定目標(biāo)要求,所用平臺(tái)和工具,不求最好,但求最適合自己。開始時(shí)決定用MFC 但是我對(duì)MFC的了解就像它對(duì)我的了解一樣多,一天之后果斷和它說再見,我不想把僅有時(shí)間用在學(xué)習(xí)一門工具上。其次是代碼的編寫,最主要的的是編程思想,語言其實(shí)不是太重要,思路最重要!在此感謝一下在我卡殼時(shí)幫助我的同學(xué)和解答的老師,雖然我沒問什么,還是要感謝一下!附錄:源代碼 1此代碼為此報(bào)告所用代碼,有文件操作,運(yùn)行后會(huì)生成一Libra.txt文件#include #include

7、#include #include#include #include #include #include #include#define BORROWED 1#define NOBORROW 0#define Max 100void Save();void Read();int BinSearch(int key);/定義圖書結(jié)構(gòu)體struct Bookint id;/圖書的編號(hào)char name20;/圖書名字int type;/圖書類型int status; /圖書現(xiàn)在狀態(tài)int count; / 圖書借出的次數(shù);/ 定義圖書類型 typedef struct Book Book;Book

8、 dataMax;int all = 0;/ 添加圖書類型,用戶信息顯示 char BookTypes32 =文學(xué),中文社科,自然科學(xué),計(jì)算機(jī),報(bào)刊/雜志,;/ 添加圖書狀態(tài) char BookStatus32 =在架上,已借出,;/圖書管理菜單char BookMenu32 = 添加圖書,列出圖書,查找圖書,借書,還書,退出,;/菜單輸出void print_menu(char menus32 ) int n = 0;printf(請(qǐng)輸入所需選項(xiàng):n);while(strlen(menusn)printf(%d %sn,n+1,menusn);+n;printf(請(qǐng)選擇();while(n)

9、printf(%d|,n-);printf();void Read() int i=0;int j=0;ifstream in(Libra.txt,ios:out);ini;all=i;if(i0&i=Max)for(j=1;dataj.typedataj.statusdataj.count;in.close();void PutInfor() /信息輸入函數(shù) all+;cout輸入圖書ID:dataall.id;cout輸入圖書名字:;cout輸入圖書類別:dataall.type;Save();Read();cout輸入完成!e

10、ndl; void Borrow() /借閱圖書 int k=0;Book B;cout輸入所要借閱圖書ID:B.id;k=BinSearch(B.id);if(k=0)cout* 無此書信息,可能是輸入錯(cuò)誤! *endl;elseofstream outfile; /在Libra.txt文件中輸入數(shù)據(jù)outfile.open(Libra.txt,ios:trunc); outfilealln;datak.status=1;for(int i=1;i=all;i+)if (i=k)datak.status=1;datak.count+;outfiledatai.idt;outfiledatai

11、.namet;outfiledatai.typet;outfiledatai.statust;outfiledatai.countn; elseoutfiledatai.idt;t;outfiledatai.typet;outfiledatai.statust;outfiledatai.countn;outfile.close();for(int j=k;jall;j+)dataj=dataj+1;all-;Read();printf(借閱成功!);void Return() /還書 int k=0;Book B;cout輸入所要?dú)w還圖書ID:B.id;k=B

12、inSearch(B.id);if(k=0)cout* 無此書信息,可能是輸入錯(cuò)誤! *endl;elseofstream outfile; /在Libra.txt文件中輸入數(shù)據(jù)outfile.open(Libra.txt,ios:trunc); outfilealln;datak.status=1;for(int i=1;i=all;i+)if (i=k)datak.status=0;outfiledatai.idt;t;outfiledatai.typet;outfiledatai.statust;outfiledatai.countn; elseoutf

13、iledatai.idt;t;outfiledatai.typet;outfiledatai.statust;outfiledatai.countn;outfile.close();for(int j=k;jall;j+)dataj=dataj+1;all-;Read();printf(歸還成功!);int BinSearch(int key)int low,high,mid;low=1;high=all;while(low=high)mid=(low+high)/2;if(key=datamid.id)return mid;else if(keydatami

14、d.id)high=mid-1;elselow=mid+1;return 0;void Save()int i=0;ofstream outfile; /在Libra.txt文件中輸入數(shù)據(jù)outfile.open(Libra.txt,ios:trunc); outfileall0;all-) i+;outfiledatai.idt;t;outfiledatai.typet;outfiledatai.statust;outfiledatai.countn;coutendl你已成功保存數(shù)據(jù)!endlendl;outfile.close();/exit(1);voi

15、d searchBook() int num,i;printf(請(qǐng)輸入所要查找的圖書ID:);scanf(%d,&num);i = BinSearch(num);if (i=0)printf(輸入有誤,請(qǐng)重新輸入!); elseprintf(-n);printf(ID| 書名| 圖書分類| 現(xiàn)在狀態(tài)| 借出次數(shù)|n);printf(-n);printf(%2d| %17s|%15s|%12s|%10d| n,datai.id, , BookTypesdatai.type-1,BookStatusdatai.status, datai.count);void Printall

16、() /輸出信息printf(-n);printf(ID| 書名| 圖書分類| 現(xiàn)在狀態(tài)| 借出次數(shù)|n);printf(-n);for(int i=1;i=all;i+) if(!=NULL)printf(%2d| %17s|%15s|%12s|%10d| n,datai.id, , BookTypesdatai.type-1,BookStatusdatai.status, datai.count);int main()int ch = 0,i,loop = 1;while(loop)Read();print_menu(BookMenu);scanf(

17、%d,&ch);if (ch 6)printf(n沒有所輸選項(xiàng),請(qǐng)確定所輸入選項(xiàng)為1-6中的選項(xiàng)!n);printf(n); switch(ch)case 1:/添加圖書信息PutInfor();break;case 2:Read();Printall();break;case 3:system(cls);Read();searchBook();break;case 4:system(cls);Read();Borrow();break;case 5:system(cls);Read();Return();break;case 6:loop=0;break;default:break; pri

18、ntf(n-分割線-nn);return 0;文件內(nèi)容格式為ID| 書名| 圖書分類| 現(xiàn)在狀態(tài)| 借出次數(shù)|例如第七行 6 為圖書ID 英語 為圖書名字 1 為圖書分類 0 為現(xiàn)在狀態(tài) 0 為借閱次數(shù)圖書分類 1: 文學(xué), :2: 中文社科, :3:自然科學(xué), :4: 計(jì)算機(jī), :5: 報(bào)刊/雜志,圖書狀態(tài) 0 在架上 1 已借出源代碼2 此代碼無文件操作,不會(huì)生成txt文件 只能在控制臺(tái)運(yùn)行 #include #include #include #define BORROWED 1#define NOBORROW 0/定義圖書結(jié)構(gòu)體struct Bookint id;/圖書的唯一編號(hào)cha

19、r name20;/圖書名字int type;/圖書類型int status; /圖書現(xiàn)在狀態(tài)int count; / 圖書借出的次數(shù) struct Book* next;/ 下一本書 struct Book* prev;/ 上一本書;/ 定義圖書類型 typedef struct Book Book;/ 添加圖書類型,用戶信息顯示 char BookTypes32 =文學(xué),中文社科,自然科學(xué),計(jì)算機(jī),報(bào)刊/雜志,;/ 添加圖書狀態(tài) char BookStatus32 =在架上,已借出,;/圖書管理菜單char BookMenu32 = 添加圖書,列出圖書,查找圖書,借書,還書,退出,;/搜索

20、目錄char bookSearchMenu32 = 按書名查找,按類型查找,;/增加圖書int addBooks(Book* head,Book* bookAdd)Book* p = head;if (!p)return -1;while(p-next)p = p-next;p-next = bookAdd;bookAdd-id = p-id+1;bookAdd-prev = p; bookAdd-next = NULL; bookAdd-count = 0; bookAdd-status = 0;return 0;/圖書信息鏈表Book* creatList(Book* bookHead)i

21、f (bookHead)bookHead-prev = bookHead;bookHead-next = NULL; bookHead-id = 1; bookHead-count = 0; bookHead-status = 0;return bookHead;/ 釋放鏈表 void freeList(Book* book_head) Book *p, *p1; p = book_head; while(p) p1 = p-next; free(p); p = p1; /菜單輸出void print_menu(char menus32 ) int n = 0;printf(請(qǐng)輸入所需選項(xiàng):n

22、);while(strlen(menusn)printf(%d %sn,n+1,menusn);+n;printf(請(qǐng)選擇();while(n)printf(%d|,n-);printf();/輸出圖書信息 void print_book(Book* book) printf(%2d| %17s|%15s|%12s|%10d| n,book-id, book-name, BookTypesbook-type,BookStatusbook-status, book-count);printf(-n);/列出全部圖書void listBooks(Book* bookHead) Book* p =

23、bookHead; while (p) print_book(p); p = p-next; /借書,如果書存在返回此書指針,如果不存在返回空Book* borrowBooks( Book* book_head, int _id ) Book* p = book_head; while (p) if (p-id = _id) break; p = p-next; if (!p) /圖書不存在 printf(您所借圖書不存在,請(qǐng)重新輸入!n);return NULL; if (p-status != 0) /圖書已借出printf(您所借圖書已借出,請(qǐng)重新輸入新的圖書!n);return NUL

24、L; p-status = 1;/圖書是否借出狀態(tài) p-count+; /借出次數(shù)+1 return p; /還書,正常歸還就返回該書的指針,否則就返回NULL Book* returnBooks(Book* book_head, int _id) Book* p = book_head; while (p) if (p-id = _id & p-status != 0) p-status = 0; /圖書歸還時(shí)狀態(tài)改變 break; p = p-next; return p;/按圖書名字查找int searchBookByName( Book* book_head, char* _name

25、) int count = 0; Book* p = book_head; while (p) if (strcmp(p-name, _name) = 0) print_book(p); +count; p = p-next; return count;/查找書類型,返回查找到的數(shù)量int searchBooksByType(Book* book_head, int _type) int count = 0; Book* p = book_head; while (p) if (p-type = _type ) print_book(p); +count; p = p-next; return

26、 count;int main()int ch = 0,loop = 1;char information100;/定義圖書Book FBooks,*pBooks,*pTemp;/初始化第一本圖書名字為數(shù)據(jù)結(jié)構(gòu)strcpy(FB, 數(shù)據(jù)結(jié)構(gòu));FBooks.type = 0;FBooks.status = 0;pBooks = creatList(&FBooks);while(loop)print_menu(BookMenu);scanf(%d,&ch);if (ch 6)printf(n沒有所輸選項(xiàng),請(qǐng)確定所輸入選項(xiàng)為1-6中的選項(xiàng)!n);printf(n); switch

27、(ch)case 1:/添加圖書信息pTemp = (Book*)malloc(sizeof(Book);if(pTemp) printf(請(qǐng)輸入圖書的名字:);scanf(%s,information);strncpy(pTemp-name,information,31);print_menu(BookTypes);scanf(%d,&ch);if (ch (sizeof(BookTypes)/32)ch = 1;pTemp-type = ch - 1;addBooks(pBooks,pTemp);break;case 2:/列出全部圖書printf(-n);printf(ID| 書名| 圖書分類| 現(xiàn)在狀態(tài)| 借出次數(shù)|n);printf(-n);listBooks(pBooks);break;case

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(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ì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論