




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、目錄1. 課程設計名稱.12.課程設計目的.13課程設計流程圖.14.實驗內容.1(1) 新書注冊模塊.3(2)借書模塊.4(3)查閱圖書.5(4)舊圖書的注銷:.6(5)歸還圖書模塊:.7(6)統(tǒng)計圖書85.程序源代碼:.86.心得體會.137.參考文獻.141.課程設計名稱:圖書管理系統(tǒng)2.課程設計目的(1)加深對文件系統(tǒng)概念的理解,明確文件系統(tǒng)等的運用。(2)熟悉在Liunx環(huán)境下的簡單程序編程。(3)以Linux系統(tǒng)文件部分系統(tǒng)調用為基礎設計一個簡易的圖書管理系統(tǒng)。包括圖書的錄入、查詢、借閱、清理、統(tǒng)計等功能。3課程設計流程圖進入圖書管理系統(tǒng)2借圖書1注冊新書6統(tǒng)計圖書5歸還圖書4注銷
2、舊書請執(zhí)行你要做的操作0退出3查閱圖書4.實驗內容以Linux系統(tǒng)文件部分系統(tǒng)調用為基礎設計一個的圖書管理系統(tǒng)。要求實現(xiàn):圖書的錄入、查詢、借閱、清理、統(tǒng)計等功能、還要實現(xiàn)對每天的借閱情況進行統(tǒng)計。(1) 注冊新書模塊:在此方法book_add()中要充分運用文件指針的運用。通過定義FILE * fp;對文件進行一系列的調整,在新書的注冊的時候不會出現(xiàn)指針的覆蓋,首先以隨機讀寫的方式打開文件,用來避免在打開文件的指針都指向第一個位置的情況通過聲明圖書的有關屬性作為一個數(shù)據(jù)結構struct BOOK。struct BOOK int id,usr10,total,store,days10; cha
3、r name31,author21; books100;/*以上是數(shù)據(jù)結構*/void book_add() char a; FILE * fp; int n=0; int c; if(fp=fopen("bbb","ab+")=NULL) /* 讀寫方式打開或建立新文件*/ printf("cannot open filen"); return ; page_title("注冊新書");do printf("序號:"); scanf("%d",&booksn.id)
4、; printf("書名:"); scanf("%s",&); printf("作者:"); scanf("%s",&booksn.author); printf("數(shù)量:"); scanf("%d",&booksn.total); booksn.store=booksn.total; n+; printf("繼續(xù)注冊:1.是 2.否"); scanf("%d",&c);while(
5、c=1); if(fwrite(books,sizeof(struct BOOK),n, fp)!=n) printf(" file write error"); fclose(fp); do printf("結束? y/n"); scanf(" %c",&a); while(a!='y'); (2)借書模塊借閱圖書模塊book_out()是是通過定義是數(shù)據(jù)結構在通過查找模塊找到該書時是通過書的圖書號進行借閱。void book_out() char a; int n,s,l,d; page_title(&qu
6、ot;借閱圖書"); if(n=search_book()!=-1&&booksn.store>0) printf("請輸入借書證序號:"); scanf("%d",&s); printf("請輸入可借天數(shù):"); scanf("%d",&d); for(l=0;l<10;l+) if(booksn.usrl=0) booksn.usrl=s; booksn.daysl=d; break; booksn.store-; out+; if(n!=-1&&a
7、mp;booksn.store=0) printf("此書已經(jīng)全部借出.n"); do printf("結束? y/n"); scanf(" %c",&a); while(a!='y'); /*上面是借書的函數(shù),首先調用找書函數(shù)*/(3)借閱圖書在查閱圖書的模塊中search_book()定義了文件bbb用與存儲圖書數(shù)據(jù),然后通過該數(shù)據(jù)結構進行圖書查詢int search_book() char a; /* 用以查看結果*/ int n=0,i=0; FILE * fp; if(fp=fopen("b
8、bb","r")=NULL) /* 讀方式打開*/ printf("cannot open filen"); while(!feof(fp) /*把文件寫入內存,books要初始化 */ fread(&booksi,sizeof(struct BOOK),1, fp); i+; fclose(fp); printf("請輸入圖書序號:"); scanf("%d",&i); for(n=0;n<100;n+) if(booksn.id=i) printf("書名:%sn&qu
9、ot;,); printf("作者:%sn",booksn.author); printf("存數(shù):%d n",booksn.store); printf("總數(shù):%d n",booksn.total); do printf("結束? y/n"); scanf(" %c",&a); while(a!='y'); return n; printf("n輸入錯誤或無效圖書序號.n"); do printf("結束? y/n&
10、quot;); scanf(" %c",&a); while(a!='y'); return -1; /*上面的函數(shù)是在數(shù)組中找到圖書號匹配的記錄,顯示其信息并返 回數(shù)組下標,如果找不到相應記錄則提示錯誤并返回-1。*/(4)舊圖書的注銷:在book_del()通過書的書號在文件中進行消除void book_del(void) char a; int n,i; page_title("注銷舊書"); if(n=search_book()!=-1) booksn.id=0; for(i=0;i<31;i+) booksn.na
11、mei=NULL; for(i=0;i<21;i+) booksn.authori=NULL; booksn.total=0; booksn.store=0; printf("該書已注銷.n"); do printf("結束? y/n"); scanf(" %c",&a); while(a!='y'); (5)歸還圖書模塊:圖書歸還模塊book_in是通過圖書的書號進行的,在進行歸還的同時要通過文件指針在進行調整。void book_in(void) char a; int n,s,l; page_tit
12、le("歸還圖書"); if(n=search_book()!=-1&&booksn.store<booksn.total) printf("借閱者圖書證列表:n"); for(l=0;l<10;l+) if (booksn.usrl!=0) printf("%d - %d天",booksn.usrl,booksn.daysl); printf("請輸入借書證序號:"); scanf("%d",&s); for(l=0;l<10;l+) if(books
13、n.usrl=s) booksn.usrl=0; booksn.daysl=0; break; booksn.store+; in-; if(n!=-1&&booksn.store=booksn.total) printf("全部入藏.n"); do printf("結束? y/n"); scanf(" %c",&a); while(a!='y'); (6)統(tǒng)計圖書void tongji() char a; printf("借出總數(shù)%dn",out ); printf(&qu
14、ot;歸還總數(shù)%dn",in); do printf("結束? y/n"); scanf(" %c",&a); while(a!='y');4.程序源代碼:/* 圖書管理系統(tǒng)*/#include <stdio.h>#include <stdlib.h>struct BOOK int id,usr10,total,store,days10; char name31,author21; books100;/*上面是結構體的定義,用于存放書籍及借書的信息。*/int out=0,in=0; /*統(tǒng)計借出
15、和歸還*/ void page_title(char *menu_item) printf(">>> 圖 書 管 理 系 統(tǒng) <<<nn- %s nn",menu_item); /*上面是打印頁眉的函數(shù),同時通過參數(shù)menu_item,可以顯示當前的狀態(tài)。*/int search_book() char a; /* 用以查看結果*/ int n=0,i=0; FILE * fp; if(fp=fopen("bbb","r")=NULL) /* 讀方式打開*/ printf("cannot
16、open filen"); while(!feof(fp) /*把文件寫入內存,books要初始化 */ fread(&booksi,sizeof(struct BOOK),1, fp); i+; fclose(fp); printf("請輸入圖書序號:"); scanf("%d",&i); for(n=0;n<100;n+) if(booksn.id=i) printf("書名:%sn",); printf("作者:%sn",booksn.author); p
17、rintf("存數(shù):%d n",booksn.store); printf("總數(shù):%d n",booksn.total); do printf("結束? y/n"); scanf(" %c",&a); while(a!='y'); return n; printf("n輸入錯誤或無效圖書序號.n"); do printf("結束? y/n"); scanf(" %c",&a); while(a!='y');
18、 return -1; /*上面的函數(shù)是在數(shù)組中找到圖書號匹配的記錄,顯示其信息并返 回數(shù)組下標,如果找不到相應記錄則提示錯誤并返回-1。*/void book_out() char a; int n,s,l,d; page_title("借閱圖書"); if(n=search_book()!=-1&&booksn.store>0) printf("請輸入借書證序號:"); scanf("%d",&s); printf("請輸入可借天數(shù):"); scanf("%d"
19、,&d); for(l=0;l<10;l+) if(booksn.usrl=0) booksn.usrl=s; booksn.daysl=d; break; booksn.store-; out+; if(n!=-1&&booksn.store=0) printf("此書已經(jīng)全部借出.n"); do printf("結束? y/n"); scanf(" %c",&a); while(a!='y'); /*上面是借書的函數(shù),首先調用找書函數(shù)*/void book_in(void) c
20、har a; int n,s,l; page_title("歸還圖書"); if(n=search_book()!=-1&&booksn.store<booksn.total) printf("借閱者圖書證列表:n"); for(l=0;l<10;l+) if (booksn.usrl!=0) printf("%d - %d天n",booksn.usrl,booksn.daysl); printf("請輸入借書證序號:"); scanf("%d",&s); f
21、or(l=0;l<10;l+) if(booksn.usrl=s) booksn.usrl=0; booksn.daysl=0; break; booksn.store+; in-; if(n!=-1&&booksn.store=booksn.total) printf("全部入藏.n"); do printf("結束? y/n"); scanf(" %c",&a); while(a!='y'); void book_add() char a; FILE * fp; int n=0; in
22、t c; if(fp=fopen("bbb","ab+")=NULL) /* 讀寫方式打開或建立新文件*/ printf("cannot open filen"); return ; page_title("注冊新書");do printf("序號:"); scanf("%d",&booksn.id); printf("書名:"); scanf("%s",&); printf("作者:&q
23、uot;); scanf("%s",&booksn.author); printf("數(shù)量:"); scanf("%d",&booksn.total); booksn.store=booksn.total; n+; printf("繼續(xù)注冊:1.是 2.否"); scanf("%d",&c);while(c=1); if(fwrite(books,sizeof(struct BOOK),n, fp)!=n) printf(" file write error&q
24、uot;); fclose(fp); do printf("結束? y/n"); scanf(" %c",&a); while(a!='y'); void book_del(void) char a; int n,i; page_title("注銷舊書"); if(n=search_book()!=-1) booksn.id=0; for(i=0;i<31;i+) i=NULL; for(i=0;i<21;i+) booksn.authori=NULL; booksn.tota
25、l=0; booksn.store=0; printf("該書已注銷.n"); do printf("結束? y/n"); scanf(" %c",&a); while(a!='y'); void tongji() char a; printf("借出總數(shù)%dn",out ); printf("歸還總數(shù)%dn",in); do printf("結束? y/n"); scanf(" %c",&a); while(a!='
26、;y');void main(void) char c;int i,j;for(i=0;i<100;i+) for(j=0;j<30;j+) j=NULL; for(j=0;j<20;j+) booksi.authorj=NULL;menu: page_title("操作選單"); printf("請用數(shù)字鍵選擇操作nn"); printf("1 借閱圖書n2 歸還圖書nn"); printf("3 注冊新書n4 注銷舊書nn"); printf("5 統(tǒng)計n"); printf("6 圖書查詢n");printf("n0 退出n"); scanf("%c&quo
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 醫(yī)療器械質量檢測服務合同
- 職場辦公技能培訓教育范文
- 高考語文復習:人物傳記類文言文專練
- 電線電纜采購合同書
- 法律行業(yè)律師服務費用免責協(xié)議
- 經(jīng)典童話白雪公主的解讀與賞析
- 高考英語完形填空專題集中訓練含參考答案(5份)
- 農(nóng)村居民公共服務需求滿足指導手冊
- 問題解決指南
- 金融科技服務風險免責合同
- 2025年蘇州農(nóng)業(yè)職業(yè)技術學院高職單招高職單招英語2016-2024歷年頻考點試題含答案解析
- 字體設計完整版本
- 【歷史】安史之亂與唐朝衰亡課件 2024-2025學年統(tǒng)編版七年級歷史下冊
- 2024年蘇州衛(wèi)生職業(yè)技術學院高職單招語文歷年參考題庫含答案解析
- 《歡樂運動會:1 我為班級出把力》說課稿-2024-2025學年四年級上冊綜合實踐活動滬科黔科版
- 2024年汽車駕駛員(高級)證考試題庫附答案
- 《兔的飼養(yǎng)管理》課件
- 2025年事業(yè)單位考試(綜合管理類A類)綜合應用能力試題及解答參考
- “互聯(lián)網(wǎng)+”大學生創(chuàng)新創(chuàng)業(yè)大賽計劃書一等獎
- 烹飪(西餐)第三屆全省職業(yè)技能大賽烹飪(西餐)項目技術文件
- 四川政采評審專家入庫考試基礎題練習試題附答案
評論
0/150
提交評論