图书馆管理系统 c语言编写
C语言图书馆管理系统1

#include<stdio.h>#include"string.h"#define Maxsize 10struct book{long num;char name[30];char author[20];char press[30];float price;}BOOKLIST[Maxsize];void input(int *);void search_num(int);void search_author(int);void search_press(int);void search_name(int);void Delete(int *);int main(){int i;int count=0;printf("\t\t---------------------------------------\n");printf("\t\t\t欢迎使用图书馆管理系统\n");printf("\t\t---------------------------------------\n");do{printf("\n");printf("\t\t\t1---:添加一本图书\n");printf("\t\t\t2---:显示某本图书信息\n");printf("\t\t\t3---:查找某作者编写图书信息\n");printf("\t\t\t4---:查找某出版社图书信息\n");printf("\t\t\t5---:查找某本书的信息\n");printf("\t\t\t6---:删除某本书的信息\n");printf("\t\t\t7---:退出\n");scanf("%d",&i);switch(i){case 1:input(&count);break;case 2:search_num(count);break;case 3:search_author(count);break;case 4:search_press(count);break;case 5:search_name(count);break;case 6:Delete(&count);break;case 7:break;default:printf("错误选择!请重选:\n");break; }}while(i!=7);return 0;}void input(int *count){int i,in_num;if(*count==Maxsize){printf("空间已满!");return;}printf("请输入编号:");scanf("%d",&in_num);for(i=0;i<*count;i++)if(BOOKLIST[i].num==in_num){printf("已经有相同编号:");return;}{BOOKLIST[i].num=in_num;printf("please enter name:");scanf("%s",BOOKLIST[i].name);printf("please enter author:");scanf("%s",BOOKLIST[i].author);printf("please enter press:");scanf("%s",BOOKLIST[i].press);printf("please enter num:");scanf("%ld",&BOOKLIST[i].num);printf("please enter price:");scanf("%f",&BOOKLIST[i].price);(*count)++;}}void search_num(int count){int i,num;printf("请输入要查询的编号:");scanf("%d",&num);for(i=0;i<count;i++)if(BOOKLIST[i].num==num){printf("book name:%s\n",BOOKLIST[i].name);printf("book author:%s\n",BOOKLIST[i].author);printf("book press:%s\n",BOOKLIST[i].press);printf("book price:%f\n",BOOKLIST[i].price);printf("book num:%ld\n",BOOKLIST[i].num);}elseprintf("没有查询到!\n");}void search_author(int count){int i;char author[20];printf("请输入要查询的作者姓名:");scanf("%s",author);for(i=0;i<count;i++)if(strcmp(BOOKLIST[i].author,author)==0) {printf("book name:%s\n",BOOKLIST[i].name); printf("book author:%s\n",BOOKLIST[i].author); printf("book press:%s\n",BOOKLIST[i].press); printf("book price:%f\n",BOOKLIST[i].price); printf("book num:%ld\n",BOOKLIST[i].num);}elseprintf("没有查询到!\n");}void search_press(int count){int i;char press[20];printf("请输入要查询的出版社:");scanf("%s",press);for(i=0;i<count;i++)if(strcmp(BOOKLIST[i].press,press)==0) {printf("book name:%s\n",BOOKLIST[i].name); printf("book author:%s\n",BOOKLIST[i].author); printf("book press:%s\n",BOOKLIST[i].press); printf("book price:%f\n",BOOKLIST[i].price); printf("book num:%ld\n",BOOKLIST[i].num); }elseprintf("没有查询到!\n");}void search_name(int count){int i;char name[30];printf("请输入要查询的书名:");scanf("%s",name);for(i=0;i<count;i++)if(strcmp(BOOKLIST[i].name,name)==0) {printf("book name:%s\n",BOOKLIST[i].name); printf("book author:%s\n",BOOKLIST[i].author); printf("book press:%s\n",BOOKLIST[i].press); printf("book price:%f\n",BOOKLIST[i].price); printf("book num:%ld\n",BOOKLIST[i].num);}elseprintf("没有查询到!\n");}void Delete(int *count){int i,j,flag=1;char name[30];printf("请输入要删除的书名:");scanf("%s",name);for(i=0;i<*count&&flag;i++){if(strcmp(BOOKLIST[i].name,name)==0) {for(j=i;j<*count-1;j++)BOOKLIST[j]=BOOKLIST[j+1];flag=0;(*count)--;}elseprintf("没有查询到可以删除的书名!\n"); }}。
图书馆管理系统 c语言编写

#include "stdio.h"#include "stdlib.h"#include "conio.h"#include "string.h"#include "math.h"#define LEN sizeof(struct library)#define LEN1 sizeof(struct reader)#define NULL 0struct library//图书馆结构体{int shuhao,xcl;char name[20],author[20],chuban[20];struct library *next;};struct reader//读者结构体{int zhenghao;char mingzi[20],riqi[20],zname[20];struct reader *next;};void mainmenu() //显示主菜单{ system ("cls");printf("\n");printf("\t\t\t\t####################\n\n"); printf("\t\t\t\t 1.图书馆信息\n\n");printf("\t\t\t\t 2.借阅系统\n\n");printf("\t\t\t\t 3.退出系统\n\n");printf("\t\t\t 请按键选择,回车确定\n"); printf("\t\t\t\t######################\n"); printf("\n");return ;}void menu1() //显示图书馆信息菜单{ system ("cls");printf("");printf("\t\t\t\t####################\n\n"); printf("\t\t\t\t 1.采编入库\n\n");printf("\t\t\t\t 2.清除库存\n\n");printf("\t\t\t\t 3.图书查询\n\n");printf("\t\t\t\t 4.库存一览\n\n");printf("\t\t\t\t 5.返回上一层\n\n");printf("\t\t\t 请按键选择,回车确定\n");printf("\t\t\t\t#######################\n");printf("\n");return ;}void menu2() //显示查询菜单{ system ("cls");//printf("");printf("\t\t\t\t#######################\n");printf("\t\t\t\t 1.书号查询\n\n");printf("\t\t\t\t 2.书名查询\n\n");printf("\t\t\t\t 3.作者查询\n\n");printf("\t\t\t\t 4.出版社查询\n\n");printf("\t\t\t 请按键选择,回车确定\n");printf("\t\t\t\t#######################\n");//printf("");return ;}void main()//主函数,调用main1{void main1();main1();}void main1()//main1函数{void tsgxx();//声明void jieshuxitong();//声明char choose;mainmenu();scanf("%c",&choose);switch(choose)//功能函数选择{ case '1':tsgxx();break;case '2':jieshuxitong();break;case '3':system ("cls");printf("\n\n\n\n\n\n\n\n\n\t\t\t Byebye...");printf("\n\n\n\n\n\n\n\n\n\t\t\t 欢迎使用本软件!!!");getch();exit(0);system ("cls");break;}}void tsgxx()//图书馆信息函数{ void tsjinku();void shanchu();void chaxunts();void xianshikucun();//函数声明char choose;menu1();//调用菜单函数scanf("%c",&choose);scanf("%c",&choose);for (;;)switch(choose)//功能函数选择{ case '1':tsjinku();break;case '2':shanchu();break;case '3':chaxunts();break;case '4':xianshikucun();break;case '5':main1();break;}}int tjzs()//统计文本个数函数{ FILE *fp;int tshuhao=0,txcl=0,n;char tname[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);//返回个数}int tjdzzs()//统计文本个数函数{ 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);//关闭文件return (n);//返回个数}void tsjinku()//图书进库函数{ FILE *fp;int shuhao=0,xcl=0,n=0;char name[20]={'\0'},author[20]={'\0'},chuban[20]={'\0'};char hitkey;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;)//循环输入{ 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("继续输入请按回车,结束输入请按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();//返回上一层}void shanchu()//删除图书信息函数{ struct library *head=NULL;struct library *p,*p1,*p2;int tshuhao=0,txcl=0,n=0,j,i;char tname[20]={'\0'},tauthor[20]={'\0'},tchuban[20]={'\0'}, ttname[20]={'\0'};char hitkey;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);)//读文件夹信息,统计个数{ 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=(struct library*)malloc(LEN);head=p1;}else{ p2->next=p1;p2=p1;p1=(struct library*)malloc(LEN);//新建链表}p1->shuhao=tshuhao;//复制书号strcpy(p1->name,tname);//复制书名strcpy(p1->author,tauthor);//复制作者名子strcpy(p1->chuban,tchuban);//复制出版社p1->xcl=txcl;//复制个数}}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();}void chaxunts()//查询函数{FILE *fp;char choose;int ttshuhao=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();//获得文件个数menu2();//调用菜单函数scanf("%c",&choose);scanf("%c",&choose);//选择查询方式if (choose=='5')return;else if (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,tch uban))//输出查询信息{if (k==0){printf("\t\t\t\t查询结果:\n\n");printf("\t 书号书名作者出版社现存量\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();}void xianshikucun()//现实库存信息{FILE *fp;int shuhao=0,xcl=0,n=0,i=0,j=0;char name[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();}void menu3() //显示借书系统主菜单{ system ("cls");//printf("*********************************************************************** *********");printf("\t\t\t\t#######################\n");printf("\t\t\t\t 1.借书登记\n\n");printf("\t\t\t\t 2.还书登记\n\n");printf("\t\t\t\t 3.借阅情况查看\n\n");printf("\t\t\t\t 4.返回上一层\n\n");printf("\t\t\t 请按键选择,回车确定\n");printf("\t\t\t\t#######################\n");//printf("*********************************************************************** *********");return ;}void jieshuxitong()//借书系统函数{ void jieshu();void huanshu();void duzheyilang();//函数声明char choose;menu3();scanf("%c",&choose);scanf("%c",&choose);//选择功能for (;;)switch(choose)//调用函数{ case '1':jieshu();break;case '2':huanshu();break;case '3':duzheyilang();break;case '4':main1();break;}}void jieshu()//借书函数{FILE *fp,*fp3;struct library *head=NULL;struct library *p,*p1,*p2;int tshuhao=0,txcl=0,i,loop,zhenghao=0,n=0,k=0,t=0,flag=0;char tname[20]={'\0'},tauthor[20]={'\0'},tchuban[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\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();//统计图书馆文件个数for (i=0;i<k;i++)//读入图书馆信息,存储到链表{fscanf(fp,"%d%s%s%s%d",&tshuhao,tname,tauthor,tchuban,&txcl);n++;if (n==1){ p1=p2=(struct library*)malloc(LEN);head=p1;}else{ p2->next=p1;p2=p1;p1=(struct library*)malloc(LEN);//新建链表}p1->shuhao=tshuhao;//复制书号strcpy(p1->name,tname);//复制书名strcpy(p1->author,tauthor);//复制作者strcpy(p1->chuban,tchuban);//复制出版社p1->xcl=txcl;//复制现存量}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;//现存量减1(p->xcl)--;}p=p->next;}if(flag&&(loop>0))//存在借书书名且现存量大于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))//存在借书书名且现存量大于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();}}void huanshu()//还书函数{FILE *fp,*fp3;struct reader *head=NULL;struct reader *p,*p1,*p2;struct library *lhead1=NULL;struct library *zp1,*lp1,*lp2;int tshuhao=0,txcl=0,i;char tname[20]={'\0'},tauthor[20]={'\0'},tchuban[20]={'\0'}, ttname[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\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();//获取读者文件夹信息个数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=(struct reader*)malloc(LEN1);//新建链表head=p1;}else{ p2->next=p1;p2=p1;p1=(struct reader*)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();//获取图书馆文件个数for (i=0;i<k;i++)//将图书馆文件复制到链表{fscanf(fp3,"%d%s%s%s%d",&tshuhao,tname,tauthor,tchuban,&txcl);//读取信息n++;if (n==1){ lp1=lp2=(struct library*)malloc(LEN);//新建链表lhead1=lp1;}else{ lp2->next=lp1;lp2=lp1;lp1=(struct library*)malloc(LEN);//新建链表}lp1->shuhao=tshuhao;//复制书号strcpy(lp1->name,tname);//复制书名strcpy(lp1->author,tauthor);//复制作者strcpy(lp1->chuban,tchuban);//复制出版社lp1->xcl=txcl; //复制现存量}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);//现存量加1zp1=zp1->next;}fp3=fopen("library.txt","w");//清空图书馆文件fclose(fp);fp3=fopen("library.txt","a");//追加信息zp1=lhead1;for (;zp1!=NULL;)//把链表内容覆盖图书馆文件{fprintf(fp3,"%d %s %s %s %d \n",zp1->shuhao,zp1->name,zp1->author,zp1->chuban,zp1->xcl);//录入信息zp1=zp1->next;}fclose(fp3);getch();//返回jieshuxitong();}elseprintf("不存在此信息!按任意键返回!");getch();//返回jieshuxitong();}void duzheyilang()//显示借书情况函数{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\n\n\n\n\n\n\n\t\t\t记录文件不存在!");}n=tjdzzs();if (n==0){ system ("cls");printf("\n\n\n\n\n\n\n\n\n\t\t\t无任何记录!");}fp=fopen("reader.txt","r");system ("cls");printf("************************************************************************* *******");printf("\t 证号读者姓名还书日期书名\n");printf("************************************************************************* *******");for (i=0;i<n;i++)//输出文件信息{fscanf(fp,"%d%s%s%s\n ",&zhenghao,mingzi,riqi,zname);printf("\t %-4d %-8s %-8s %-8s \n", zhenghao,mingzi,riqi,zname);}fclose(fp);printf("\t\t\t\t按任意键返回\n");getch();//返回jieshuxitong();}。
原创c语言图书馆管理系统源代码

原创C语言图书馆管理系统源代码介绍图书馆作为一个重要的知识储备和学习场所,必须进行有效的管理和组织。
使用C语言编写的图书馆管理系统可以帮助图书馆实现自动化的借阅、归还和管理功能。
本文将介绍一个原创的C语言图书馆管理系统的源代码。
功能概述这个图书馆管理系统具有以下核心功能: - 图书管理:包括添加图书、删除图书、查询图书等操作。
- 借阅管理:可以进行借阅操作,记录借阅者和借阅时间。
- 归还管理:可以进行归还操作,并更新图书的可借状态。
- 用户管理:管理借阅者的信息,包括添加用户、删除用户、查询用户等操作。
数据结构设计该图书馆管理系统使用了以下几种数据结构: 1. 图书(Book)结构体:包含图书的ID、书名、作者、可借状态等字段。
2. 用户(User)结构体:包含用户的ID、姓名、地址等字段。
3. 借阅记录(BorrowRecord)结构体:包含借阅者ID、图书ID、借阅时间等字段。
系统流程整个系统的流程可以分为以下几个步骤: 1. 用户打开系统,进入主菜单。
2. 用户选择不同的功能选项(如图书管理、借阅管理、用户管理等)。
3. 根据用户选择的功能,进入相应的功能界面。
4. 用户可以根据提示,输入相应的信息进行图书管理、借阅管理或用户管理操作。
5. 用户完成操作后,可以选择返回主菜单或退出系统。
代码实现以下是一个简化版的C语言图书馆管理系统的源代码:```c #include <stdio.h>// 定义结构体 struct Book { int id; char name[50]; char author[50]; int isAvailable; };struct User { int id; char name[50]; char address[100]; };struct BorrowRecord { int userId; int bookId; char borrowDate[20]; };// 函数声明 void addBook(); void deleteBook(); void searchBook(); void borrowBook(); void returnBook(); void addUser(); void deleteUser(); void searchUser();int main() { int choice;do {// 显示主菜单printf(\。
图书馆管理系统C语言_附完整源码

if (m == 5) { bnode* temp; head = NULL; sum = ReadSum(); head=ReadFile(sum); SelectSort(sum, head); //OutToFileArray(temp, sum); system("pause"); system("cls"); menu(); cin >> m; } if (m == 6) { bnode* temp; head = NULL; sum = ReadSum(); head=ReadFile(sum); BubbleSortName(sum, head); //OutToFileArray(temp, sum); system("pause"); system("cls"); menu(); cin >> m; } if (m == 7) { bnode* temp; head = NULL; sum = ReadSum(); head=ReadFile(sum); SelectSortWord(sum, head); //OutToFileArray(temp, sum); system("pause"); system("cls"); menu(); cin >> m; }
图书馆管理系统
#include< iostream > #include< string > #include< fstream > using namespace std; typedef struct node { char name[20]; char writter[30]; char publish[30]; int date; int word; double price; int number; struct node* next; }bnode; bnode* head = NULL; int sum = 1; void WriteSum(int mysum); int ReadSum(); void menu(); //对书库的操作 void InputInfo(); void SearchBook(bnode* myhead); void ChangeBook(bnode* myhead); int DeleteBook(bnode* myhead); //文件操作 void OutputToFile(); void OutToFileArray(bnode *temp, int mysum); bnode* ReadFile(int mysum); 在屏幕上 //排序 bnode* SelectSort(int mysum, bnode* myhead); bnode* SelectSortWord(int mysum, bnode* myhead); bnode* SelectSortDate(int mysum, bnode* myhead); bnode* BubbleSortName(int mysum, bnode* myhead);
C语言 图书馆信息管理系统

#include〈iostream〉#include<fstream〉#include〈conio.h〉using namespace std;class Librarian //图书管理员类{public:Librarian();Librarian(int n,int j,char na[20],int w );int getnumber();int getjobage();char *getname();int getwages();void resetjobage(int j);void resetwages(int w);void resetname(char na[20]);private:int number;int jobage;char name[20];int wages;};Librarian::Librarian() //其函数的实现{number=0;char b[20]="no one”;jobage=0;strcpy(name,b);}Librarian::Librarian(int n,int j,char na[20],int w) {number=n;jobage=j;strcpy(name,na);wages=w;}int Librarian::getjobage(){return jobage;}char *Librarian::getname(){return name;}int Librarian::getnumber(){return number;}int Librarian::getwages(){return wages;}void Librarian::resetjobage(int j){jobage=j;}void Librarian::resetname(char na[20]){strcpy(name,na);}void Librarian::resetwages(int w){wages=w;}class reader //读者类{private:int number;int age;char name[20];char borrowbook[20];public:reader();reader(int c,int a,char b[20],char e[20]);int getnumber();int getage();char *getname();char * getborrowbook();void reworkborrowbook(char a[20]);};reader::reader() //其函数的实现{char a[20]="没有人”;char c[20]=”没有借书";number=0;age=0;}reader::reader(int a,int c,char d[20],char e[20]) {number=a;age=c;strcpy(name,d);strcpy(borrowbook,e);}int reader::getnumber(){return number;}int reader::getage(){return age;}char *reader::getname(){return name;}char * reader::getborrowbook(){return borrowbook;}void reader::reworkborrowbook(char a[20]){strcpy(borrowbook,a);}struct book //图书的结构体{int num;char name[20];char writer[20];};void outbookinf() //输出所有图书信息{int i;ifstream infile(”allbook。
c语言图书管理系统

int86(0x16, &rg,&rg);
return rg。h。ah;
}
int choose(int bot,int top)/*根据Y的值选择操作*/
{
int ky,y = 7;
gotoxy(30,bot);
do
{
ky = key();
switch(ky)
{
case Key_UP:
gotoxy(x + 1, y + high - 3);
for (i = 1; i < width - 1; i++)
{
putchar(0xc4);
}
gotoxy(x + width—1,y + high —1);
putchar(0xd9);
}
int key()/*读键盘*/
{
union REGS rg;
int halfw(int sum,bbasic binfo[100],char *find);
void sta();
void blist();
void bmoney();
int main(void)
{
menu();
}
void menu()
{
int y;
_window();/*显示窗口*/
words();/*显示菜单文字*/
gotoxy(30,16);
cprintf(”Book Statistic");
gotoxy(30,19);
cprintf(”Exit”);
gotoxy(35,22);
textcolor(LIGHTGRAY);
c语言图书馆管理系统

C源代码如下:view plaincopy to clipboardprint?#include<stdio.h>#include<stdlib.h>#include<string.h>struct book{char book_name[30];int bianhao;double price;char author[20];char state[20];char name[20];char sex[10];int xuehao;struct book *book_next;};struct club{char name[20];char sex[10];int xuehao;char borrow[30];struct club *club_next;};void Print_Book(struct book *head_book);/*浏览所有图书信息*/void Print_Club(struct club *head_club);/*浏览所有会员信息*/struct book *Create_New_Book();/*创建新的图书库,图书编号输入为0时结束*/ struct book *Search_Book_bianhao(int bianhao,struct book *head_book);struct book *Search_Book_name(char *b_name,struct book *head_book);struct book *Search_Book_price(double price_h,double price_l,struct book *head_book);struct book *Insert_Book(struct book *head_book,struct book *stud_book);/*增加图书,逐个添加*/struct book *Delete_Book(struct book *head_book,int bianhao);/*删除图书*/ struct club *Create_New_Club();struct club *Search_Club_xuehao(int xuehao,struct club *head_club);struct club *Search_Club_name(char *c_name,struct club *head_club);struct club *Insert_Club(struct club *head_club,struct club *stud_club); struct club *Delete_Club(struct club *head_club,int xuehao);struct book *Lent_Book(int bianhao,int xuehao,struct book *head_book,struct club *head_club);struct book *back(int bianhao,int xuehao,struct book *head_book,struct club *head_club);int main(){struct book *head_book,*p_book;char book_name[30],name[20],author[20],sex[10];int bianhao;double price,price_h,price_l;int size_book=sizeof(struct book);int m=1,n=1,f;char *b_name,*c_name;struct club *head_club,*p_club;int xuehao;int size_club=sizeof(struct club);int choice;printf("\n欢迎您第一次进入图书管理系统!\n\n");printf("----->[向导]----->[新建图书库]\n\n");printf("注意:当输入图书编号为0时,进入下一步.\n\n");head_book=Create_New_Book();system("cls");printf("\n欢迎您第一次进入图书管理系统!\n\n");printf("----->[向导]----->[新建会员库]\n\n");printf("注意:当输入会员学号为0时,进入主菜单.\n\n");head_club=Create_New_Club();system("cls");do{printf("\n\t\t\t〓〓〓〓〓图书管理系统〓〓〓〓〓\n\n");printf("\n");printf("\t\t\t[1]:借书办理\t");printf(" [6]:还书办理\n");printf("\n");printf("\t\t\t[2]:查询图书\t");printf(" [7]:查询会员\n");printf("\t\t\t[3]:添加图书\t");printf(" [8]:添加会员\n");printf("\t\t\t[4]:删除图书\t");printf(" [9]:删除会员\n");printf("\t\t\t[5]:遍历图书\t");printf("[10]:遍历会员\n\n"); printf("\t\t\t〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓\n\n");printf("\t\t\t0:退出\n\n");printf("请选择<0~10>:");scanf("%d",&choice);switch(choice){case 1:printf("\n\t\t\t〓〓〓〓〓图书管理系统〓〓〓〓〓\n\n"); printf("输入所借图书编号:\n");scanf("%d",&bianhao);printf("输入借书人的学号:\n");scanf("%d",&xuehao);head_book=Lent_Book(bianhao,xuehao,head_book,head_club);system("cls");printf("\n借阅成功!\n\n");printf("相关信息如下:\n\n");head_book=Search_Book_bianhao(bianhao,head_book);break;case 2:system("cls");printf("\n\t\t\t〓〓〓〓〓图书管理系统〓〓〓〓〓\n\n");printf("1.按编号查询\n\n");printf("2.按名称查询\n\n");printf("3.按价格区间查询\n\n");printf("0.返回主菜单\n\n");printf("请选择:");scanf("%d",&f);if(f==1){printf("请输入查询图书编号:");scanf("%d",&bianhao);printf("相关信息如下:\n\n");head_book=Search_Book_bianhao(bianhao,head_book);break;}else if(f==2){b_name=book_name;getchar();printf("请输入查询图书名称:");gets(b_name);printf("相关信息如下:\n\n");head_book=Search_Book_name(b_name,head_book);break;}else if(f==3){printf("请输入最高价格:");scanf("%lf",&price_h);printf("请输入最低价格:");scanf("%lf",&price_l);printf("相关信息如下:\n\n");head_book=Search_Book_price(price_h,price_l,head_book); break;}else if(f==0){break;}break;case 6:printf("\n\t\t\t〓〓〓〓〓图书管理系统〓〓〓〓〓\n\n"); printf("输入所还图书编号:\n");scanf("%d",&bianhao);printf("输入还书人的学号:\n");scanf("%d",&xuehao);head_book=back(bianhao,xuehao,head_book,head_club);system("cls");printf("\n归还成功!\n\n");printf("相关信息如下:\n\n");head_book=Search_Book_bianhao(bianhao,head_book);break;case 3:system("cls");printf("\n\t\t\t〓〓〓〓〓图书管理系统〓〓〓〓〓\n\n"); printf("请输入图书名称:");scanf("%s",book_name);printf("请输入图书编号:");scanf("%d",&bianhao);printf("请输入单价:");scanf("%lf",&price);printf("请输入作者名字:");scanf("%s",author);printf("\n");struct book *ptr_b;for(ptr_b=head_book;ptr_b;ptr_b=ptr_b->book_next){if(ptr_b->bianhao==bianhao){printf("此编号图书已存在\n");m=0;break;}}if(m){p_book=(struct book *)malloc(size_book);strcpy(p_book->book_name,book_name);p_book->bianhao=bianhao;p_book->price=price;p_book->xuehao=0;strcpy(p_book->author,author);strcpy(p_book->state,"存在");strcpy(p_book->sex,"待定");strcpy(p_book->name,"待定");head_book=Insert_Book(head_book,p_book);printf("\n添加图书成功!\n\n");}break;case 4:system("cls");printf("\n\t\t\t〓〓〓〓〓图书管理系统〓〓〓〓〓\n\n"); printf("输入删除图书编号:\n");scanf("%d",&bianhao);head_book=Delete_Book(head_book,bianhao);printf("\n删除图书成功!\n\n");break;case 5:system("cls");printf("\n\t\t\t〓〓〓〓〓图书管理系统〓〓〓〓〓\n\n"); Print_Book(head_book);break;case 7:system("cls");printf("\n\t\t\t〓〓〓〓〓图书管理系统〓〓〓〓〓\n\n"); printf("1.按学号查询\n\n");printf("2.按姓名查询\n\n");printf("0.返回主菜单\n\n");printf("请选择:");scanf("%d",&f);if(f==1){printf("请输入查询会员学号:");scanf("%d",&xuehao);printf("相关信息如下:\n\n");head_club=Search_Club_xuehao(xuehao,head_club);break;}else if(f==2){c_name=name;getchar();printf("请输入查询会员姓名:");gets(c_name);printf("相关信息如下:\n\n");head_club=Search_Club_name(c_name,head_club);break;}else if(f==0){break;}break;printf("请输入查询会员学号:\n");scanf("%d",&xuehao);printf("相关信息如下:\n\n");break;case 8:system("cls");printf("\n\t\t\t〓〓〓〓〓图书管理系统〓〓〓〓〓\n\n"); printf("请输入会员名字:");scanf("%s",name);printf("请输入会员性别:");scanf("%s",sex);printf("请输入会员学号:");scanf("%d",&xuehao);printf("\n");struct club *ptr_c;for(ptr_c=head_club;ptr_c;ptr_c=ptr_c->club_next){if(ptr_c->xuehao==xuehao){printf("此学号会员已存在\n");n=0;break;}}if(n){p_club=(struct club *)malloc(sizeof(struct club));strcpy(p_club->name,name);strcpy(p_club->sex,sex);p_club->xuehao=xuehao;strcpy(p_club->borrow,"暂无");head_club=Insert_Club(head_club,p_club);printf("\n添加会员成功!\n\n");}break;case 9:system("cls");printf("\n\t\t\t〓〓〓〓〓图书管理系统〓〓〓〓〓\n\n"); printf("输入要删除会员学号:\n");scanf("%d",&xuehao);head_club=Delete_Club(head_club,xuehao);printf("\n删除会员成功!\n\n");break;case 10:system("cls");printf("\n\t\t\t〓〓〓〓〓图书管理系统〓〓〓〓〓\n\n"); Print_Club(head_club);break;case 0:system("cls");printf("\n\t\t\t〓〓〓〓〓图书管理系统〓〓〓〓〓\n\n"); printf("\n谢谢您的使用!\n\n");break;}}while(choice!=0);return 0;}struct book *Create_New_Book(){struct book *head_book,*p_book;int bianhao;double price;char book_name[30],author[20];int size_book=sizeof(struct book);head_book=NULL;printf("请输入图书名称:");scanf("%s",book_name);printf("请输入图书编号:");scanf("%d",&bianhao);printf("请输入单价:");scanf("%lf",&price);printf("请输入作者名字:");scanf("%s",author);printf("\n");while(bianhao!=0){p_book=(struct book *)malloc(size_book);strcpy(p_book->book_name,book_name);p_book->bianhao=bianhao;p_book->price=price;p_book->xuehao=0;strcpy(p_book->author,author);strcpy(p_book->state,"存在");strcpy(p_book->sex,"待定");strcpy(p_book->name,"待定");head_book=Insert_Book(head_book,p_book);printf("请输入图书名称:");scanf("%s",book_name);printf("请输入图书编号:");scanf("%d",&bianhao);printf("请输入单价:");scanf("%lf",&price);printf("请输入作者名字:");scanf("%s",author);printf("\n");}return head_book;}struct book *Search_Book_bianhao(int bianhao,struct book *head_book) {struct book *ptr_book;int flag=0;for(ptr_book=head_book;ptr_book;ptr_book=ptr_book->book_next){if(ptr_book->bianhao==bianhao){printf("图书编号:%d\n",ptr_book->bianhao);printf("图书名称:%s\n",ptr_book->book_name);printf("图书单价:%.2lf\n",ptr_book->price);printf("图书作者:%s\n",ptr_book->author);printf("存在状态:%s\n",ptr_book->state);printf("借书人姓名:%s\n",ptr_book->name);printf("借书人性别:%s\n",ptr_book->sex);printf("学号:%d\n",ptr_book->xuehao);printf("\n");flag++;}}if(flag==0){printf("暂无此图书信息!\n\n");}return head_book;}struct book *Search_Book_name(char *b_name,struct book *head_book) {struct book *ptr_book;int flag=0;for(ptr_book=head_book;ptr_book;ptr_book=ptr_book->book_next){if(strcmp(ptr_book->book_name,b_name)==0){printf("图书编号:%d\n",ptr_book->bianhao);printf("图书名称:%s\n",ptr_book->book_name);printf("图书单价:%.2lf\n",ptr_book->price);printf("图书作者:%s\n",ptr_book->author);printf("存在状态:%s\n",ptr_book->state);printf("借书人姓名:%s\n",ptr_book->name);printf("借书人性别:%s\n",ptr_book->sex);printf("学号:%d\n",ptr_book->xuehao);printf("\n");flag++;}}if(flag==0){printf("暂无此图书信息!\n\n");}return head_book;}struct book *Search_Book_price(double price_h,double price_l,struct book *head_book){struct book *ptr_book;int flag=0;for(ptr_book=head_book;ptr_book;ptr_book=ptr_book->book_next){if((ptr_book->price>=price_l)&&(ptr_book->price<=price_h)){printf("图书编号:%d\n",ptr_book->bianhao);printf("图书名称:%s\n",ptr_book->book_name);printf("图书单价:%.2lf\n",ptr_book->price);printf("图书作者:%s\n",ptr_book->author);printf("存在状态:%s\n",ptr_book->state);printf("借书人姓名:%s\n",ptr_book->name);printf("借书人性别:%s\n",ptr_book->sex);printf("学号:%d\n",ptr_book->xuehao);printf("\n");flag++;}}if(flag==0){printf("暂无此图书信息!\n\n");}return head_book;}struct book *Delete_Book(struct book *head_book,int bianhao){struct book *ptr1_book,*ptr2_book;while(head_book!=NULL && head_book->bianhao==bianhao){ ptr2_book=head_book;head_book=head_book->book_next;free(ptr2_book);}if(head_book==NULL)return NULL;ptr1_book=head_book;ptr2_book=head_book->book_next;while(ptr2_book!=NULL){if(ptr2_book->bianhao==bianhao){ptr1_book->book_next=ptr2_book->book_next;free(ptr2_book);}elseptr1_book=ptr2_book;ptr2_book=ptr1_book->book_next;}return head_book;}struct club *Create_New_Club(){struct club *head_club,*p_club;int xuehao;char name[20],sex[10];int size_club=sizeof(struct club);head_club=NULL;printf("请输入会员名字:");scanf("%s",name);printf("请输入会员性别:");scanf("%s",sex);printf("请输入会员学号:");scanf("%d",&xuehao);printf("\n");while(xuehao!=0){p_club=(struct club *)malloc(size_club);strcpy(p_club->name,name);strcpy(p_club->sex,sex);p_club->xuehao=xuehao;strcpy(p_club->borrow,"暂无");head_club=Insert_Club(head_club,p_club);printf("请输入会员名字:");scanf("%s",name);printf("请输入会员性别:");scanf("%s",sex);printf("请输入会员学号:");scanf("%d",&xuehao);printf("\n");}return head_club;}struct club *Search_Club_xuehao(int xuehao,struct club *head_club) {struct club *ptr_club;int flag=0;for(ptr_club=head_club;ptr_club;ptr_club=ptr_club->club_next) {if(ptr_club->xuehao==xuehao){printf("会员姓名:%s\n",ptr_club->name);printf("会员性别:%s\n",ptr_club->sex);printf("会员学号:%d\n",ptr_club->xuehao);printf("所借图书:%s\n",ptr_club->borrow);printf("\n");flag++;}}if(flag==0){printf("此用户不存在!\n\n");}return head_club;}struct club *Search_Club_name(char *c_name,struct club *head_club) {struct club *ptr_club;int flag=0;for(ptr_club=head_club;ptr_club;ptr_club=ptr_club->club_next) {if(strcmp(ptr_club->name,c_name)==0){printf("会员姓名:%s\n",ptr_club->name);printf("会员性别:%s\n",ptr_club->sex);printf("会员学号:%d\n",ptr_club->xuehao);printf("所借图书:%s\n",ptr_club->borrow);printf("\n");flag++;}}if(flag==0){printf("此用户不存在!\n\n");}return head_club;}struct book *Lent_Book(int bianhao,int xuehao,struct book *head_book,struct club *head_club){struct book *ptr_book;struct club *ptr_club;int flag=0;for(ptr_book=head_book;ptr_book;ptr_book=ptr_book->book_next)for(ptr_club=head_club;ptr_club;ptr_club=ptr_club->club_next){if((ptr_book->bianhao==bianhao)&&(ptr_club->xuehao==xuehao)){strcpy(ptr_book->name,ptr_club->name); /*字符串的复制,把右边的内容复制到左边*/strcpy(ptr_book->sex,ptr_club->sex);ptr_book->xuehao=ptr_club->xuehao;strcpy(ptr_book->state,"暂无");strcpy(ptr_club->borrow,ptr_book->book_name);flag++;}if(flag==0){printf("暂无此图书或您还未注册为会员!\n\n");}}return head_book;}struct book *back(int bianhao,int xuehao,struct book *head_book,struct club *head_club){struct book *ptr_book;struct club *ptr_club;int flag=0;for(ptr_book=head_book;ptr_book;ptr_book=ptr_book->book_next)for(ptr_club=head_club;ptr_club;ptr_club=ptr_club->club_next){if((ptr_book->bianhao==bianhao) && (ptr_club->xuehao==xuehao)){strcpy(ptr_book->name,"暂无");strcpy(ptr_book->sex,"待定");ptr_book->xuehao=0;strcpy(ptr_book->state,"暂无");strcpy(ptr_club->borrow,"暂无");flag++;}if(flag==0){printf("输入有误,请重试\n\n");}}return head_book;}struct book *Insert_Book(struct book *head_book,struct book *stud_book){struct book *ptr_b,*ptr1_b,*ptr2_b;ptr2_b=head_book;ptr_b=stud_book;if(head_book==NULL){head_book=ptr_b;head_book->book_next=NULL;}else{while((ptr_b->bianhao > ptr2_b->bianhao) && (ptr2_b->book_next!=NULL)){ ptr1_b=ptr2_b;ptr2_b=ptr2_b->book_next;}if(ptr_b->bianhao <= ptr2_b->bianhao){if(head_book==ptr2_b) head_book=ptr_b;else ptr1_b->book_next=ptr_b;ptr_b->book_next=ptr2_b;}else{ptr2_b->book_next=ptr_b;ptr_b->book_next=NULL;}}return head_book;}struct club *Insert_Club(struct club *head_club,struct club *stud_club){struct club *ptr_c,*ptr1_c,*ptr2_c;ptr2_c=head_club;ptr_c=stud_club;if(head_club==NULL){head_club=ptr_c;head_club->club_next=NULL;}else{while((ptr_c->xuehao > ptr2_c->xuehao) && (ptr2_c->club_next!=NULL)){ ptr1_c=ptr2_c;ptr2_c=ptr2_c->club_next;}if(ptr_c->xuehao <= ptr2_c->xuehao){if(head_club==ptr2_c) head_club=ptr_c;else ptr1_c->club_next=ptr_c;ptr_c->club_next=ptr2_c;}else{ptr2_c->club_next=ptr_c;ptr_c->club_next=NULL;}}return head_club;}void Print_Club(struct club *head_club){struct club *ptr_c;if(head_club==NULL){printf("\n无记录\n\n");return;}printf("\n会员姓名\t会员性别\t会员学号\n\n");for(ptr_c=head_club;ptr_c;ptr_c=ptr_c->club_next)printf("%s\t\t%s\t\t%d\n",ptr_c->name,ptr_c->sex,ptr_c->xuehao);}struct club *Delete_Club(struct club *head_club,int xuehao){struct club *ptr1_club,*ptr2_club;while(head_club!=NULL && head_club->xuehao==xuehao){ptr2_club=head_club;head_club=head_club->club_next;free(ptr2_club);}if(head_club==NULL)return NULL;ptr1_club=head_club;ptr2_club=head_club->club_next;while(ptr2_club!=NULL){if(ptr2_club->xuehao==xuehao){ptr1_club->club_next=ptr2_club->club_next;free(ptr2_club);}elseptr1_club=ptr2_club;ptr2_club=ptr1_club->club_next;}return head_club;}void Print_Book(struct book *head_book){struct book *ptr_b;if(head_book==NULL){printf("\n无记录\n\n");return;}printf("\n图书编号\t图书名称\t图书单价\t图书作者\n\n");for(ptr_b=head_book;ptr_b;ptr_b=ptr_b->book_next)printf("%d\t\t%s\t\t%.2lf\t\t%s\n\n",ptr_b->bianhao,ptr_b->book_name,ptr_b->pri ce,ptr_b->author);}(注:可编辑下载,若有不当之处,请指正,谢谢!)。
图书馆管理系统-C语言

/********这是第十组的程序,这个程序包括管理员的部分和读者的部分,管理员有删除书本、增加书本、修改密码、查询书本;读者的有借书、还书*****************************/ /*********************************以及查询图书馆中的所有图书的信息、你借阅的书本;管理员的初始密码是1234,读者的初始密码是3456;****************************************//****************************************************************************** ******************************************************/#include<stdio.h>#include<conio.h>#include<stdlib.h>#include<string.h>#include<time.h>/******************************************定义************************************/#define topborrow 2#define SIZE 10struct book /*定义书的类型*/{char bookname[40]; /*书本的名字*/char author[40]; /*书本的作者*/long int booknum; /*书本的索引号*/char type[50]; /*书本的类型*/char address[40]; /*书本的位置*/int price; /*书本的价格*/int tag; /*是否借出*/};/******************************函数的声明************************//****************************读者*******************************/void readerwelcome(); /*读者欢迎界面*/void readerpw(); /*读者的密码*/void reader(); /*读者的界面*/void search_books(); /*查询书本*/void modify_password();/*修改读者的密码*/void write_time(); /*记录借书的时间*/void write1_time(); /*还书时候判断是否超期*/void return_books(); /*还书*/void borrow_books(); /*借书*/void search_borbooks();/*****查询你借阅书本***********/void search_allbooks();/****查询图书馆中所有书本*****/void findauthor();/*通过作者来查询*/void findname(); /*通过书名来查询*/void findnum(); /*通过索引号查询*//************************管理员**************************/void read_allbook(); /*查询图书馆中的所有书本************/void managerpw(); /*管理员的密码*/void welcome_manger() ;/*进入管理员的界面*/void modify_pw(); /*修改密码*/void addbook(); /*增加书本*/void delbook(); /*删除书本*/void manager(); /*管理员的界面*//***********************进入的程序**********************/void menu(); /*菜单*/void welcome(); /*欢迎的界面*/void choice(); /*选择的菜单*/void stop();/******************************主函数*************************************/ /*************************************************************************/ void main(){int choice;char goon='y';welcome();while(goon=='y'){flushall();scanf("%d",&choice);switch(choice){case 1 :managerpw();/*读者的界面*/break;case 2 :readerpw();/*调用读者的界面*/break;case 3 :stop();/*退出*/break;}printf("\nWould you like to continue or exit ? <y/n>");goon=getch();putch(goon);if(goon=='y') /*是否继续循环*/welcome();}getch();return;}/***************************欢迎的界面***************************************/ void welcome(){system("cls"); /*清屏*/printf("\n*********************************************************************** ****\n");printf("\n**\n");printf("\n* Welcome to Putian University library *\n");printf("\n**\n");printf("\n*********************************************************************** ****\n");menu();return;}/*************************菜单栏********************************************/void menu(){printf("\n*********************************************************************** *****\n");printf("\n* 1.Manager *\n");printf("\n* 2.Reader *\n");printf("\n* 3.Exit *\n");printf("\n* Which menu would you want to choice?*\n");printf("\n* Please input number <1/2/3> : *\n");printf("\n*********************************************************************** *****\n");return;}/*******************************不想进入图书馆系统,退出************************/void stop(){system("cls"); /*clean screen*/printf("\n\t\t************************************************\n");printf("\n\t\t* Thank you for use! *\n");printf("\n\t\t* Welcome to use next time! *\n");printf("\n\t\t************************************************\n");getch();exit(0);return;}/*************************管理员*********************************************/ /**************************模块**********************************************//***************************管理员的界面************************************/void welcome_manger(){system("cls");printf("\n*********************************************************************** *********");printf("\n\t Welcome to use the manager systme! ");printf("\n*********************************************************************** *******\n");return;}void manager(){int choice;char answer='y';while(answer=='y'||answer=='Y'){system("cls"); /*清空屏幕*/printf("\n\t\t************************************************\n");printf("\n\t\t* 1.delete books. *\n");printf("\n\t\t* 2.add books. *\n");printf("\n\t\t* 3.modify password. *\n");printf("\n\t\t* 4.search all book. *\n");printf("\n\t\t* 5.back. *\n");printf("\n\t\t************************************************\n");printf("\n\t\tWhich menu would you want choice<1-4>");choice=getch();switch(choice){case '1' :delbook();break;case '2' :addbook();break;case '3':modify_pw();break;case '4':read_allbook();break;case '5' :welcome();break;}printf("\nWould you want to go to manager?<y/n>");answer=getch();putch(answer);if(answer=='y'||answer=='Y')continue;elsebreak;}return;}/*************************管理员输入密码*****************************************/void managerpw(){FILE *fp;int i;char pw[4],pw1[4];welcome_manger();while (1){printf("\n\t\t\tPlease input you four password:");for(i=0;i<4;i++){pw[i]=getch();putch('*');}fp=fopen("manager_pw.txt","r");for(i=0;i<4;i++)fscanf(fp,"%c ",&pw1[i]);fclose(fp);if(pw[0]==pw1[0]&&pw[1]==pw1[1]&&pw[2]==pw1[2]&&pw[3]==pw1[3])break;elseprintf("\n\t\t\tYour password is wrong!Please input again!\n");}manager();return;}/****************************修改管理员的密码*****************************************/void modify_pw(){FILE *fp;char pw[4],pw1[4],answer='y';int i;system("cls"); /*清空屏幕*/printf("************************************************************************* ******\n");printf(" Welcome to use modify password system! \n");printf("*************************************************************************while(1){printf("\n\t\tPlease input you want to change password: ");for(i=0;i<4;i++){pw[i]=getch();putch('*');}printf("\n\t\tPlease input you want to change password again: ");for(i=0;i<4;i++){pw1[i]=getch();putch('*');}if(pw[0]==pw1[0]&&pw[1]==pw1[1]&&pw[2]==pw1[2]&&pw[3]==pw1[3]){fp=fopen("manager_pw.txt","w");for(i=0;i<4;i++)fprintf(fp,"%c ",pw[i]);fclose(fp);printf("\n\t\tYou modify successful modify password!");getch();break;}else{printf("\n\t\tYou input two time password different\n\t\tWould you want to try again<y/n>");answer=getch();putch(answer);if(answer=='y'||answer=='Y')continue;elsebreak;}}return;}/************************************查看所有的书本****************************/void read_allbook(){int i;struct book bookinf[SIZE];fp=fopen("book_list.txt","rb");for(i=0;i<SIZE;i++)fread(&bookinf[i],sizeof(struct book),1,fp);fclose(fp);for(i=0;i<SIZE;i++){if(bookinf[i].price==0)break;else{printf("\nbook name:%s\nbook author:%s\nbook type:%s\nBook num:%ld\nbook price:%d\nbook address:%s",bookinf[i].bookname,bookinf[i].author,bookinf[i].type,bookinf[i].booknum,bookinf[i].price,booki nf[i].address);if(bookinf[i].tag==1)printf("\n\tThe book have been borrow.");if(i%4==0)getch();}}return;}/**************************************增加书本*********************************/void addbook(){FILE *fp1,*fp2;int i=0,j;char answer='y';long int booknum;struct book bookinf[SIZE];do{printf("\nBook Name:");gets(bookinf[i].bookname); /*书本的名字*/printf("\nBook Author:");gets(bookinf[i].author); /*书本的作者*/fflush(stdin); /*清空键盘缓存*/printf("\nBooknum:");scanf("%ld",&bookinf[i].booknum); /*书本的索引号*/fflush(stdin);printf("\nBook Type:");gets(bookinf[i].type); /*书本的类型*/printf("\nBook Price:"); /*书本的价格*/scanf("%d",&bookinf[i].price);fflush(stdin);printf("\nBook Address:");gets(bookinf[i].address); /*书本的位置*/printf("\nBooktag:");scanf("%ld",&bookinf[i].tag);fflush(stdin);printf("\nWould you want to add more:<y/n>");answer=getch();putch(answer);if(i>=10) /*书本只能放20本书*/{printf("\n\tIt is more than our library storage.");break;}i++;}while(answer=='y'||answer=='Y');if((fp2=fopen("book_list.txt","ab"))!= NULL ){for(j=0;j<i;j++)fwrite(&bookinf[j],sizeof(struct book),1,fp2);fclose(fp2);}else{printf("The file can be written.\n");}return;}/****************************************删除课本*******************************/void delbook(){FILE *fp,*fp1;int i,j;long int num;struct book bookinf[SIZE];system("cls"); /*清空屏幕*/fp=fopen("book_list.txt","rb");if((fp=fopen("book_list.txt","rb"))==NULL){printf("Can't open this file!!!");exit(0);}for(i=0;i<SIZE;i++){fread(&bookinf[i],sizeof(struct book),1,fp);if(bookinf[i].booknum==0)break;elseprintf("\nBook num:%ld\nBook author:%s\nBook name:%s ",bookinf[i].booknum,bookinf[i].author,bookinf[i].bookname);}fclose(fp);printf("\nWhich book number you want to delete :");scanf("%ld",&num);for(i=0;i<SIZE;i++){if(num==bookinf[i].booknum){if(bookinf[i].tag==1)printf("\nThe book have been borrow,Please when it return and delete.");else{for(j=i;j<SIZE;j++)/******************************/{ /*****将后面的书本往前面覆盖***/bookinf[j].booknum=bookinf[j+1].booknum;bookinf[j].tag=0;/******************************/bookinf[j].price=bookinf[j+1].price;strcpy(bookinf[j].bookname,bookinf[j+1].bookname);strcpy(bookinf[j].author,bookinf[j+1].author);strcpy(bookinf[j].type,bookinf[j+1].type);strcpy(bookinf[j].address,bookinf[j+1].address);}fp1=fopen("book_list.txt","wb");for(i=0;i<SIZE;i++)fwrite(&bookinf[i],sizeof(struct book),1,fp1);fclose(fp1);printf("\nYou delete successful!!!");}}}if(num!=bookinf[i].booknum){printf("\nOur library doesn't have this book.");}return;}/**********************************************读者*********************************************//**********************************************模块*********************************************//************************************读者进入的密码,密码是3456**********************************/void readerwelcome(){system("cls"); /*清空屏幕*/printf("\n*********************************************************************** *********");printf("\n\t Welcome to use the reader systme! ");printf("\n*********************************************************************** *******\n");return;}void readerpw(){FILE *fp;char pw[4],pw1[4];int i;readerwelcome();while (1){printf("\n\t\t\tPlease input you four password:");for(i=0;i<4;i++){pw[i]=getch();putch('*');}fp=fopen("reader_pw.txt","r");for(i=0;i<4;i++)fscanf(fp,"%c ",&pw1[i]);fclose(fp);if(pw[0]==pw1[0]&&pw[1]==pw1[1]&&pw[2]==pw1[2]&&pw[3]==pw1[3]) break;else{printf("\n\t\t\tYour password is wrong!Please input again!\n");continue;}}reader();return;}void reader(){int choice;char answer='y';while(1){system("cls"); /*清空屏幕*/printf("\n\t\t************************************************\n");printf("\n\t\t* 1.borrow books. *\n");printf("\n\t\t* 2.return books. *\n");printf("\n\t\t* 3.search all books. *\n");printf("\n\t\t* 4.search you have borrow. *\n");printf("\n\t\t* 5.modify password. *\n");printf("\n\t\t* 6.back. *\n");printf("\n\t\t* 7.exit. *\n");printf("\n\t\t************************************************\n");printf("\n\t\tWhich menu would you want choice<1-4>");scanf("%d",&choice);switch(choice){case 1 :borrow_books();break;case 2 :return_books();break;case 3:search_allbooks() ;break;case 4:search_borbooks();break;case 5:modify_password();break;case 6 :welcome();break;case 7:exit(0);break;}printf("\nWould you want to back to reader ?<y/n>");answer=getch();putch(answer);if(answer=='y'||answer=='Y')continue;elsebreak;}return;}/******************************************借书******************************************//****************************************************************************** **********/void borrow_books(){FILE *fp,*fp1,*fp2;int i,count=0,j;long int num;int year, month, day,hour,minute,second;struct book bookinf[SIZE];fp=fopen("book_list.txt","rb");for(i=0;i<SIZE;i++)fread(&bookinf[i],sizeof(struct book),1,fp);fclose(fp);for(i=0;i<SIZE;i++){if(bookinf[i].tag==1){count++;}}if(count<topborrow){readerwelcome();printf("Please choice which book you want to borrow number :");scanf("%ld",&num);flushall();for(i=0;i<SIZE;i++){if((num==bookinf[i].booknum)&&(bookinf[i].tag==1)){printf("This book have been borrow!!!");break;}if(num==bookinf[i].booknum){printf("\nbook name:%s\nbook author:%s\nbook type:%s\nBook num:%ld\nbook price:%d\nbook address:%s",bookinf[i].bookname,bookinf[i].author,bookinf[i].type,bookinf[i].booknum,bookinf[i].price,booki nf[i].address);bookinf[i].tag=1;printf("\nYou borrow successful !!!!");write_time();printf("\nYou should return in:");fp2=fopen("time.txt","r");fscanf(fp2,"%d %d %d %d %d %d",&year,&month,&day,&hour,&minute,&second);fprintf(stdout,"%d %d %d %d %d %d",year,month,(day+1),hour,minute,second); /*如果借书时间超过1天划款*/fclose(fp2);fp1=fopen("book_list.txt","wb");for(i=0;i<SIZE;i++)fwrite(&bookinf[i],sizeof(struct book),1,fp1);fclose(fp1);break;}}if(num!=bookinf[i].booknum&&i==SIZE-1)printf("\nOur library doesn't have this book.");}elseprintf("\nYou have borrow two books.If you want to borrow please return some books.");return;}/*********************************************记录借书本的时间********************/void write_time(){FILE *fp;time_t nowtime;int year, month, day,hour,min,sec;struct tm *timeinfo;time( &nowtime );timeinfo = localtime( &nowtime );year = timeinfo->tm_year + 1900;month = timeinfo->tm_mon + 1;day = timeinfo->tm_mday;hour=timeinfo->tm_hour;min=timeinfo->tm_min;sec=timeinfo->tm_sec;fp=fopen("time.txt","w");fprintf(fp,"%d %d %d %d %d %d",year,month,day,hour,min,sec);fclose(fp);return;}/****************************************还书************************************//****************************************************************************** **/void return_books(){FILE *fp,*fp1,*fp2,*fp3;int i,sum,j;long int num;int year, month, day,hour,minute,second;int year1, month1, day1,hour1,minute1,second1;struct book bookinf[SIZE];readerwelcome();printf("\nPlease choice which book you want to return number :");scanf("%ld",&num);flushall();fp=fopen("book_list.txt","rb");if((fp=fopen("book_list.txt","rb"))==NULL){printf("Can't open this file.");exit(0);}for(i=0;i<SIZE;++i)fread(&bookinf[i],sizeof(struct book),1,fp);fclose(fp);for(j=0;j<SIZE;j++){if((num==bookinf[j].booknum)&&(bookinf[j].tag==1)){bookinf[j].tag=0;printf("\nbook name:%s\nbook author:%s\nbook type:%s\nBook num:%ld\nbook price:%d\nbook address:%s",bookinf[j].bookname,bookinf[j].author,bookinf[j].type,bookinf[j].booknum,bookinf[j].price,booki nf[j].address);printf("\nYou borrow in:");fp1=fopen("time.txt","r");if((fp1=fopen("time.txt","r"))==NULL){printf("\nCan't open this file.");exit(0);}fscanf(fp1,"%d %d %d %d %d %d",&year,&month,&day,&hour,&minute,&second);fprintf(stdout,"%d %d %d %d %d %d",year,month,day,hour,minute,second);fclose(fp1);write1_time();if((fp2=fopen("time1.txt","r"))==NULL){printf("\nCan't open this file.");exit(0);}fscanf(fp2,"%d %d %d %d %d %d",&year1,&month1,&day1,&hour1,&minute1,&second1);fclose(fp2);if(((month1-month)==0)&&((day1-day)<1)){fp3=fopen("book_list.txt","wb");for(i=0;i<SIZE;i++)fwrite(&bookinf[i],sizeof(struct book),1,fp3);fclose(fp3);printf("\nYou successful return this book!!!");break;}else{sum=(hour1-hour)/24;printf("\n You should spend %d monney and go on.",sum);break;}}if((num==bookinf[j].booknum)&&(bookinf[j].tag==0)){printf("\nSorry! You doesn't borrow this book!!!");break;}}if(num!=bookinf[j].booknum)printf("\nSorry! Our library doesn't have this book");return;}/********************记录还书的时候的时间用来判断是否超期**********************/void write1_time(){FILE *fp;time_t nowtime;int year, month, day,hour,min,sec;struct tm *timeinfo;time( &nowtime );timeinfo = localtime( &nowtime );year = timeinfo->tm_year + 1900;month = timeinfo->tm_mon + 1;day = timeinfo->tm_mday;hour=timeinfo->tm_hour;min=timeinfo->tm_min;sec=timeinfo->tm_sec;fp=fopen("time1.txt","w");fprintf(fp,"%d %d %d %d %d %d",year,month,day,hour,min,sec);fclose(fp);return;}/*************************************查询书本***********************************//***************************************查询*************************************//***********************************查询你借的书本*******************************/void search_borbooks(){FILE *fp;int i;struct book bookinf[SIZE];fp=fopen("book_list.txt","rb");for(i=0;i<SIZE;i++)fread(&bookinf[i],sizeof(struct book),1,fp);fclose(fp);for(i=0;i<SIZE;i++){if(bookinf[i].tag==1)printf("\nbook name:%s\nbook author:%s\nbook type:%s\nBook num:%ld\nbook price:%d\nbook address:%s",bookinf[i].bookname,bookinf[i].author,bookinf[i].type,bookinf[i].booknum,bookinf[i].price,booki nf[i].address);}if(bookinf[i].tag!=1)printf("\n You doesn't borrow any book.");getch();return;}/********************************查询图书管中的所有图书*************************//****************************************************************************** */void search_allbooks(){int way;char answer='y';while(1){system("cls"); /*清空屏幕*/printf("---------------Welcome to research system--------------\n");printf(" \t1: Search by book name.\n");printf(" \t2: Search by book author.\n");printf(" \t3: Search by book num.\n");printf(" \t0: back\n");printf("\n\n********************************************************************** *******");printf("\n Please choice which way would you want to?<0-3>,other wrong input! ");printf("\n please select which one you want to operate: ");printf("\n*********************************************************************** ******\n");scanf("%d",&way);fflush(stdin); /*清空键盘缓存*/switch(way){case 1:findname();break;case 2:findauthor();break;case 3:findnum();break;case 0:exit(0);/*关闭屏幕*/}printf("\nWould you want to search anther book ?<y/n>");answer=getch();putch(answer);if(answer=='y'||answer=='Y')continue;elsebreak;}return;}/**********************************通过书名来查询********************************/void findname(){FILE *fp;char BookName[40];struct book bookinf[SIZE];int i;system("cls"); /*清空屏幕*/printf("************************************************************************* ******\n");printf(" Welcome to use the name reseach system! \n");printf("************************************************************************* ******\n");printf("\n\t\t\tPlease input book name!");gets(BookName);fp=fopen("book_list.txt","rb");for(i=0;i<SIZE;i++)fread(&bookinf[i],sizeof(struct book),1,fp);fclose(fp);for(i=0;i<SIZE;i++){if(strcmp(BookName,bookinf[i].bookname)==0) /*判断所输入的和储存的一致*/{printf("\nbook name:%s\nbook author:%s\nbook type:%s\nBook num:%ld\nbook price:%d\nbook address:%s",bookinf[i].bookname,bookinf[i].author,bookinf[i].type,bookinf[i].booknum,bookinf[i].price,booki nf[i].address);if(bookinf[i].tag==1)printf("\n\tThe book have been borrow");}}if(strcmp(BookName,bookinf[SIZE].bookname)!=0)printf("\nOur library doesn't have this book.");return;}/*************************通过作者查询****************************************/ void findauthor(){FILE *fp;char Bookauthor[40];int i;struct book bookinf[SIZE];system("cls"); /*清空屏幕*/printf("************************************************************************* ******\n");printf(" Welcome to use the author reseach system! \n");printf("************************************************************************* ******\n");printf("\n\t\t\tPlease input book author!");gets(Bookauthor);fp=fopen("book_list.txt","rb");for(i=0;i<SIZE;i++)fread(&bookinf[i],sizeof(struct book),1,fp);fclose(fp);for(i=0;i<SIZE;i++){if(strcmp(Bookauthor,bookinf[i].author)==0) /*判断所输入的和储存的有没有一致*/{printf("\nbook name:%s\nbook author:%s\nbook type:%s\nBook num:%ld\nbook price:%d\nbook address:%s",bookinf[i].bookname,bookinf[i].author,bookinf[i].type,bookinf[i].booknum,bookinf[i].price,booki nf[i].address);if(bookinf[i].tag==1)printf("\n\tThe book have been borrow");}}if(strcmp(Bookauthor,bookinf[SIZE].author)!=0)printf("\nOur library haven't this book.");fclose(fp);return;}/**************************按图书馆的索引号查询**********************************/void findnum(){FILE *fp;long int num;int i;struct book bookinf[SIZE];system("cls"); /*清空屏幕*/printf("************************************************************************* ******\n");printf(" Welcome to use the num reseach system! \n");printf("************************************************************************* ******\n");fp=fopen("book_list.txt","rb");for(i=0;i<SIZE;i++)fread(&bookinf[i],sizeof(struct book),1,fp);fclose(fp);for(i=0;i<SIZE;i++){if(bookinf[i].booknum==0)break;elseprintf("\nBook num: %ld ",bookinf[i].booknum);}printf("\nPlease input book num!");scanf("%ld",&num);fflush(stdin); /*清空键盘缓存*/for(i=0;i<SIZE;i++){if(num==bookinf[i].booknum) /*判断所输入的和储存的有没有一致*/{printf("\nbook name:%s\nbook author:%s\nbook type:%s\nBook num:%ld\nbook price:%d\nbook address:%s",bookinf[i].bookname,bookinf[i].author,bookinf[i].type,bookinf[i].booknum,bookinf[i].price,booki nf[i].address);if(bookinf[i].tag==1)printf("\n\tThe book have been borrow");break;}}if(num!=bookinf[SIZE].booknum)printf("\nOur library haven't this book.");return;}/****************************************修改密码****************************************/void modify_password() /*修改读者的密码*/{FILE *fp;char pw[4],pw1[4];int i;system("cls"); /*清空屏幕*/printf("************************************************************************* ******\n");printf(" Welcome to use modify password system! \n");printf("************************************************************************* ******\n");while(1){printf("\n\t\tPlease input you want to change password: ");for(i=0;i<4;i++){pw[i]=getch();putch('*');}printf("\n\t\tPlease input you want to change password again: ");for(i=0;i<4;i++){pw1[i]=getch();putch('*');}if(pw[0]==pw1[0]&&pw[1]==pw1[1]&&pw[2]==pw1[2]&&pw[3]==pw1[3]){printf("\n\t\tYou modify successful modify password!");fp=fopen("reader_pw.txt","w");for(i=0;i<4;i++)fprintf(fp,"%c ",pw[i]);fclose(fp);getch();break;}elseprintf("\n\t\tYou input two time password different\n\t\tPlease input again!!!");}return;}。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
#include "stdio.h"#include "stdlib.h"#include "conio.h"#include "string.h"#include "math.h"#define LEN sizeof(struct library)#define LEN1 sizeof(struct reader)#define NULL 0struct library//图书馆结构体{int shuhao,xcl;char name[20],author[20],chuban[20];struct library *next;};struct reader//读者结构体{int zhenghao;char mingzi[20],riqi[20],zname[20];struct reader *next;};void mainmenu() //显示主菜单{ system ("cls");printf("\n");printf("\t\t\t\t####################\n\n"); printf("\t\t\t\t 1.图书馆信息\n\n");printf("\t\t\t\t 2.借阅系统\n\n");printf("\t\t\t\t 3.退出系统\n\n");printf("\t\t\t 请按键选择,回车确定\n"); printf("\t\t\t\t######################\n"); printf("\n");return ;}void menu1() //显示图书馆信息菜单{ system ("cls");printf("");printf("\t\t\t\t####################\n\n"); printf("\t\t\t\t 1.采编入库\n\n");printf("\t\t\t\t 2.清除库存\n\n");printf("\t\t\t\t 3.图书查询\n\n");printf("\t\t\t\t 4.库存一览\n\n");printf("\t\t\t\t 5.返回上一层\n\n");printf("\t\t\t 请按键选择,回车确定\n");printf("\t\t\t\t#######################\n");printf("\n");return ;}void menu2() //显示查询菜单{ system ("cls");//printf("");printf("\t\t\t\t#######################\n");printf("\t\t\t\t 1.书号查询\n\n");printf("\t\t\t\t 2.书名查询\n\n");printf("\t\t\t\t 3.作者查询\n\n");printf("\t\t\t\t 4.出版社查询\n\n");printf("\t\t\t 请按键选择,回车确定\n");printf("\t\t\t\t#######################\n");//printf("");return ;}void main()//主函数,调用main1{void main1();main1();}void main1()//main1函数{void tsgxx();//声明void jieshuxitong();//声明char choose;mainmenu();scanf("%c",&choose);switch(choose)//功能函数选择{ case '1':tsgxx();break;case '2':jieshuxitong();break;case '3':system ("cls");printf("\n\n\n\n\n\n\n\n\n\t\t\t Byebye...");printf("\n\n\n\n\n\n\n\n\n\t\t\t 欢迎使用本软件!!!");getch();exit(0);system ("cls");break;}}void tsgxx()//图书馆信息函数{ void tsjinku();void shanchu();void chaxunts();void xianshikucun();//函数声明char choose;menu1();//调用菜单函数scanf("%c",&choose);scanf("%c",&choose);for (;;)switch(choose)//功能函数选择{ case '1':tsjinku();break;case '2':shanchu();break;case '3':chaxunts();break;case '4':xianshikucun();break;case '5':main1();break;}}int tjzs()//统计文本个数函数{ FILE *fp;int tshuhao=0,txcl=0,n;char tname[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);//返回个数}int tjdzzs()//统计文本个数函数{ 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);//关闭文件return (n);//返回个数}void tsjinku()//图书进库函数{ FILE *fp;int shuhao=0,xcl=0,n=0;char name[20]={'\0'},author[20]={'\0'},chuban[20]={'\0'};char hitkey;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;)//循环输入{ 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("继续输入请按回车,结束输入请按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();//返回上一层}void shanchu()//删除图书信息函数{ struct library *head=NULL;struct library *p,*p1,*p2;int tshuhao=0,txcl=0,n=0,j,i;char tname[20]={'\0'},tauthor[20]={'\0'},tchuban[20]={'\0'}, ttname[20]={'\0'};char hitkey;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);)//读文件夹信息,统计个数{ 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=(struct library*)malloc(LEN);head=p1;}else{ p2->next=p1;p2=p1;p1=(struct library*)malloc(LEN);//新建链表}p1->shuhao=tshuhao;//复制书号strcpy(p1->name,tname);//复制书名strcpy(p1->author,tauthor);//复制作者名子strcpy(p1->chuban,tchuban);//复制出版社p1->xcl=txcl;//复制个数}}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();}void chaxunts()//查询函数{FILE *fp;char choose;int ttshuhao=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();//获得文件个数menu2();//调用菜单函数scanf("%c",&choose);scanf("%c",&choose);//选择查询方式if (choose=='5')return;else if (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,tch uban))//输出查询信息{if (k==0){printf("\t\t\t\t查询结果:\n\n");printf("\t 书号书名作者出版社现存量\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();}void xianshikucun()//现实库存信息{FILE *fp;int shuhao=0,xcl=0,n=0,i=0,j=0;char name[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();}void menu3() //显示借书系统主菜单{ system ("cls");//printf("*********************************************************************** *********");printf("\t\t\t\t#######################\n");printf("\t\t\t\t 1.借书登记\n\n");printf("\t\t\t\t 2.还书登记\n\n");printf("\t\t\t\t 3.借阅情况查看\n\n");printf("\t\t\t\t 4.返回上一层\n\n");printf("\t\t\t 请按键选择,回车确定\n");printf("\t\t\t\t#######################\n");//printf("*********************************************************************** *********");return ;}void jieshuxitong()//借书系统函数{ void jieshu();void huanshu();void duzheyilang();//函数声明char choose;menu3();scanf("%c",&choose);scanf("%c",&choose);//选择功能for (;;)switch(choose)//调用函数{ case '1':jieshu();break;case '2':huanshu();break;case '3':duzheyilang();break;case '4':main1();break;}}void jieshu()//借书函数{FILE *fp,*fp3;struct library *head=NULL;struct library *p,*p1,*p2;int tshuhao=0,txcl=0,i,loop,zhenghao=0,n=0,k=0,t=0,flag=0;char tname[20]={'\0'},tauthor[20]={'\0'},tchuban[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\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();//统计图书馆文件个数for (i=0;i<k;i++)//读入图书馆信息,存储到链表{fscanf(fp,"%d%s%s%s%d",&tshuhao,tname,tauthor,tchuban,&txcl);n++;if (n==1){ p1=p2=(struct library*)malloc(LEN);head=p1;}else{ p2->next=p1;p2=p1;p1=(struct library*)malloc(LEN);//新建链表}p1->shuhao=tshuhao;//复制书号strcpy(p1->name,tname);//复制书名strcpy(p1->author,tauthor);//复制作者strcpy(p1->chuban,tchuban);//复制出版社p1->xcl=txcl;//复制现存量}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;//现存量减1(p->xcl)--;}p=p->next;}if(flag&&(loop>0))//存在借书书名且现存量大于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))//存在借书书名且现存量大于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();}}void huanshu()//还书函数{FILE *fp,*fp3;struct reader *head=NULL;struct reader *p,*p1,*p2;struct library *lhead1=NULL;struct library *zp1,*lp1,*lp2;int tshuhao=0,txcl=0,i;char tname[20]={'\0'},tauthor[20]={'\0'},tchuban[20]={'\0'}, ttname[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\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();//获取读者文件夹信息个数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=(struct reader*)malloc(LEN1);//新建链表head=p1;}else{ p2->next=p1;p2=p1;p1=(struct reader*)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();//获取图书馆文件个数for (i=0;i<k;i++)//将图书馆文件复制到链表{fscanf(fp3,"%d%s%s%s%d",&tshuhao,tname,tauthor,tchuban,&txcl);//读取信息n++;if (n==1){ lp1=lp2=(struct library*)malloc(LEN);//新建链表lhead1=lp1;}else{ lp2->next=lp1;lp2=lp1;lp1=(struct library*)malloc(LEN);//新建链表}lp1->shuhao=tshuhao;//复制书号strcpy(lp1->name,tname);//复制书名strcpy(lp1->author,tauthor);//复制作者strcpy(lp1->chuban,tchuban);//复制出版社lp1->xcl=txcl; //复制现存量}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);//现存量加1zp1=zp1->next;}fp3=fopen("library.txt","w");//清空图书馆文件fclose(fp);fp3=fopen("library.txt","a");//追加信息zp1=lhead1;for (;zp1!=NULL;)//把链表内容覆盖图书馆文件{fprintf(fp3,"%d %s %s %s %d \n",zp1->shuhao,zp1->name,zp1->author,zp1->chuban,zp1->xcl);//录入信息zp1=zp1->next;}fclose(fp3);getch();//返回jieshuxitong();}elseprintf("不存在此信息!按任意键返回!");getch();//返回jieshuxitong();}void duzheyilang()//显示借书情况函数{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\n\n\n\n\n\n\n\t\t\t记录文件不存在!");}n=tjdzzs();if (n==0){ system ("cls");printf("\n\n\n\n\n\n\n\n\n\t\t\t无任何记录!");}fp=fopen("reader.txt","r");system ("cls");printf("************************************************************************* *******");printf("\t 证号读者姓名还书日期书名\n");printf("************************************************************************* *******");for (i=0;i<n;i++)//输出文件信息{fscanf(fp,"%d%s%s%s\n ",&zhenghao,mingzi,riqi,zname);printf("\t %-4d %-8s %-8s %-8s \n", zhenghao,mingzi,riqi,zname);}fclose(fp);printf("\t\t\t\t按任意键返回\n");getch();//返回jieshuxitong();}。