圖書館管理系統(tǒng)-c語言編寫_第1頁
圖書館管理系統(tǒng)-c語言編寫_第2頁
圖書館管理系統(tǒng)-c語言編寫_第3頁
圖書館管理系統(tǒng)-c語言編寫_第4頁
圖書館管理系統(tǒng)-c語言編寫_第5頁
已閱讀5頁,還剩27頁未讀 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

#include"stdio.h"#include"stdlib.h"#include"conio.h"#include"string.h"#include"math.h"#defineLENsizeof(structlibrary)#defineLEN1sizeof(structreader)#defineNULL0structlibrary//圖書館構造體{intshuhao,xcl;charname[20],author[20],chuban[20];structlibrary*next;};structreader//讀者構造體{intzhenghao;charmingzi[20],riqi[20],zname[20];structreader*next;};voidmainmenu()//顯示主菜單{system("cls");printf("\n");printf("\t\t\t\t####################\n\n");printf("\t\t\t\t1.圖書館信息\n\n");printf("\t\t\t\t2.借閱系統(tǒng)\n\n");printf("\t\t\t\t3.退出系統(tǒng)\n\n");printf("\t\t\t請按鍵選擇,回車確定\n");printf("\t\t\t\t######################\n");printf("\n");return;}voidmenu1()//顯示圖書館信息菜單{system("cls");printf("");printf("\t\t\t\t####################\n\n");printf("\t\t\t\t1.采編入庫\n\n");printf("\t\t\t\t2.清除庫存\n\n");printf("\t\t\t\t3.圖書查詢\n\n");printf("\t\t\t\t4.庫存一覽\n\n");printf("\t\t\t\t5.返回上一層\n\n");printf("\t\t\t請按鍵選擇,回車確定\n");printf("\t\t\t\t#######################\n");printf("\n");return;}voidmenu2()//顯示查詢菜單{system("cls");//printf("");printf("\t\t\t\t#######################\n");printf("\t\t\t\t1.書號查詢\n\n");printf("\t\t\t\t2.書名查詢\n\n");printf("\t\t\t\t3.作者查詢\n\n");printf("\t\t\t\t4.出版社查詢\n\n");printf("\t\t\t請按鍵選擇,回車確定\n");printf("\t\t\t\t#######################\n");//printf("");return;}voidmain()//主函數(shù),調用main1{voidmain1();main1();}voidmain1()//main1函數(shù){voidtsgxx();//申明voidjieshuxitong();//申明charchoose;mainmenu();scanf("%c",&choose);switch(choose)//功能函數(shù)選擇{case'1':tsgxx();break;case'2':jieshuxitong();break;case'3':system("cls");printf("\n\n\n\n\n\n\n\n\n\t\t\tByebye...");printf("\n\n\n\n\n\n\n\n\n\t\t\t歡迎使用本軟件?。?!");getch();exit(0);system("cls");break;}}voidtsgxx()//圖書館信息函數(shù){voidtsjinku();voidshanchu();voidchaxunts();voidxianshikucun();//函數(shù)申明charchoose;menu1();//調用菜單函數(shù)scanf("%c",&choose);scanf("%c",&choose);for(;;)switch(choose)//功能函數(shù)選擇{case'1':tsjinku();break;case'2':shanchu();break;case'3':chaxunts();break;case'4':xianshikucun();break;case'5':main1();break;}}inttjzs()//記錄文本個數(shù)函數(shù){FILE*fp;inttshuhao=0,txcl=0,n;chartname[20]={'\0'},tauthor[20]={'\0'},tchuban[20]={'\0'};fp=fopen("library.txt","r");//打開文獻for(n=0;!feof(fp);n++)//逐一讀文獻fscanf(fp,"%d%s%s%s%d",&tshuhao,tname,tauthor,tchuban,&txcl);n--;fclose(fp);//關閉文獻return(n);//返回個數(shù)}inttjdzzs()//記錄文本個數(shù)函數(shù){FILE*fp;intzhenghao=0,n;charmingzi[20]={'\0'},riqi[20]={'\0'},zname[20]={'\0'};fp=fopen("reader.txt","r");//打開文獻for(n=0;!feof(fp);n++)//逐一讀文獻fscanf(fp,"%d%s%s%s",&zhenghao,&mingzi,&riqi,&zname);fclose(fp);//關閉文獻return(n);//返回個數(shù)}voidtsjinku()//圖書進庫函數(shù){FILE*fp;intshuhao=0,xcl=0,n=0;charname[20]={'\0'},author[20]={'\0'},chuban[20]={'\0'};charhitkey;system("cls");if((fp=fopen("library.txt","r"))==NULL)//打開圖書館文獻,不存在此文獻則新建{fp=fopen("library.txt","w");fclose(fp);}fp=fopen("library.txt","a");printf("\n\n\n\n\n\n\t\t\t請按如下格式輸入圖書信息:\t\t\t\t\t\t書號書名作者出版社進庫量\n請輸入:");//按格式輸入圖書館信息for(;hitkey!=27;)//循環(huán)輸入{if(n!=0)printf("請輸入:");scanf("%d%s%s%s%d",&shuhao,name,author,chuban,&xcl);fprintf(fp,"%d%s%s%s%d\n",shuhao,name,author,chuban,xcl);printf("繼續(xù)輸入請按回車,結束輸入請按esc\n");n++;hitkey=getch();for(;hitkey!=13&&hitkey!=27;)hitkey=getch();}fclose(fp);printf("\n\n\n\n\n\n\t\t\t保留成功,按任意鍵返回上一層!");getch();tsgxx();//返回上一層}voidshanchu()//刪除圖書信息函數(shù){structlibrary*head=NULL;structlibrary*p,*p1,*p2;inttshuhao=0,txcl=0,n=0,j,i;chartname[20]={'\0'},tauthor[20]={'\0'},tchuban[20]={'\0'},ttname[20]={'\0'};charhitkey;FILE*fp;if((fp=fopen("library.txt","r"))==NULL)//打開文獻{system("cls");printf("\n\n\n\n\n\n\n\n\n\t\t\t記錄文獻不存在!按任意鍵返回...");getch();tsgxx();}else{system("cls");printf("\n\n\n\n\n\n\n\n\t\t請輸入你要刪除旳書名:");//輸入刪除圖書書名scanf("%s",&ttname);printf("\t\t確認刪除請回車,取消請按esc\n");hitkey=getch();for(;hitkey!=13&&hitkey!=27;)hitkey=getch();if(hitkey==27)tsgxx();fp=fopen("library.txt","r");for(j=0;!feof(fp);)//讀文獻夾信息,記錄個數(shù){j++;fscanf(fp,"%d%s%s%s%d",&tshuhao,tname,tauthor,tchuban,&txcl);}fclose(fp);fp=fopen("library.txt","r");for(i=1;i<j;i++){fscanf(fp,"%d%s%s%s%d",&tshuhao,tname,tauthor,tchuban,&txcl);if(strcmp(ttname,tname))//比較名字,將不同樣名字旳信息復制到鏈表{n++;if(n==1)//建立鏈表{p1=p2=(structlibrary*)malloc(LEN);head=p1;}else{p2->next=p1;p2=p1;p1=(structlibrary*)malloc(LEN);//新建鏈表}p1->shuhao=tshuhao;//復制書號strcpy(p1->name,tname);//復制書名strcpy(p1->author,tauthor);//復制作者名子strcpy(p1->chuban,tchuban);//復制出版社p1->xcl=txcl;//復制個數(shù)}}if(n==0){head=NULL;}else{p2->next=p1;p1->next=NULL;fclose(fp);}}fp=fopen("library.txt","w");//清空文獻fclose(fp);fp=fopen("library.txt","a");//追加文獻p=head;for(;p!=NULL;)//把鏈表內容覆蓋到文獻{fprintf(fp,"%d%s%s%s%d\n",p->shuhao,p->name,p->author,p->chuban,p->xcl);p=p->next;}fclose(fp);//關閉文獻system("cls");printf("\n\n\n\n\n\n\n\n\t\t刪除成功\n\t\t按任意鍵返回上一層\n");getch();//返回上一層tsgxx();}voidchaxunts()//查詢函數(shù){FILE*fp;charchoose;intttshuhao=0,tshuhao=0,txcl=0,n=0,k=0,i,l;chartname[20]={'\0'},ttauthor[20]={'\0'},tauthor[20]={'\0'},ttchuban[20]={'\0'},tchuban[20]={'\0'},ttname[20]={'\0'};if((fp=fopen("library.txt","r"))==NULL)//打開文獻{system("cls");printf("\n\n\n\n\n\n\n\n\n\t\t\t記錄文獻不存在!按任意鍵返回...");getch();tsgxx();}l=tjzs();//獲得文獻個數(shù)menu2();//調用菜單函數(shù)scanf("%c",&choose);scanf("%c",&choose);//選擇查詢方式if(choose=='5')return;elseif(choose=='1')//書號查詢{system("cls");printf("請輸入書號:");scanf("%d",&ttshuhao);}elseif(choose=='2')//書名查詢{system("cls");printf("請輸入書名:");scanf("%s",ttname);}elseif(choose=='3')//作者查詢{system("cls");printf("請輸入作者:");scanf("%s",ttauthor);}elseif(choose=='4')//出版社查詢{system("cls");printf("請輸入出版社:");scanf("%s",ttchuban);}system("cls");for(i=0;i<l;i++){fscanf(fp,"%d%s%s%s%d",&tshuhao,tname,tauthor,tchuban,&txcl);//讀文獻信息if(ttshuhao==tshuhao||!strcmp(ttname,tname)||!strcmp(ttauthor,tauthor)||!strcmp(ttchuban,tchuban))//輸出查詢信息{if(k==0){printf("\t\t\t\t查詢成果:\n\n");printf("\t書號書名作者出版社現(xiàn)存量\n");}printf("\t%-4d%-8s%-8s%-8s%-4d\n",tshuhao,tname,tauthor,tchuban,txcl);k++;}}if(k==0)//文獻夾為空則輸出無記錄{system("cls");printf("\n\n\n\n\n\n\n\t\t\t\t無符合記錄!\n");getch();tsgxx();}fclose(fp);getch();//返回tsgxx();}voidxianshikucun()//現(xiàn)實庫存信息{FILE*fp;intshuhao=0,xcl=0,n=0,i=0,j=0;charname[20]={'\0'},author[20]={'\0'},chuban[20]={'\0'};if((fp=fopen("library.txt","r"))==NULL)//打開文獻夾{system("cls");printf("\n\n\n\n\n\n\n\n\n\t\t\t記錄文獻不存在!");}n=tjzs();if(n==0){system("cls");printf("\n\n\n\n\n\n\n\n\n\t\t\t無任何記錄!");}fp=fopen("library.txt","r");system("cls");printf("********************************************************************************");printf("\t書號書名作者出版社庫存量\n");printf("********************************************************************************");for(i=0;i<n;i++)//輸出信息{fscanf(fp,"%d%s%s%s%d",&shuhao,name,author,chuban,&xcl);printf("\t%-4d%-8s%-8s%-8s%-4d\n",shuhao,name,author,chuban,xcl);}fclose(fp);printf("\t\t\t\t按任意鍵返回\n");getch();//返回tsgxx();}voidmenu3()//顯示借書系統(tǒng)主菜單{system("cls");//printf("********************************************************************************");printf("\t\t\t\t#######################\n");printf("\t\t\t\t1.借書登記\n\n");printf("\t\t\t\t2.還書登記\n\n");printf("\t\t\t\t3.借閱狀況查看\n\n");printf("\t\t\t\t4.返回上一層\n\n");printf("\t\t\t請按鍵選擇,回車確定\n");printf("\t\t\t\t#######################\n");//printf("********************************************************************************");return;}voidjieshuxitong()//借書系統(tǒng)函數(shù){voidjieshu();voidhuanshu();voidduzheyilang();//函數(shù)申明charchoose;menu3();scanf("%c",&choose);scanf("%c",&choose);//選擇功能for(;;)switch(choose)//調用函數(shù){case'1':jieshu();break;case'2':huanshu();break;case'3':duzheyilang();break;case'4':main1();break;}}voidjieshu()//借書函數(shù){FILE*fp,*fp3;structlibrary*head=NULL;structlibrary*p,*p1,*p2;inttshuhao=0,txcl=0,i,loop,zhenghao=0,n=0,k=0,t=0,flag=0;chartname[20]={'\0'},tauthor[20]={'\0'},tchuban[20]={'\0'},ttname[20]={'\0'},mingzi[20]={'\0'},riqi[20]={'\0'},zname[20]={'\0'};charhitkey=0;system("cls");{if((fp=fopen("library.txt","r"))==NULL)//打開圖書館文獻{system("cls");printf("\n\n\n\n\n\n\n\n\n\t\t圖書館無庫存!按任意鍵退出!");getch();exit(0);}else{{printf("\n\n\n\n\n\n\t\t\t請輸入借閱書名:\t\t\t\t\t\t\n請輸入:");//輸入書名scanf("%s",zname);k=tjzs();//記錄圖書館文獻個數(shù)for(i=0;i<k;i++)//讀入圖書館信息,存儲到鏈表{fscanf(fp,"%d%s%s%s%d",&tshuhao,tname,tauthor,tchuban,&txcl);n++;if(n==1){p1=p2=(structlibrary*)malloc(LEN);head=p1;}else{p2->next=p1;p2=p1;p1=(structlibrary*)malloc(LEN);//新建鏈表}p1->shuhao=tshuhao;//復制書號strcpy(p1->name,tname);//復制書名strcpy(p1->author,tauthor);//復制作者strcpy(p1->chuban,tchuban);//復制出版社p1->xcl=txcl;//復制現(xiàn)存量}if(n==0)head=NULL;else{p2->next=p1;p1->next=NULL;fclose(fp);}}}p=head;for(;p!=NULL;)//讀鏈表{if(!(strcmp(p->name,zname)))//名字相似{flag=1;//標識取1loop=p->xcl;//現(xiàn)存量減1(p->xcl)--;}p=p->next;}if(flag&&(loop>0))//存在借書書名且現(xiàn)存量不不大于0{fp=fopen("library.txt","w");fclose(fp);fp=fopen("library.txt","a");p=head;for(;p!=NULL;){fprintf(fp,"%d%s%s%s%d\n",p->shuhao,p->name,p->author,p->chuban,p->xcl);p=p->next;}free(p);//把鏈表內容覆蓋文獻fclose(fp);}if(flag&&(loop>0))//存在借書書名且現(xiàn)存量不不大于0{{if((fp3=fopen("reader.txt","r"))==NULL)//建讀者文獻夾{fp3=fopen("reader.txt","w");fclose(fp3);}fp3=fopen("reader.txt","a");}{{if(n!=0)printf("\n\n\n\n\n\n\t\t\t請按如下格式輸入讀者信息:\t\t\t\t\t\t證號姓名償還日期借書書名\n請輸入:");//錄入讀者信息scanf("%d%s%s%s",&zhenghao,&mingzi[20],&riqi[20],&zname[20]);fprintf(fp3,"%d%s%s%s\n",zhenghao,&mingzi[20],&riqi[20],&zname[20]);fp=fopen("library.txt","w");//刪除圖書館文獻信息fclose(fp);fp=fopen("library.txt","a");//重新追加信息p=head;for(;p!=NULL;)//把鏈表內容覆蓋圖書館文獻{fprintf(fp,"%d%s%s%s%d\n",p->shuhao,p->name,p->author,p->chuban,p->xcl);p=p->next;}fclose(fp);fclose(fp3);printf("成功!按任意鍵返回\n");getch();//返回jieshuxitong();}}jieshuxitong();}elseprintf("此書已被借完!按任意鍵返回!");//否則輸出此書已被接完getch();//返回jieshuxitong();}}voidhuanshu()//還書函數(shù){FILE*fp,*fp3;structreader*head=NULL;structreader*p,*p1,*p2;structlibrary*lhead1=NULL;structlibrary*zp1,*lp1,*lp2;inttshuhao=0,txcl=0,i;chartname[20]={'\0'},tauthor[20]={'\0'},tchuban[20]={'\0'},ttname[20]={'\0'};intttzhenghao=0,tzhenghao=0,n=0,k=0,t=0,flag=0;chartmingzi[20]={'\0'},triqi[20]={'\0'},tzname[20]={'\0'},ttzname[20]={'\0'};charhitkey=0;system("cls");{if((fp=fopen("reader.txt","r"))==NULL)//不存在讀者文獻,則輸出不能還書{system("cls");printf("\n\n\n\n\n\n\n\n\n\t\t不存在借書者!按任意鍵退出!");getch();exit(0);}else{{printf("\n\n\n\n\n\n\t\t\t請輸入讀者證號和書名:\t\t\t\t\t\t\n請輸入:");scanf("%d%s",&ttzhenghao,ttzname);//輸入還書證號和書名k=tjdzzs();//獲取讀者文獻夾信息個數(shù)for(i=0;i<k;i++)//讀取讀者文獻夾信息{fscanf(fp,"%d%s%s%s\n",&tzhenghao,tmingzi,triqi,tzname);if((ttzhenghao==tzhenghao)&&!strcmp(ttzname,tzname))//假如證號書名存在,則標識為1flag=1;}fclose(fp);fp=fopen("reader.txt","r");//打開讀者文獻if(flag){for(i=0;i<k;i++)//將讀者文獻復制到鏈表{fscanf(fp,"%d%s%s%s\n",&tzhenghao,tmingzi,triqi,tzname);//讀取文獻信息if(!((ttzhenghao==tzhenghao)&&!strcmp(ttzname,tzname))){n++;if(n==1){p1=p2=(structreader*)malloc(LEN1);//新建鏈表head=p1;}else{p2->next=p1;p2=p1;p1=(structreader*)malloc(LEN1);//新建鏈表}p1->zhenghao=tzhenghao;//復制證號strcpy(p1->mingzi,tmingzi);//復制讀者名字strcpy(p1->riqi,triqi);//復制日期strcpy(p1->zname,tzname);//復制書名}}if(n==0)head=NULL;else{p2->next=p1;p1->next=NULL;fclose(fp);}fp=fopen("reader.txt","w");//清空讀者文獻fclose(fp);fp=fopen("reader.txt","a");//追加信息p=head;for(;p!=NULL;)//把鏈表內容覆蓋讀者文獻{fprintf(fp,"%d%s%s%s\n",p->zhenghao,p->mingzi,p->riqi,p->zname);p=p->next;}free(p);fclose(fp);}}}}if(flag)//標識為1,既還書時{{{printf("確認還書請按回車!");for(;hitkey!=13&&hitkey!=27;)hitkey=getch();if(hitkey==13)printf("成功!按任意鍵返回!");n=0;flag=0;fp3=fopen("library.txt","r");//打開圖書館文獻k=tjzs();//獲取圖書館文獻個數(shù)for(i=0;i<k;i++)//將圖書館文獻復制到鏈表{fscanf(fp3,"%d%s%s%s%d",&tshuhao,tname,tauthor,tchuban,&txcl);//讀取信息n++;if(n==1){lp1=lp2=(structlibrary*)malloc(LEN);//新建鏈表lhead1=lp1;}else{lp2->next=lp1;lp2=lp1;lp1=(structlibrary*)malloc(LEN);//新建鏈表}lp1->shuhao=tshuhao;//復制書號strcpy(lp1->name,tname);//復制書名strcpy(lp1->author,tauthor);//復制作者strcpy(lp1->chuban,tchuban);//復制出版社lp1->x

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論