图书馆管理系统 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;}。
图书馆管理系统(C语言程序设计)
图书管理系统/*图书数据由编号、书名、出版社、单价和图书状态(库存用0表示或借出用读者编号表示),读者数据由编号、姓名和电话号码构成。
实现功能包括:(1)添加图书的记录(2)图书管理(借书和还书)(3)对图书数据排序(按单价的降序)(4)删除图书记录(5)修改图书记录(6)添加读者记录(7)输出图书信息表和读者信息表*#include <stdio.h>#include <string.h>#include <stdlib.h>#include <windows.h>/*函数的声明*/void bookname();void writername();void booknumber();void press();void bookdate();void Bfind(); //查询主菜单void Bdevise(); //修改函数void Badd(); //添加函数void Bdelete(); //删除函数void Bdisplay(); //显示所以已保存的图书信息函数void Bclean(); //清除所有图书信息函数void lendbook(); // 借书函数void returnbook(); //还书函数void lendorreturnbook();//借书或还书主菜单函数void appealkey();//用户密码申诉函数void devisepeoplekey();//修改用户密码函数void accountapply(); //用户申请账户函数void addpeopleaccount(); //管理员之添加用户帐号函数void addmanageaccount(); //管理员之添加管理员账号函数void addaccount(); //管理员之账户添加主菜单函数void devisepeopleaccount();//管理员之修改用户账号函数void devisemanageaccount();//管理员之修改管理员帐号函数void deviseaccount();//管理员之修改账号主菜单函数void deletepeopleaccount();//管理员之删除用户账号函数void deletemanageaccount();//管理员之删除管理员账号函数void deleteaccount();//管理员之删除账号主菜单函数void displayallpeopleaccounts();//显示所有用户信息函数void displayallmanageaccounts();//显示所有管理员信息函数void displayallaccountsmessage();//显示所有账号信息主菜单函数void highaddpeopleaccount(); //高级管理员添加用户账户函数void highaddmanageaccount(); //高级管理员添加管理员账户函数void highaddaccount(); //高级管理员之添加账户主菜单函数void booksmanage();//图书操作主菜单函数void accountsmanage();//管理员账号操作主菜单函数void highaccountsmanage();//高级管理员账号操作主菜单函数void menu1(); //用户之查询主菜单void menu2(); //管理员之查询主菜单void menu3(); //高级管理员之查询主菜单/*定义书的类型*/struct book{int bookstock; //库存量char bookname[20]; //书名char bookwriter[20]; //作者char booknumber[20]; //书号char press[20]; //出版社char bookdate[20]; //出版日期char price[20]; //出版价格int turefalse; //判断图书是否被借阅}books[20];/*定义用户类型*/struct peopleaccount{char pname[20];char pkey[20];}peopleaccounts[20];/*定义管理员类型*/struct manageaccount{char mname[20];char mkey[20];}manageaccounts[20];/*定义借书卡类型*/struct card{char cardnumber[20]; //借书卡号和用户信息一起写入yonghu.txt文件中的}cards[20];/*定义文件指针变量*/FILE *fp1; //fp1打开用户信息文件FILE *fp2; //fp2打开管理员信息文件FILE *fp3; //fp3打开图书信息文件FILE *fp4; //打开借还书记录的文件FILE *fpa; //fpa是临时文件指针/*改变输出的字体颜色*/void color(const unsigned short color1){if(color1>=0&&color1<=15)SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color1);/*仅限改变0-15的颜色;如果在0-15那么实现他的颜色因为如果超过15后面的改变的是文本背景色。
C语言编程--图书馆管理系统
#include <iostream。
h〉#include 〈iomanip。
h>#include <string。
h〉#include 〈fstream〉//输入/输出文件流类using namespace std;const int Max1=100; //最大学生数const int Max2=100;//最大图书量const int Max3=100; //每个学生最多借2本书class student //学生类,实现对学生的信息的描述{private:int tb;//删除标记1:已删0:未删int no;//学号char name[10];//学生姓名char yuanxi[15]; //院系int ex;int borbook[Max3];//所借图书public:student() {}char *get_name() {return name;} //获取姓名char *get_yuanxi(){return yuanxi;} //获取院系int get_tb() {return tb;} //获取删除标记int get_no() {return no;} //获取学号int getex(){return ex;}void set_name(char na[]) //设置学生姓名{strcpy(name,na);}void set_yuan(char yu[]) //设置学生所在院系{strcpy(yuanxi,yu);}void set_no(int n)//设置学号{no=n;}void delbook(){ tb=1;}//设置删除标记1:已删0:未删void addstudent(int n,int ex1,char *na,char *yu)//增加学生信息{tb=0;no=n;ex=ex1;strcpy(name,na);strcpy(yuanxi,yu);for(int i=0;i〈Max3;i++)borbook[i]=0;}void borrowbook(int bookid)//借书操作{for(int i=0;i<ex;i++){if (borbook[i]==0){borbook[i]=bookid;return;}}}int retbook(int bookid)//还书操作{for(int i=0;i〈Max3;i++){if(borbook[i]==bookid){borbook[i]=0;return 1;}}return 0;}void out()//输出学生信息{cout 〈<”学号:”〈〈setw(5)<〈no <<"姓名:”<<setw(10)〈< name〈〈"院系:”<〈setw(10)<<yuanxi〈<”最大借书量:"〈<setw(10)〈<ex〈<”图书号:[";for(int i=0;i〈ex;i++)if(borbook[i]!=0)cout 〈〈borbook[i] 〈< "|";cout <〈"]"〈〈endl;}};//学生类库,用来建立学生的个人资料class studentbase{private:int top;//学生记录指针student read[Max1];//学生记录public:studentbase() //构造函数,将student。
C语言课程设计——图书馆管理系统
C语言课程设计——图书馆管理系统目录第1章引言 (2)1.1 题目背景 (2)1.2 设计目的 (2)1.3 解决问题 (2)第2章使用工具与特点 (4)2.1 C语言的发展 (4)2.2 C语言的特点 (5)第3章总体设计 (6)3.1编写目的 (6)3.2系统功能 (6)第4章系统分析与设计 (12)4.1添加功能设计 (12)4.2借阅图书功能 (13)第5章系统功能实现 (19)5.1添加功能 (19)5.2借阅功能 (19)结论 (22)致谢 (23)第1章引言1.1 题目背景随着计算机技术的飞速发展,改变了世界,也改变了人类的生活。
作为现代科学技术的飞速发展,改变了世界,也改变了人类的生活。
新世纪的大学生,应当站在时代发展的前列,掌握现代科学技术知识,调整自己的知识结构和能力结构,以适应社会发展的要求当今社会,多元文化快速发展,人与人的交流也越来越多,社交也越来越广泛,这时,记住自己认识的人是很重要的,因此我们做了这个程序,为了使我们更有效的记录下自己所认识的人,更方便去和更多的人交流而不会记错。
C语言成了在国内外使用的一种计算机语言。
C语言功能丰富、表达能力强、使用灵活方便、应用面广、目标程序效率高、可移植性好、既具有高级语言的优点,又具有低级语言的许多特点,因此特别适合于编写系统软件。
现在大多数的高校都把C语言作为第一门计算机语言进行教学,这是可行的,学生也是能够学习好的。
1.2 设计目的这次设计主要是应用了C程序设计中的一些算法,还有一些函数的调用,结构体的应用等,根据他们的基本思想来编写程序。
程序包括的主要内容可以对图书馆管理系统进行输入、修改、删除、借阅、归还、显示等操作,设计一个有关学生借阅图书的管理程序,来方便人们对信息更方便的使用,经过这样一个过程来巩固和完善自己所学的知识,同时来培养一下自己的实践能力。
通过本设计可以加深理解利用程序设计思想开发一个系统的整个流程,提高分析问题、解决问题和实际动手的能力。
图书管理系统c语言
图书管理系统C语言1. 简介图书管理系统是一种用于管理图书馆藏书和借阅记录的软件系统。
它通常包括图书的录入、借阅、归还、查询等功能,能够提高图书馆的工作效率和服务质量。
本文将使用C语言编写一个简单的图书管理系统,实现基本的图书信息录入、修改、查询、借阅、归还等功能。
2. 功能实现2.1 数据结构我们首先需要定义合适的数据结构来存储图书信息和借阅记录。
以下是一个简单的数据结构示例:struct Book {int id; // 图书编号char title[100]; // 图书标题char author[50]; // 图书作者char category[50]; // 图书分类int isBorrowed; // 图书是否已借阅,0表示未借阅,1表示已借阅char borrowerName[100]; // 借阅者姓名// 可根据需求扩展其他字段};struct BorrowRecord {int bookId; // 图书编号char borrowerName[100]; // 借阅者姓名char borrowDate[20]; // 借阅日期char returnDate[20]; // 归还日期// 可根据需求扩展其他字段};2.2 图书信息录入和修改我们可以通过实现相应的函数来实现图书信息的录入和修改。
以下是一个简单的示例:void addBook(struct Book *library, int *count) {// 输入图书信息,将其存入library数组中,同时更新count}void updateBook(struct Book *library, int count, int bookId) { // 根据图书编号bookId,更新library数组中对应图书的信息}2.3 图书查询我们可以根据图书的不同字段来实现不同的查询功能,比如根据图书标题、作者、分类等进行模糊查询,或根据图书编号进行精确查询。
图书馆管理系统(c语言)
亲试c语言图书馆管理系统,(需自行添加书目信息)#include<stdio.h>#include<malloc.h>#define FORMAT "%-10ld%-20s%-15s%-20s%-5.2f\n"#define SIZE 50#define LEN sizeof(struct send)struct book /*图书结构体*/{long book_num;char name[13];char author[10];char press[15];float price;}book[SIZE];struct send /*借阅信息结构体*/{char book_num[20];char std_num[10];}send;int n=5,l=0;void preword() /*菜单*/{printf("\n\n\t\t=============欢迎图书馆模拟系统============\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");printf("\t\t==============================================\n");printf("\t\t\t\t请选择(1-7):");}void load() /*加载磁盘文件图书信息*/{FILE *fp = fopen("BookInfo.txt","r");int i;if(!fp){printf("文件打开错误!\n");return;}while(!feof(fp)){for(i=0;i<n;i++)fscanf(fp,"%ld%s%s%s%f",&book[i].book_num,book[i].name,book[i].author,book[i].press, &book[i].price);}fclose(fp);}void print(struct book a) /*输出图书信息*/{if(l==0) /*开关变量l,控制表单*/{printf("\n%-10s%-20s%-15s%-20s%-5s\n\n","图书编号","书名","作者","出版社","价钱");printf(FORMA T,a.book_num,,a.author,a.press,a.price);l=1;}elseprintf(FORMA T,a.book_num,,a.author,a.press,a.price);}void view_all() /*浏览所有图书*/{int i;printf("\n所有图书信息为:\n");for(i=0;i<n;i++)print(book[i]);l=0;void view_one() /*浏览单个图书*/{long num;int i,k=0;find:printf("\n请出入图书编号:");scanf("%ld",&num);for(i=0;i<n;i++)if(num==book[i].book_num){printf("\n%ld 信息:\n",num);print(book[i]);k=1; /*开关变量k,反应是否找到该书*/}if(k==0){printf("\n没有对应图书,请输入正确编号!\n");goto find;}l=0;}void add() /*添加图书*/{printf("\n请输入添加图书信息:\n\t");scanf("%ld%s%s%s%f",&book[n].book_num,book[n].name,book[n].author,book[n].press,& book[n].price);printf("图书添加成功! (浏览请选择1)\n");n++;}void delet() /*删除图书*/{long num;int i,j,k=0;del:printf("\n请输入图书编号:");scanf("%ld",&num);for(i=0;i<n;i++)if(num==book[i].book_num){for(j=i;j<n-1;j++)book[j]=book[j+1];k=1;n--;printf("图书删除成功!\n");}if(k==0) /*开关变量k,反应是否找到该书*/{printf("\n没有对应图书,请输入正确编号!\n");goto del;}}void modify() /*修改图书信息*/{long num;int i,k=0;mod:printf("\n请输入图书编号:");scanf("%ld",&num);for(i=0;i<n;i++)if(num==book[i].book_num){printf("请输入新信息:\n\t");scanf("%ld%s%s%s%f",&book[i].book_num,book[i].name,book[i].author,book[i].press,&bo ok[i].price);printf("图书修改成功!\n");k=1;}if(k==0) /*开关变量k,反应是否找到该书*/{printf("\n没有对应图书,请输入正确编号!\n");goto mod;}}void select() /*借书*/{long num;char std_n[10];int i,k=0;FILE *fp = fopen("SendInfo.txt","w+");sel:printf("\n请输入图书编号:");scanf("%ld",&num);for(i=0;i<n;i++)if(num==book[i].book_num){printf("请输入学号:");scanf("%s",std_n);k=1;printf("借书成功!\n");}if(k==0) /*开关变量k,反应是否找到该书*/ {printf("\n没有对应图书,请输入正确编号!\n");goto sel;}fprintf(fp,"%-10s%-8ld\n",std_n,num);printf("\n借书信息:\n");printf("%-10s%-8ld\n",std_n,num);fclose(fp);}void main() /*主函数*/{int chois;load();loop: preword();scanf("%d",&chois);switch(chois) /*选择菜单*/{case 1: view_all(); goto loop;case 2: view_one(); goto loop;case 3: add(); goto loop;case 4: delet(); goto loop;case 5: modify(); goto loop;case 6: select(); goto loop;case 7: goto end;default: printf("请输入正确数字!\n"); goto loop;}end:printf("\n\n系统结束!\n\n");}。
c语言图书馆管理系统(codeblocks版)
printf("\t--------PASS: %40s--------\n", p1->pass);
printf("\t--------LEVEL:%40d--------\n", p1->level);
/*
*图书馆管理系统
*@author琴卓
*@time 2015-12-10
*/
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
#include<ctype.h>
#include<windows.h>
#define PASS_LEN 20 //密码长度
int lendsum;
struct user *next;
}user;
//用户结构体简写为bokk
typedef struct book {
char name[20];
char author[20];
char publish[20];
char year[10];
char ISBN[40];
char state[10];
char choice;
//程序入口
void main()
{
system("color 8b");
system("mode con cols=100 lines=50");
printf("\t\t\t图书馆系统细则:\n\t\t1.新用户注册由系统管理员操作\n\t\t2.图书由图书管理员负责\n\t\t3.普通用户最多借3本书为期30天,可续借一次,\n\t\t超期不换将每天扣除0.1元,超过10元账户将冻\n\t\t结,届时无法完成登录,需要找系统管理员解冻\n\t\t4.密码输入支持退格,访问级别1代表普通用户\n\t\t5.单项数据输入不支持空格\n\t\t6.程序每关闭开启一次经过6天\n");
C语言图书管理系统源代码
#include<stdio。
h〉#include<stdlib.h〉#include〈string。
h〉struct tushu{ /*图书结构体*/ char num[10]; /*编号*/char name[20];/*书名*/char writer[20];/*作者*/char press[20];/*出版社*/char kind[20];/*类别*/double time; /*时间*/double price;/*价格*/struct tushu *next;};struct stu /*学生结构体*/ {int snum;/*学号*/char mima[10]; /*密码*/struct stu *next;};FILE *fp; /*图书文件*/FILE *fp1; /*管理员信息文件*/ FILE *fp2; /*学生信息文件*/void menu();/*管理员主菜单(管理员进入对图书及学生信息进行管理操作)*/void xmenu();/*学生主菜单(学生进入可对图书,密码进行操作)*/void gfind(); /*管理员查询(管理员可按一定的方式查询图书)*/void xfind();/*学生查询(学生可按一定的方式查询图书)*/ void secret();/*管理员权限(管理员登陆所用,输入错误次数过多自动退出)*/void sort();/*排序(管理员可按一定的方式对图书进行排序,排序完之后可选择文件进行保存)*/void fprint(struct tushu *head);/*保存(可追加的保存,如添加可用)*/void fprint_(struct tushu *head);/*保存(可覆盖保存如修改,删除,排序后用)*/void hfprint(struct tushu *head); /*还书保存(还书成功后自动保存到文件)*/void jfprint_(struct tushu *head);/*借书保存(借书成功之后自动从图书馆删除)*/struct tushu * Input(); /*图书添加(可进行图书的添加)*/struct tushu *create(); /*从文件创建链表(从文件中读出信息,建立单链表)*/void gBrowse(struct tushu *head);/*管理员浏览(对图书进行遍历)*/void xBrowse(struct tushu *head);/*学生浏览(学生对图书进行遍历)*/void count(struct tushu *head); /*统计数量(管理员可对图书进行统计)*/void Findofname(struct tushu *head); /*按书名查找*/ void Findofwriter(struct tushu *head); /*按作者查找*/void Findofkind(struct tushu *head); /*按类别查找*/void xFindofname(struct tushu *head);/*学生按书名查找*/void xFindofwriter(struct tushu *head);/*学生按作者查找*/ void xFindofkind(struct tushu *head); /*学生按类别查找*/ void Sort_time(struct tushu * head); /*按时间排序(管理员按时间对图书进行排序,排序完之后可选择文件进行保存)*/ void Sort_price(struct tushu *head); /*按价格排序*/void Sort_num(struct tushu * head);/*按编号排序*/ void Delete(struct tushu * head,char m[15]);/*按编号删除(管理员可按编号删除图书)*/void Revise(struct tushu *head);/*修改(管理员可对图书进行修改,并选择是否保存)*/void borrow(struct tushu *head); /*借书*/void huanshu(); /*还书(学生借完书之后进行还书,若没有图书则不能借)*/void gxinxi(); /*管理员信息(有管理员的账号及密码,可进行修改)*/void xmima(struct stu *head1);/*学生密码修改(学生可对自己的密码进行修改)*/struct stu *xcreate();/*从文件创建学生信息(从文件读出学生信息,建立学生链表)*/void xsecret(struct stu *head1);/*学生权限(学生登陆所用)*/void menu() /*管理员主菜单(管理员进入对图书及学生信息进行管理操作)*/{int choice,n=0;struct tushu *head;struct stu *head1,*p;char m[15];there:printf("┏━┓━━━━━━━━━━━━━━━━━━━┏━┓\n"); printf(" ┃┃socat 图书管理系统printf(” ┃┗━━━━━━━━━━━━━━━━━━━┛┃\n"); printf(" ┃●[0]退出系统┃\n");printf(” ┃┃\n”);prin tf(” ┃●[1]帮助┃\n");printf(” ┃┃\n”);printf(” ┃●[2]浏览图书┃\n");printf(” ┃┃\n");printf(” ┃●[3]统计图书数目┃\n”);printf(" ┃┃\n”);printf(” ┃●[4]查询┃\n”);printf(” ┃printf(” ┃●[5]添加┃\n");printf(” ┃┃\n”);printf(” ┃●[6]排序┃\n");printf(” ┃┃\n");printf(" ┃●[7]修改┃\n”);printf(” ┃┃\n");printf(" ┃●[8]删除┃\n”);printf(" ┃┃\n”);printf(" ┃●[9]修改账号及密码┃\n");printf(” ┃┃\n”);printf(” ┃●[10]学生信息printf(”┗━━━━━━━━━━━━━━━━━━━━━━━┛\n");printf(” 请选择:”);fflush(stdin);head=create();scanf("%d”,&choice);if(choice==1){//help();printf(”没有内容!\n”);system("pause”);system(”cls”);menu();}else if(choice==2){system(”cls");if(head==NULL){printf(”没有图书,请先添加图书!\n”);system("pause");system("cls");menu();}gBrowse(head);}else if(choice==3){system(”cls");count(head);}else if(choice==4){system("cls");if(head==NULL){printf(”没有图书,请先添加图书!\n”);system("pause”);system(”cls”);menu();}gfind();}else if(choice==5){Input();}else if(choice==6){system("cls");if(head==NULL){printf(”没有图书,请先添加图书!\n”); system("pause”);system(”cls”);menu();}sort(head);}else if(choice==7){system("cls”);if(head==NULL){printf(”没有图书,请先添加图书!\n”);system("pause");system("cls”);menu();}Revise(head);}else if(choice==8){if(head==NULL){printf("没有图书,请先添加图书!\n");system(”pause");system(”cls");menu();}printf(" 请输入想要删除的图书编号:”);scanf(”%s",m);Delete(head,m);}else if(choice==9){gxinxi();else if(choice==10){system(”cls”);head1=xcreate();if(head1==NULL){printf("没有学生信息,请到xuesheng_list.txt添加!\n”); sys tem(”pause”);system(”cls”);menu();}for(p=head1;p!=NULL;p=p—>next){printf(”学生学号密码\n”);printf("%d %s\n",p->snum,p—>mima);}system(”pause”);system("cls”);menu();}else if(choice==0)system(”cls");printf(”\n\n\n\n”);printf(” ━━━━━━━━感谢使用图书管理系统━━━━━━━━\n\n\n”);exit(0);}else{system("cls");printf(”\n\n\n\n ━━━━输入错误,请重新输入!━━━━\n\n\n ");system("pause”);system(”cls”);n++;if(n==3){printf(” \n\n\n ━━━━━━━━你错误次数太多,自动退出!━━━━━━━━\n\n\n”);printf(" ━━━━━━━━感谢使用图书管理系统━━━━━━━━\n\n\n");system(”pause");exit(0);}goto there;}}void xmenu()/*学生主菜单(学生进入可对图书,密码进行操作)*/{struct tushu *head;struct stu *head1;int choice,n=0;there:printf(”┏━┓━━━━━━━━━━━━━━━━━━━┏━┓\n");printf(” ┃┃socat 图书借阅系统┃┃\n");printf(” ┃┗━━━━━━━━━━━━━━━━━━━┛┃\n"); printf(” ┃●[0]退出系统┃\n”);printf(” ┃printf(” ┃●[1]帮助┃\n”);printf(” ┃┃\n”);printf(” ┃●[2]浏览图书┃\n");printf(” ┃┃\n”);printf(" ┃●[3]查询┃\n”);printf(” ┃┃\n”);printf(” ┃●[4]借书┃\n");printf(” ┃┃\n”);printf(" ┃●[5]还书┃\n");printf(" ┃┃\n”);printf(” ┃●[6]修改密码printf("┗━━━━━━━━━━━━━━━━━━━━━━━┛\n”); printf(" 请选择:");fflush(stdin);head=create();scanf("%d”,&choice);if(choice==1){//xhelp();printf(”没有内容!\n");system(”pa use");system(”cls”);xmenu();}else if(choice==2){system("cls");if(head==NULL){printf(”没有图书!\n");system("pause”);xmenu();}xBrowse(head);}else if(choice==3){if(head==NULL){printf(”没有图书!\n”);system(”pause”);system(”cls”);xmenu();}xfind();}else if(choice==4){if(head==NULL){printf(”没有图书!\n");system(”pause”);xmenu();}borrow(head);}else if(choice==5){huanshu(head);}else if(choice==6){system("cls”);head1=xcreate();if(head1==NULL){printf(”学生信息被清空!!\n”);system("pause");system("cls”);xmenu();}xmima(head1); ;}else if(choice==0){system("cls");printf(”\n\n\n\n”);printf(” ━━━━━━━━感谢使用图书管理系统━━━━━━━━\n\n\n");exit(0);}else{system("cls”);printf("\n\n\n\n ━━━━输入错误,请重新输入!━━━━\n\n\n ”);system(”pause”);system(”cls”);n++;if(n==3){printf(” \n\n\n ━━━━━━━━你错误次数太多,自动退出!━━━━━━━━\n\n\n”);printf(” ━━━━━━━━感谢使用图书管理系统━━━━━━━━\n\n\n”);system("pause”);exit(0);}goto there;}}void gfind()/*管理员查询(管理员可按一定的方式查询图书)*/{int choice,n=0;struct tushu *head;there:system(”cls”);printf(” ┏━┓━━━━━━━━━━━━━━━━━━━┏━┓\n”);printf(” ┃┃socat 图书借阅系统┃┃\n”);printf(” ┃┗━━━━━━━━━━━━━━━━━━━┛┃\n");printf(" ┃●[0]返回┃\n");printf(" ┃┃\n”);printf(" ┃●[1]按书名查找┃\n”);printf(" ┃┃\n”);printf(" ┃●[2]按作者查找┃\n”);printf(” ┃┃\n”);printf(" ┃●[3]按类别查找┃\n”);printf(" ┃┃\n”);printf(" ┃● ┃\n”);printf(”┗━━━━━━━━━━━━━━━━━━━━━━━┛\n”);printf(" 请选择:”);fflush(stdin);head=create();scanf(”%d”,&choice);if(choice==1){system(”cls");Findofname(head); }else if(choice==2){system(”cls”); Findofwriter(head); }else if(choice==3){system(”cls");Findofkind(head); }else if(choice==0){system(”cls”);menu();}else{system(”cls”);printf(”\n\n\n\n ━━━━输入错误,请重新输入!━━━━\n\n\n ”);system("pause");system(”cls");n++;if(n==3){printf(" \n\n\n ━━━━━━━━你错误次数太多,自动退出! ━━━━━━━━\n\n\n”);printf(" ━━━━━━━━感谢使用图书管理系统━━━━━━━━\n\n\n”);system(”pause”);exit(0);}goto there;}}void xfind()/*学生查询(学生可按一定的方式查询图书)*/ {struct tushu *head;int choice,n=0;there:system("cls”);printf(” ┏━┓━━━━━━━━━━━━━━━━━━━┏━┓\n”);printf(” ┃┃socat 图书借阅系统┃┃\n”);printf(” ┃┗━━━━━━━━━━━━━━━━━━━┛┃\n");printf(” ┃●[0]返回┃\n”);printf(” ┃┃\n");printf(" ┃●[1]按书名查找┃\n”);printf(” ┃┃\n”);printf(" ┃●[2]按作者查找┃\n”);printf(" ┃┃\n");printf(” ┃●[3]按类别查找┃\n");printf(” ┃┃\n”);printf(" ┃● ┃\n");printf(”┗━━━━━━━━━━━━━━━━━━━━━━━┛\n"); printf(” 请选择:");fflush(stdin);head=create();scanf(”%d",&choice);if(choice==1){system(”cls”);xFindofname(head);}else if(choice==2){system(”cls”);xFindofwriter(head);}else if(choice==3){system("cls");xFindofkind(head);}else if(choice==0){system(”cls");xmenu();}else{system("cls");printf("\n\n\n\n ━━━━输入错误,请重新输入!━━━━\n\n\n ”);system(”pause”);system(”cls");n++;if(n==3){printf(” \n\n\n ━━━━━━━━你错误次数太多,自动退出!━━━━━━━━\n\n\n”);printf(” ━━━━━━━━感谢使用图书借阅系统━━━━━━━━\n\n\n”);system("pause”);exit(0);}goto there;}}void sort(){struct tushu *head;int choice,n=0;there:system("cls”);printf(” ┏━┓━━━━━━━━━━━━━━━━━━━┏━┓\n");printf(” ┃┃socat 图书借阅系统┃┃\n");printf(" ┃┗━━━━━━━━━━━━━━━━━━━┛┃\n”);printf(" ┃●[0]返回┃\n”);printf(” ┃┃\n");printf(” ┃●[1]按时间排序┃\n”);printf(” ┃┃\n”);printf(” ┃●[2]按价格排序┃\n");printf(" ┃┃\n”);printf(” ┃●[3]按编号排序┃\n”);printf(" ┃┃\n”);printf(” ┃●┃\n”);printf(”┗━━━━━━━━━━━━━━━━━━━━━━━┛\n”);printf(" 请选择:”);fflush(stdin);head=create();scanf("%d",&choice);if(choice==1){system("cls”); Sort_time(head);}else if(choice==2){sys tem(”cls");Sort_price(head);}else if(choice==3){system(”cls”);Sort_num(head); }else if(choice==0){system("cls”); menu();}else{system(”cls");printf("\n\n\n\n ━━━━输入错误,请重新输入!━━━━\n\n\n ”);system(”pause”);system(”cls”);n++;if(n==3){printf(” \n\n\n ━━━━━━━━你错误次数太多,自动退出! ━━━━━━━━\n\n\n”);printf(” ━━━━━━━━感谢使用图书借阅系统━━━━━━━━\n\n\n”);system("pause”);exit(0);}goto there;}}struct tushu *Input(){struct tushu *p1,*p2,*head,*ptr;char num;int x,i=0;system("cls”);p1=(struct tushu *)malloc(sizeof(struct tushu));head=p1;p1-〉price=—1;while(i!=1){printf(”请输入编号,以’#’结束\n”);scanf("%s",p1—>num);if(strcmp(p1-〉num,”#")==0)i=1;while(i!=1){printf(”请依次输入书名作者出版社类别出版时间价格\n”); scanf(”%s%s%s%s%lf%lf”,p1—>name,p1—>writer,p1—〉press,p1-〉kind,&p1-〉time,&p1—〉price);p2=p1;p1=(struct tushu *)malloc(sizeof(struct tushu));p2—〉next=p1;break;}}if(p1-〉price!=-1)p2—〉next=NULL;elsehead=NULL;system("cls”);printf("\n\n\n\t\t\t图书信息输入结束!\n\n\n”);system(”pause”);system(”cls”);printf(”\n\n\n\t\t\t是否保存图书信息?(1。
- 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();}。