圖書管理系統(tǒng)
任務(wù)背景:
18級軟件工程大一上學(xué)期C語言課程設(shè)計。
編寫目的:
把學(xué)習(xí)的C語言知識運用到實際上,強化能力。
任務(wù)描述:
C語言編程模擬一個簡單的圖書管理系統(tǒng),主要包括圖書的庫存信息,每一本書的借閱信息以及每一個人的借書信息。
系統(tǒng)功能:
(1)借閱資料管理(對相關(guān)資料進行添加,刪除,修改,查詢等操作)
(2)借閱管理(包括借出操作,還書操作,續(xù)借處理)
(3)讀者管理(定義讀者借書數(shù)量和相關(guān)的借閱時間等信息)
(4)統(tǒng)計分析(當前借閱和相關(guān)資料狀態(tài),資料狀態(tài)統(tǒng)計,借閱統(tǒng)計)
系統(tǒng)設(shè)計分析(程序流程圖,函數(shù)模塊分析):
程序源代碼:
添加鏈接描述
/*圖書管理系統(tǒng) 終極確定版*/ #include<stdio.h>
#include<stdlib.h> //有system函數(shù)
#include<conio.h> //有通過控制臺進行數(shù)據(jù)輸入和數(shù)據(jù)輸出的函數(shù)
#include<string.h> //有字符數(shù)組
#include<math.h>
#define LEN sizeof(struct library)//有關(guān)圖書信息的結(jié)構(gòu)體
#define LEN1 sizeof(struct reader) //有關(guān)讀者信息的結(jié)構(gòu)體struct library//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%圖書館結(jié)構(gòu)體
{int xcl;//庫存float price;//單價char name[20],author[20],chuban[20],kind[20],shuhao[20];struct library *next;
};struct reader//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%讀者結(jié)構(gòu)體
{int zhenghao;char mingzi[20],riqi[20],zname[20];struct reader *next;
};void mainmenu()//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~主菜單
{ system ("cls");//清除屏幕先前顯示的內(nèi)容 ,往下運行(在stdlib.h頭文件中) printf("\n\n\n ^.^ ^.^ ^.^ ^.^ ^.^ ^.^ ^.^ ^.^ ^.^ ^.^ ^.^ ^.^ ^.^ ");printf("\n\n\n 1.__庫存圖書信息__\n\n");printf("\n\n 2.__借閱圖書系統(tǒng)__\n\n");printf("\n\n 3.__退出管理系統(tǒng)__\n\n");//printf("\n\n ^~^請您按鍵選擇and回車確定哦~.~\n\n\n");printf(" ^.^ ^.^ ^.^ ^.^ ^.^ ^.^ ^.^ ^.^ ^.^ ^.^ ^.^ ^.^ ^.^ \n");
}void menu1() //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~顯示 圖書信息 菜單
{ system ("cls");printf("\n\n\n ^~^ ^~^ ^~^ ^~^ ^~^ ^~^ ^~^ ^~^ ^~^ ^~^ ^~^ ^~^ ^~^ ");printf("\n\n 1.__圖書入庫__\n\n");printf("\n 2.__圖書清理__\n\n");printf("\n 3.__圖書查詢__\n\n");printf("\n 4.__庫存概覽__\n\n");printf("\n 5..返回上一層..\n\n");//printf("\n ^~^請您按鍵選擇and回車確定哦*.*\n\n");printf(" ^~^ ^~^ ^~^ ^~^ ^~^ ^~^ ^~^ ^~^ ^~^ ^~^ ^~^ ^~^ ^~^ \n");
}void menu2() //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~顯示 借閱系統(tǒng) 菜單
{ system ("cls");printf("請輸入書號,書名,作者或類別查詢:\n");printf("類別(科學(xué)技術(shù) 語言文學(xué) 政治經(jīng)濟 歷史地理 意識形態(tài) 藝術(shù))\n\n");
}void main1()//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~main1函數(shù)
{void tsgxx();//聲明 圖書館信息 函數(shù) void jieshuxitong();//聲明 借書系統(tǒng) 函數(shù)char choose;mainmenu();//顯示主菜單 scanf("%c",&choose);switch(choose)//功能函數(shù)選擇{ case '1': tsgxx();break;case '2': jieshuxitong(); break; case '3': system ("cls");printf("\n\n\n 刪改內(nèi)容已經(jīng)保存了呢 ^、^\n\n\n 任意鍵安全退出哦 ^、^\n\n");exit(0);//exit關(guān)閉所有文件,終止正在執(zhí)行的程序。exit(0):正常退出break;}
}void tsgxx()//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~圖書館信息函數(shù)
{ void tsjinku();//聲明 圖書進庫 函數(shù) void shanchu();//聲明 刪除圖書信息 函數(shù) void chaxunts();//聲明 查詢圖書 函數(shù) void kucunxinxi();//聲明 顯示庫存 函數(shù) char choose;menu1();//顯示 圖書信息 菜單 getchar();//吞掉一個顯示出menu1函數(shù)后的進行下一步的回車 scanf("%c",&choose);for (;;)//在返回上一級前循環(huán)輸入 //??? switch(choose){ case '1': tsjinku();break;case '2': shanchu();break;case '3': chaxunts();break;case '4': kucunxinxi();break;case '5': main1();//返回上一級 break;}
}int kucungs()//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~統(tǒng)計庫存圖書文本個數(shù)函數(shù)
{ FILE *fp;//定義一個指針 int txcl=0,n;float tprice=0;char tname[20]={'\0'},tauthor[20]={'\0'},tchuban[20]={'\0'},tkind[20]={'\0'},tshuhao[20]={'\0'};fp=fopen("library.txt","r");//打開文件 fopen("文件名.文件類型","權(quán)限"); for (n=0;!feof(fp);n++)//逐個讀文件(feof(fp):檢測是否以及讀取到文件尾部,到達尾部返回1,否則返回0)fscanf(fp,"%s%s%s%s%s%d%f",tshuhao,tname,tauthor,tchuban,tkind,&txcl,&tprice);n--;fclose(fp);//關(guān)閉文件return (n);//返回個數(shù)
}int duzhegs()//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~統(tǒng)計讀者文本個數(shù)函數(shù)
{ FILE *fp;int zhenghao=0,n;char mingzi[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);//關(guān)閉文件return (n);//返回個數(shù)
}void tsjinku()//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~圖書進庫函數(shù)
{ FILE *fp;int xcl=0,n=0;float price=0;char name[20]={'\0'},author[20]={'\0'},kind[20]={'\0'},chuban[20]={'\0'},shuhao[20]={'\0'};char hitkey; system ("cls");if ((fp=fopen("library.txt","a"))==NULL)//打開圖書館文件,不存在此文件則新建{ fp=fopen("library.txt","w");fclose(fp);}fp=fopen("library.txt","a");//追加寫打開進行錄入數(shù)據(jù) printf("\n 請您輸入需要添加的圖書信息:\n\n 書號 書名 作者 出版社 類別 進庫量 單價");printf("\n\n (類別:哲學(xué),文學(xué),教育,藝術(shù),科學(xué),教材,小說,其它)\n (書號:(XXX) )\n"); for (;hitkey!=27;)//如果輸入一組數(shù)據(jù)后敲了回車鍵則循環(huán)輸入 { if (n!=0)printf("請輸入:\n");//從第二次輸入開始提示請輸入 scanf("%s%s%s%s%s%d%f",shuhao,name,author,chuban,kind,&xcl,&price); fprintf(fp,"%-8s%-9s%-14s%-16s%-18s%-7d%-8.2f\n",shuhao,name,author,chuban,kind,xcl,price);printf("繼續(xù)輸入請按回車\n結(jié)束輸入請按Esc\n");n++;hitkey=getch();//記錄敲擊進來的鍵 for (;hitkey!=13&&hitkey!=27;)//13:\r回車 27:ESC退出 hitkey=getch();//敲擊錯誤可重復(fù)敲擊 }fclose(fp);printf("\n保存成功,按任意鍵返回上一層!");getch();tsgxx();//返回上一層
}void shanchu()//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~刪除圖書信息
{ struct library *head=NULL;struct library *p,*p1,*p2;int txcl=0,n=0,j,i;float tprice=0;char tname[20]={'\0'},tauthor[20]={'\0'},tchuban[20]={'\0'},tkind[20]={'\0'},ttname[20]={'\0'},tshuhao[20]={'\0'};char hitkey;FILE *fp;if ((fp=fopen("library.txt","r"))==NULL)//打開文件{ system ("cls");printf("\n庫存圖書為零!無法刪除圖書!\n請按任意鍵返回\n");getch();tsgxx();}else{ system ("cls");printf("\n請輸入你要刪除的書名:");//輸入刪除圖書書名scanf("%s",&ttname);printf("\n確認刪除請回車,取消請按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);)//讀文件夾信息,統(tǒng)計在庫圖書個數(shù){ j++;fscanf(fp,"%s%s%s%s%s%d%f",tshuhao,tname,tauthor,tchuban,tkind,&txcl,&tprice);}fclose(fp);fp=fopen("library.txt","r");for (i=1;i<j;i++){ fscanf(fp,"%s%s%s%s%s%d%f",tshuhao,tname,tauthor,tchuban,tkind,&txcl,&tprice);if (strcmp(ttname,tname))//比較名字,將不同名字的信息復(fù)制到鏈表 //??? { n++;//相同返回值為0不執(zhí)行if語句繼續(xù)循環(huán),不同則執(zhí)行直到將所有不同的書名建立成鏈表if (n==1)//建立鏈表{ p1=p2=(struct library*)malloc(LEN);head=p1;}else{ p2->next=p1;p2=p1;p1=(struct library*)malloc(LEN);//新建鏈表}strcpy(p1->shuhao,tshuhao);//復(fù)制書號strcpy(p1->name,tname);//復(fù)制書名strcpy(p1->author,tauthor);//復(fù)制作者名字strcpy(p1->chuban,tchuban);//復(fù)制出版社strcpy(p1->kind,tkind);//復(fù)制類別p1->xcl=txcl;//復(fù)制個數(shù)p1->price=tprice;//復(fù)制單價}}if (n==0)//如果圖書只有一項且這一項剛好和要刪除的相同{ head=NULL;}else//建立鏈表的最后剩余一個儲存空間,所以封底{p2->next=p1;p1->next=NULL;fclose(fp);}}fp=fopen("library.txt","w");//清空文件,只寫打開,然后關(guān)閉fclose(fp);fp=fopen("library.txt","a");//追加文件p=head;for (;p!=NULL;)//把鏈表內(nèi)容覆蓋到文件{fprintf(fp,"%-8s%-9s%-14s%-16s%-18s%-7d%-8.2f\n",p->shuhao,p->name,p->author,p->chuban,p->kind,p->xcl,p->price);p=p->next;}fclose(fp);//關(guān)閉文件system ("cls");printf("\n刪除成功 \n按任意鍵返回上一層\n");getch();//返回上一層tsgxx();
}void chaxunts()//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~查詢函數(shù)
{FILE *fp;char choose;int txcl=0,n=0,k=0,i,l;float tprice=0;char tname[20]={'\0'},tauthor[20]={'\0'},chazhao[20]={'\0'},tchuban[20]={'\0'},tshuhao[20]={'\0'},tkind[20]={'\0'};if ((fp=fopen("library.txt","r"))==NULL)//打開文件{ system ("cls");printf("\n記錄文件不存在!按任意鍵返回");getch();tsgxx();}l=kucungs();//獲得庫存圖書個數(shù)menu2();//提示輸入菜單 scanf("%s",chazhao);system ("cls");for (i=0;i<l;i++){ fscanf(fp,"%s%s%s%s%s%d%f",tshuhao,tname,tauthor,tchuban,tkind,&txcl,&tprice);//讀文件信息if(!strcmp(chazhao,tshuhao)||!strcmp(chazhao,tname)||!strcmp(chazhao,tauthor)||!strcmp(chazhao,tkind))//在庫存圖書里面模糊檢索 {if (k==0){printf("查詢結(jié)果:\n\n");printf("書號\t書名\t作者\t\t出版社\t\t類別\t\t現(xiàn)存量\t單價\n");}printf("%-8s%-9s%-14s%-16s%-18s%-7d%-8.2f\n",tshuhao,tname,tauthor,tchuban,tkind,txcl,tprice);k++;}}if (k==0)//沒有這本書 { system ("cls");printf("\n無符合記錄!\n");getch();tsgxx();}fclose(fp);getch();//返回tsgxx();
}void kucunxinxi()//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~顯示庫存圖書信息
{FILE *fp;int xcl=0,n=0,i=0,j=0;float price=0;char name[20]={'\0'},author[20]={'\0'},kind[20]={'\0'},chuban[20]={'\0'},shuhao[20]={'\0'};if ((fp=fopen("library.txt","r"))==NULL)//打開文件夾{system ("cls");printf("\n記錄文件不存在!");}n= kucungs();if (n==0){ system ("cls");printf("\n無任何記錄!");}fp=fopen("library.txt","r");//打開只讀文件system ("cls");printf("書號\t書名\t作者\t\t出版社\t\t類別\t\t庫存量\t單價\n");for (i=0;i<n;i++)//輸出所有在庫圖書信息{fscanf(fp,"%s%s%s%s%s%d%f",shuhao,name,author,chuban,kind,&xcl,&price);printf("%-8s%-9s%-14s%-16s%-18s%-7d%-8.2f\n",shuhao,name,author,chuban,kind,xcl,price);}fclose(fp);printf("\n按任意鍵返回\n");getch();//返回tsgxx();
}void menu3() //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~顯示借書系統(tǒng)主菜單
{system ("cls");printf("\n `~` `~` `~` `~` `~` `~` `~` `~` `~` `~` `~` `~` `~` `~` ");printf("\n\n 1.借書登記\n\n");printf("\n\n 2.還書登記\n\n");printf("\n\n 3.借閱情況查看\n\n");printf("\n\n 4.返回上一層\n\n");//printf("\n\n ^~^請按鍵選擇and回車確定哦 *·*\n");printf("\n `~` `~` `~` `~` `~` `~` `~` `~` `~` `~` `~` `~` `~` `~`\n "); return ;
}void jieshuxitong()//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~借書系統(tǒng)函數(shù)
{ void jieshu();void huanshu();void duzhexinxi();//函數(shù)聲明char choose;menu3();getchar();//吞掉一個顯示出menu3函數(shù)后的進行下一步的回車 scanf("%c",&choose);//選擇功能for (;;)switch(choose){ case '1': jieshu();break; case '2': huanshu();break;case '3': duzhexinxi();break;case '4': main1();break;}
}void jieshu()//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~借書函數(shù)
{FILE *fp,*fp3;struct library *head=NULL;struct library *p,*p1,*p2;int txcl=0,i,loop,zhenghao=0,n=0,k=0,t=0,flag=0;float tprice=0;char tname[20]={'\0'},tauthor[20]={'\0'},tchuban[20]={'\0'},tkind[20]={'\0'},tshuhao[20]={'\0'},ttname[20]={'\0'},mingzi[20]={'\0'},riqi[20]={'\0'},zname[20]={'\0'};char hitkey=0;system ("cls");{if ((fp=fopen("library.txt","r"))==NULL)//打開圖書館文件{system ("cls");printf("\n 圖書館無庫存!按任意鍵退出!");getch();exit (0);}else{{printf("\n請輸入借閱書名:\n請輸入:\n");//輸入書名scanf("%s",zname);k= kucungs();//統(tǒng)計圖書館文件個數(shù)for (i=0;i<k;i++)//讀入圖書館信息,存儲到鏈表{fscanf(fp,"%s%s%s%s%s%d%f",tshuhao,tname,tauthor,tchuban,tkind,&txcl,&tprice);n++;if (n==1){ p1=p2=(struct library*)malloc(LEN);head=p1;}else{ p2->next=p1;p2=p1;p1=(struct library*)malloc(LEN);//新建鏈表}strcpy(p1->shuhao,tshuhao);//復(fù)制書號 strcpy(p1->name,tname);//復(fù)制書名strcpy(p1->author,tauthor);//復(fù)制作者strcpy(p1->chuban,tchuban);//復(fù)制出版社strcpy(p1->kind,tkind);//復(fù)制類別p1->xcl=txcl;//復(fù)制現(xiàn)存量p1->price=tprice;//復(fù)制單價}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,"%-8s%-9s%-14s%-16s%-18s%-7d%-8.2f\n",p->shuhao,p->name,p->author,p->chuban,p->kind,p->xcl,p->price);p=p->next;}free(p);//把鏈表內(nèi)容覆蓋文件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請輸入:");//錄入讀者信息scanf("%d %s %s %s",&zhenghao,&mingzi[20],&riqi[20],&zname[20]);fprintf(fp3,"\n%-8d%-23s%-18s%-10s\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;)//把鏈表內(nèi)容覆蓋圖書館文件{fprintf(fp,"%-8s%-9s%-14s%-16s%-18s%-7d%-8.2f\n",p->shuhao,p->name,p->author,p->chuban,p->kind,p->xcl,p->price); p=p->next;}fclose(fp);fclose(fp3);printf("成功!按任意鍵返回\n");getch();//返回jieshuxitong();//調(diào)用借閱系統(tǒng)}}jieshuxitong();//調(diào)用借閱系統(tǒng)}elseprintf("此書已被借完!按任意鍵返回!");//否則輸出此書已被借完getch();//返回 jieshuxitong();//調(diào)用借閱系統(tǒng)}
}void huanshu()//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~還書函數(shù)
{FILE *fp,*fp3; struct reader *head=NULL;struct reader *p,*p1,*p2;struct library *lhead1=NULL;struct library *zp1,*lp1,*lp2;int txcl=0,i;float tprice=0;char tname[20]={'\0'},tauthor[20]={'\0'},tkind[20]={'\0'},tchuban[20]={'\0'},ttname[20]={'\0'},tshuhao[20]={'\0'};int ttzhenghao=0,tzhenghao=0,n=0,k=0,t=0,flag=0;char tmingzi[20]={'\0'},triqi[20]={'\0'},tzname[20]={'\0'},ttzname[20]={'\0'};char hitkey=0;system ("cls");{ if ((fp=fopen("reader.txt","r"))==NULL)//不存在讀者文件,則輸出不能還書{system ("cls");printf("\n 不存在借書者!按任意鍵退出!");getch();exit (0);}else{{ printf("\n請輸入讀者證號和書名:\n請輸入:"); scanf("%d %s",&ttzhenghao,ttzname);//輸入還書證號和書名k=duzhegs();//獲取讀者文件夾信息個數(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;//strcmp:將兩個字符串進行比較返回比較結(jié)果,相同返回0 }fclose(fp);fp=fopen("reader.txt","r");//打開讀者文件if(flag){ for (i=0;i<k;i++)//將讀者文件復(fù)制到鏈表{fscanf(fp,"%d%s%s%s\n ",&tzhenghao,tmingzi,triqi,tzname);//讀取文件信息 if(!((ttzhenghao==tzhenghao)&&!strcmp(ttzname,tzname))){ n++;if (n==1){ p1=p2=(struct reader*)malloc(LEN1);//新建鏈表開辟內(nèi)存 head=p1;//head指向第一個節(jié)點 }else{ p2->next=p1;p2=p1;p1=(struct reader*)malloc(LEN1);//新建鏈表}p1->zhenghao=tzhenghao;//復(fù)制證號strcpy(p1->mingzi,tmingzi);//復(fù)制讀者名字 strcpy(p1->riqi,triqi);//復(fù)制日期 strcpy(p1->zname,tzname);//復(fù)制書名 }}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;)//把鏈表內(nèi)容覆蓋讀者文件 { fprintf(fp,"\n%-8d%-23s%-18s%-10s\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=kucungs();//獲取圖書館文件個數(shù)for (i=0;i<k;i++)//將圖書館文件復(fù)制到鏈表{ fscanf(fp3,"%s%s%s%s%s%d%f",tshuhao,tname,tauthor,tchuban,tkind,&txcl,&tprice);//讀取信息 n++; if (n==1) { lp1=lp2=(struct library*)malloc(LEN);//新建鏈表lhead1=lp1;}else{ lp2->next=lp1;lp2=lp1;lp1=(struct library*)malloc(LEN);//新建鏈表}strcpy(lp1->shuhao,tshuhao);//復(fù)制書號 strcpy(lp1->name,tname);//復(fù)制書名 strcpy(lp1->author,tauthor);//復(fù)制作者 strcpy(lp1->chuban,tchuban);//復(fù)制出版社 strcpy(lp1->kind,tkind);//復(fù)制類別 lp1->xcl=txcl; //復(fù)制現(xiàn)存量 lp1->price=tprice;//復(fù)制單價 }if (n==0){lhead1=NULL;}else { lp2->next=lp1; lp1->next=NULL; fclose(fp3); }}}zp1=lhead1; for (;zp1!=NULL;){ if(!(strcmp(zp1->name,ttzname)))//尋找書名相同 ++(zp1->xcl);//現(xiàn)存量加1 zp1=zp1->next;}fp3=fopen("library.txt","w");//清空圖書館文件fclose(fp);fp3=fopen("library.txt","a");//追加信息zp1=lhead1;for (;zp1!=NULL;)//把鏈表內(nèi)容覆蓋圖書館文件{fprintf(fp3,"%-8s%-9s%-14s%-16s%-18s%-7d%-8.2f\n", zp1->shuhao,zp1->name,zp1->author,zp1->chuban,zp1->kind,zp1->xcl,zp1->price); zp1=zp1->next;}fclose(fp3);getch();//返回jieshuxitong();//調(diào)用借閱系統(tǒng)}elseprintf("不存在此信息!按任意鍵返回!");getch();//返回jieshuxitong();//調(diào)用借閱系統(tǒng)
}void duzhexinxi()//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~顯示讀者借書情況函數(shù)
{FILE *fp;int zhenghao=0,xcl=0,n=0,i=0,j=0;char mingzi[20]={'\0'},riqi[20]={'\0'},zname[20]={'\0'};if ((fp=fopen("reader.txt","r"))==NULL)//打開讀者文件夾{system ("cls");printf("\n記錄文件不存在!");}n=duzhegs();if (n==0){ system ("cls");printf("\n無任何記錄!");}fp=fopen("reader.txt","r");system ("cls");printf("\n證號\t讀者姓名\t\t還書日期\t書名\n");for (i=0;i<n;i++)//輸出文件信息{ fscanf(fp,"%d%s%s%s\n ",&zhenghao,mingzi,riqi,zname); printf("\n%-8d%-23s%-18s%-10s\n", zhenghao,mingzi,riqi,zname);}fclose(fp);printf("\n按任意鍵返回\n");getch();//返回jieshuxitong();//調(diào)用借閱系統(tǒng)
}void begin()
{char num;printf("\n\n\n\n 教師端登錄請按 1 \n\n 學(xué)生端登錄請按 2 \n\n");scanf("%c",&num);getchar();
}int main()//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~主函數(shù)調(diào)用
{system("color 3F");//藍色背景白色字體 begin();main1();return 0;
}
——2018.12.28——by Z方 的 '^舊時光~'
總結(jié)
以上是生活随笔為你收集整理的C语言 图书管理系统(课程设计)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。