圖書管理系統(tǒng)源代碼--純C語言..doc_第1頁
圖書管理系統(tǒng)源代碼--純C語言..doc_第2頁
圖書管理系統(tǒng)源代碼--純C語言..doc_第3頁
圖書管理系統(tǒng)源代碼--純C語言..doc_第4頁
圖書管理系統(tǒng)源代碼--純C語言..doc_第5頁
已閱讀5頁,還剩3頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡介

#include#include#include#include#define NULL 0#define LEN sizeof(Book)struct A char Name20; int all,left,borrow; struct A *next; ;typedef struct A Book;int Display_Main_Menu(); /*主菜單顯示*/Book *Create(); /*功能函數(shù)聲明*/ void Display(Book *head);Book *Insert(Book *head,Book *s);Book *Insert_a_record(Book *head);Book *Delete(Book *head,char *name);Book *Delete_a_record(Book *head);Book *Borrow(Book *head,char *name,int sum);Book *Borrow_a_Book(Book *head);Book *Return(Book *head,char *name,int sum);Book *Return_a_Book(Book *head);Book *Query(Book *head,char *name); void Query_a_record(Book *head);Book *AddfromText(Book *head,char *filename);Book *WritetoText(Book *head,char *filename); void Quit(Book *head);void main() /*主函數(shù)部分*/Book *head; /*定義變量*/ char filename20; int keyword=111,a; printf(Please input keyword:); scanf(%d,&a); if(a!=keyword) exit(0); else printf(Welcome!); head=NULL; /*置首指針為空*/ for(;) switch(Display_MainMenu() case 1:printf(1.Create BookListn); /*調(diào)用Create函數(shù)創(chuàng)建鏈表*/ head=Create(); system(pause); break; case 2:printf(Display All Booksn); Display(head); /*調(diào)用Display函數(shù)顯示所有*/ system(pause);break; case 3:printf(Insert a Recordn); head=Insert_a_record(head);/*調(diào)用Insert_a_record函數(shù)插入*/ system(pause);break; case 4:printf(Delete a Bookn); head=Delete_a_record(head);/*調(diào)用Delete_a_record函數(shù)刪除*/ system(pause);break; case 5:printf(Borrow a BooknInput BookName and sum you borrow:); head=Borrow_a_Book(head); system(pause);break; case 6:printf(Return a BooknInput BookName and sum you return:); head=Return_a_Book(head); system(pause);break; case 7:printf(QuerynInput the BookName you want:); Query_a_record(head);/*調(diào)用查詢函數(shù)*/ system(pause);break; case 8:printf(Input the name of Text Filen); scanf(%s,filename);/*輸入文件名*/ head=AddfromText(head,filename); system(pause);break; case 9:printf(Input the name of the NewText Filen); scanf(%s,filename);/*輸入要寫入的文件名*/ head=WritetoText(head,filename); system(pause);break; case 0:printf(Goodbyen); Quit(head); exit(0); int Display_MainMenu() /*顯示菜單的函數(shù)*/char x; do system(cls); printf(*n); printf(1.Create BookListn); printf(2.Display All Booksn); printf(3.Insert a BookInformationn); printf(4.Delete a Bookn); printf(5.Borrow a Bookn); printf(6.Return a Bookn); printf(7.Queryn); printf(8.Add Records From a Filen); printf(9.Write to a Filen); printf(0.Goodbyen); printf(*n); printf(Please choose from 0-9:); printf(n); x=getchar(); while(x9); return(x-0);Book *Create() /*創(chuàng)建鏈表的函數(shù),返回首指針*/Book *head,*newrecord; char ch; printf(Input a Bookn); head=NULL;/*首指針置空*/ do newrecord=(Book *)malloc(LEN); /*動(dòng)態(tài)分配存儲(chǔ)空間*/ scanf(%s%d,newrecord-Name,&newrecord-all); newrecord-left=newrecord-all; newrecord-borrow=0; head=Insert(head,newrecord); /*調(diào)用Insert函數(shù)判斷位置插入*/ getchar(); / *接收最后輸入的回車符*/ printf(Add another Book Y/N?n); ch=getchar(); getchar(); /*接收回車符*/while(ch!=n&ch!=N); /*判斷是否繼續(xù)*/ return(head);Book *Insert(Book *head,Book *s)/*插入結(jié)點(diǎn)的函數(shù)*/ Book *p0,*p1,*p2; p1=head;p0=s; if(head=NULL) head=p0;p0-next=NULL; while(strcmp(p0-Name,p1-Name)0&(p1-next!=NULL) p2=p p1=p1-next; if(strcmp(p0-Name,p1-Name)next=p1; if(head=p1) head=p0; else p2-next=p0; elsep1-next=p0;p0-next=NULL; return(head);Book *Insert_a_record(Book *head) Book *newrecord; newrecord=(Book *)malloc(LEN); /*動(dòng)態(tài)分配存儲(chǔ)空間*/ scanf(%s%d,newrecord-Name,&newrecord-all); newrecord-borrow=0; newrecord-left=newrecord-all; head=Insert(head,newrecord); printf(Insert successfullyn);/*輸出插入成功的信息*/ return(head);Book *Delete(Book *head,char *name) /*刪除功能函數(shù)*/ Book *p1,*p2; if(head=NULL) printf(Sorry No record!n); p1=head; while(strcmp(p1-Name,name)!=0&p1-next!=NULL) / p2=p1;p1=p1-next; if(strcmp(p1-Name,name)=0) if(p1=head)head=p1-next; else p2-next=p1-next; printf(delete %s successfullyn,name); return(head);Book *Delete_a_record(Book *head) char name20,ch; Book *p; scanf(%s,name); getchar(); p=Query(head,name); if(p=NULL) printf(Cannot Find %sn,name); else printf(Delete %s, Y/N?n,name); ch=getchar(); system(pause); if(ch=y|ch=Y) while(p!=NULL) head=Delete(head,name); p=Query(head,name); return(head);Book *Borrow_a_Book(Book *head) char name20,ch; int n; Book *p; scanf(%s%d,name,&n); getchar(); / p=Query(head,name); if(p=NULL) printf(Cannot Find %sn,name); else printf(Are you sure to borrow? %s, Y/N?n,name); ch=getchar(); system(pause); if(ch=y|ch=Y) head=Borrow(head,name,n); return(head);Book *Borrow(Book *head,char *name,int sum) Book *p1; p1=head; while(strcmp(p1-Name,name)!=0&p1-next!=NULL) p1=p1-next; if(strcmp(p1-Name,name)=0) p1-borrow=sum; p1-left=p1-all-sum; return(head);Book *Return_a_Book(Book *head) char name20,ch; int n; Book *p; scanf(%s%d,name,&n); getchar(); /*接收回車*/ p=Query(head,name); if(p=NULL) printf(Cannot Find %sn,name); /*找不到結(jié)點(diǎn)*/ else printf(Are you sure to return? %s, Y/N?n,name); ch=getchar(); system(pause); if(ch=y|ch=Y) head=Return(head,name,n); return(head);Book *Return(Book *head,char *name,int sum) Book *p1; p1=head; while(strcmp(p1-Name,name)!=0&p1-next!=NULL) /*p1不是要找的結(jié)點(diǎn),且后面還有結(jié)點(diǎn)*/ p1=p1-next; /*p1后移一個(gè)結(jié)點(diǎn)*/ if(strcmp(p1-Name,name)=0) /*找到了*/ p1-borrow=p1-borrow-sum; p1-left=p1-left+sum; return(head);void Display(Book *head) Book *p; int i; p=head; printf(Num BookName Total Left Borrown); for(i=1;p!=NULL;i+) printf(%-5d%-14s%-10d%-10d%-5dn, i,p-Name,p-all,p-left,p-borrow); p=p-next; if(i%10=0) system(pause); /*按回車?yán)^續(xù)顯示*/ printf(Num BookName total left borrown); Book *Query(Book *head,char *name) Book *p; p=head; while(strcmp(name,p-Name)!=0&p-next!=NULL) p=p-next; if(strcmp(name,p-Name)=0) /*找到了,返回結(jié)點(diǎn)地址*/ return(p); else /*找不到返回空指針*/ return(NULL);void Query_a_record(Book *head) char name20; Book *p; scanf(%s,name); p=Query(head,name); if(p!=NULL) /*找到了*/ printf(Find successfullyn%s total:%d left:%d borrow:%dn, p-Name,p-all,p-left,p-borrow); else printf(Cant find the records of %sn,name); /*找不到*/Book *AddfromText(Book *head,char *filename) FILE *fp; int n,i; if(fp=fopen(filename,r)=NULL) printf(Cannot find file:%sn,filename); /*打不開所指定文件*/ return(head); fscanf(fp,%d,&n); /*待插入記錄個(gè)數(shù)*/ for(i=0;iName,&p-all,&p-left,&p-borrow); head=Insert(head,p); /*插入結(jié)點(diǎn)*/ printf(Add from %s successfullyn,filename); fclose(fp);return(head);Book *WritetoText(Book *head,char

溫馨提示

  • 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)論