一个用c++编写的小型图书馆系统
- 格式:doc
- 大小:114.00 KB
- 文档页数:31
#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"); }}。
#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();}。
#include<iostream>#include<string>#include<ctime>#include<fstream>const int i=1000;int m=0,_m=0;using namespace std;class library;/************************时间类*******************************/class Time{private:int year;int month;int Day;public:Time(){int temp=time(0);int day1,day;year=1970+(temp-10*24*3600)/(3600*24*365);day=(temp-(year-1970)*(3600*24*365)-10*24*3600)/(3600*24)+1;if(0<day&&day<=31) month=1,day1=1;if(31<day&&day<=59) month=2,day1=31;if(59<day&&day<=90) month=3,day1=59;if(90<day&&day<=120) month=4,day1=90;if(120<day&&day<=151) month=5,day1=120;if(151<day&&day<=181) month=6,day1=151;if(181<day&&day<=212) month=7,day1=181;if(212<day&&day<=243) month=8,day1=212;if(243<day&&day<=273) month=9,day1=243;if(273<day&&day<=304) month=10,day1=273;if(304<day&&day<=334) month=11,day1=304;if(334<day&&day<=365) month=12,day1=334;Day=day-day1;};int getyear(){ return year;}int getmonth(){return month;}int getDay(){return Day;}};/************************************************书籍**************************************************/class book{private:string bookname[i];string writer[i];string isbn[i];string press[i];string edition[i];string publishing_time[i];string collection_number[i];int number[i];int book_number;friend class library;public:void add_book(){string Bookname;string Writer;string Isbn;string Press;string Edition;string Publishing_time;string Collection_number;ofstream out("book.txt",ios::app);cout<<"你要添加多少书籍"<<endl;cin>>book_number;cout<<"请输入书籍的信息:(依次为书籍名称、作者、书号、出版社、版次、出版时间、馆藏编号)"<<endl;for(int n=0;n<book_number;n++){cout<<"书籍名称:";cin>>Bookname;cout<<"作者:";cin>>Writer;cout<<"书号:";cin>>Isbn;cout<<"出版社:";cin>>Press;cout<<"版次:";cin>>Edition;cout<<"出版时间:";cin>>Publishing_time;cout<<"馆藏编号:";cin>>Collection_number;out<<endl<<Bookname<<"\t"<<Writer<<"\t"<<Isbn<<"\t"<<Press<<"\t"<<Edition<<"\t"<<Publi shing_time<<"\t"<<Collection_number<<"\t"<<"1";}out.close();}void read_book(){m=0;ifstream in("book.txt",ios::in);for(int a=0;!in.eof();a++){in>>bookname[a]>>writer[a]>>isbn[a]>>press[a]>>edition[a]>>publishing_time[a]>>collection_ number[a]>>number[a];m++;}in.close();}void jieshu(int n){read_book();ofstream out("book.txt",ios::out);for(int a=0;a<m;a++){ if(a==n) setnumber(a,0);out<<endl<<getbname(a)<<"\t"<<getwriter(a)<<"\t"<<getisbn(a)<<"\t"<<getpress(a)<<"\t"<<gete dition(a)<<"\t"<<getpublishing_time(a)<<"\t"<<getcollection_number(a)<<"\t"<<getnumber(a);}out.close();}void setname(string a,int n){bookname[n]=a;}void setwriter(string a,int n){writer[n]=a;}void setisbn(string a,int n){isbn[n]=a;}void setpress(string a,int n){press[n]=a;}void setedition(string a,int n){edition[n]=a;}void setpublishing_time(int a,int n){publishing_time[n]=a;}void setcollection_number(string a,int n){collection_number[n]=a;}void setnumber(int i,int a){number[i]=a;}string getbname(int i){return bookname[i];}string getwriter(int i){return writer[i];}string getisbn(int i){return isbn[i];}string getpress(int i){return press[i];}string getedition(int i){return edition[i];}string getpublishing_time(int i){return publishing_time[i];}string getcollection_number(int i){return collection_number[i];}int getnumber(int i){return number[i];}void show(){for(int a=0;a<m;a++){ cout<<bookname[a]<<" "<<writer[a]<<" "<<isbn[a]<<" "<<press[a]<<" "<<edition[a]<<" "<<publishing_time[a]<<" "<<collection_number[a]<<" ";if(number[a]==1)cout<<"在架"<<endl;else cout<<"借出"<<endl;}}};/********************************读者************************************/class reader{private:string name[i];string readid[i];string department[i];char sort[i];int borrowbook[i];int ydbook[i];int b_name[i][6];int y_name[i][3];public:void REG(){ ///////////////注册int count=-1;string Name;string Readid;string Department;char Sort;ofstream out("read.txt",ios::app);cout<<"请输入你的信息:"<<endl;cout<<"姓名:";cin>>Name;cout<<"借书证号:";cin>>Readid;cout<<"系部:";cin>>Department;cout<<"学生?老师(s/学生,t/老师)";cin>>Sort;read_reader();for(int a=0;a<_m;a++){ if(name[a]==Name) {cout<<"该用户名已被注册!"<<endl;count=a;break;}}// out.close();if(count==-1){cout<<"注册成功"<<endl;out<<endl<<Name<<"\t"<<Readid<<"\t"<<Department<<"\t"<<Sort<<"\t"<<"0"<<"\t"<<"0"<<"\ t"<<"0"<<"\t"<<"0"<<"\t"<<"0"<<"\t"<<"0"<<"\t"<<"0"<<"\t"<<"0"<<"\t"<<"0"<<"\t"<<"0"<<" \t"<<"0";}}void read_reader(){_m=0;ifstream in("read.txt",ios::in);for(int a=0;!in.eof();a++){in>>name[a]>>readid[a]>>department[a]>>sort[a]>>borrowbook[a]>>ydbook[a]>>b_name[a][0] >>b_name[a][1]>>b_name[a][2]>>b_name[a][3]>>b_name[a][4]>>b_name[a][5]>>y_name[a][0]>>y_name[a][1]>>y_n ame[a][2];_m++;}in.close();}string getname(int a){return name[a];}string getreadid(int a ){return readid[a];}string getdepartment(int a){return department[a];}char getsort(int a){return sort[a];}int getybbook(int a){return ydbook[a];}int getYname(int a,int _a){return y_name[a][_a];}int getb_name(int a,int b){return b_name[a][b];}int getborrowbook(int a){return borrowbook[a];}void setborrow(int a,int _a){borrowbook[a]=_a;}int getydbook(int a){return ydbook[a];}int gety_name(int a,int _a){return y_name[a][_a];}void setb_name(int a,int b,int c){b_name[a][b]=c;}void show(){read_reader();for(int a=0;a<_m;a++){cout<<getname(a)<<" "<<getreadid(a)<<" "<<getdepartment(a)<<" "<<getsort(a)<<" "<<borrowbook[a]<<" "<<ydbook[a]<<" ";for(int _a=0;_a<6;_a++) cout<<b_name[a][_a]<<" ";for(int A=0;A<3;A++) cout<<y_name[a][A]<<" ";cout<<endl;}}};/***************************图书馆*******************************/class library{public:string Bookname;string Writer;string Isbn;string Press;string Edition;int Publishing_time;string Collection_number;int Number;book a;int pd;reader b;int j; //记住登入人的位置int _j;//记录书得位置void setj(int a){j=a;}int getj(){return j;}void set_j(int a){_j=a;}int get_j(){return _j;}void find_name(int s){a.read_book();int count=-1;cout<<"请输入书名:";cin>>Bookname;for(int n=0;n<m;n++){if(Bookname==a.getbname(n)){ count=n;break;}}if(count==-1) {cout<<"您要借阅的书籍本馆暂无"<<endl<<endl<<"请重新选择"<<endl;if(s==1)find_book_interface();else borrow_book_interface();}else{cout<<"书名:"<<a.getbname(count)<<endl;cout<<"作者;"<<a.getwriter(count)<<endl;cout<<"书号:"<<a.getisbn(count)<<endl;cout<<"出版社:"<<a.getpress(count)<<endl;cout<<"馆藏编号:"<<a.getcollection_number(count)<<endl;if(s==0){cout<<"确借阅本书?(y/n)";char s;cin>>s;if(s=='y'){if(a.getnumber(count)==1){cout<<"借阅成功!"<<endl;set_j(count);a.jieshu(count);borrow_book();}else cout<<"本书已借出!"<<endl;}borrow_book_interface();}if(s==1)find_book_interface();}}void find_press(int s){a.read_book();int count=-1;cout<<"请输入书籍出版社:";cin>>Press;for(int n=0;n<m;n++){if(Press==a.getpress(n)) count=n;break;}if(count==-1) {cout<<"您要借阅的书籍本馆暂无"<<endl<<"请重新选择"<<endl;if(s==1)find_book_interface();else borrow_book_interface();}else{cout<<"书名:"<<a.getbname(count)<<endl;cout<<"作者;"<<a.getwriter(count)<<endl;cout<<"书号:"<<a.getisbn(count)<<endl;cout<<"出版社:"<<a.getpress(count)<<endl;cout<<"馆藏编号:"<<a.getcollection_number(count)<<endl;if(s==0){cout<<"确借阅本书?(y/n)";char s;cin>>s;if(s=='y'){if(a.getnumber(count)==1){cout<<"借阅成功!"<<endl;a.jieshu(count);set_j(count);}else cout<<"本书已借出!"<<endl;}borrow_book_interface();}if(s==1)find_book_interface();}}void find_isbn(int s){a.read_book();int count=-1;cout<<"请输入书号:";cin>>Isbn;for(int n=0;n<m;n++){if(Isbn==a.getisbn(n)) count=n;break;}if(count==-1) {cout<<"您要借阅的书籍本馆暂无"<<endl<<"请重新选择"<<endl;if(s==1)find_book_interface();else borrow_book_interface();}else{cout<<"书名:"<<a.getbname(count)<<endl;cout<<"作者;"<<a.getwriter(count)<<endl;cout<<"书号:"<<a.getisbn(count)<<endl;cout<<"出版社:"<<a.getpress(count)<<endl;cout<<"馆藏编号:"<<a.getcollection_number(count)<<endl;if(s==0){cout<<"确借阅本书?(y/n)";char s;cin>>s;if(s=='y'){if(a.getnumber(count)==1){cout<<"借阅成功!"<<endl;a.jieshu(count);set_j(count);borrow_book();}else cout<<"本书已借出!"<<endl;}borrow_book_interface();}if(s==1)find_book_interface();}}void find_collection_number(int s){a.read_book();int count=-1;cout<<"请输入书籍馆藏编号:";cin>>Collection_number;for(int n=0;n<m;n++){if(Collection_number==a.getcollection_number(n)) count=n;break;}if(count==-1) {cout<<"您要借阅的书籍本馆暂无"<<endl<<"请重新选择"<<endl;if(s==1)find_book_interface();else borrow_book_interface();}else{cout<<"书名:"<<a.getbname(count)<<endl;cout<<"作者;"<<a.getwriter(count)<<endl;cout<<"书号:"<<a.getisbn(count)<<endl;cout<<"出版社:"<<a.getpress(count)<<endl;cout<<"馆藏编号:"<<a.getcollection_number(count)<<endl;if(s==0){cout<<"确借阅本书?(y/n)";char s;cin>>s;if(s=='y'){if(a.getnumber(count)==1){cout<<"借阅成功!"<<endl;a.jieshu(count);set_j(count);}else cout<<"本书已借出!"<<endl;}borrow_book_interface();}if(s==1)find_book_interface();}}void library_interface(){ ////图书馆界面int c;cout<<"########################################"<<endl;cout<<" 欢迎来到长沙学院图书馆"<<endl;cout<<" 请按键选择功能"<<endl;cout<<"########################################"<<endl;cout<<"1、登陆2、用户注册"<<endl;cout<<"3、图书管理4、图书检索"<<endl;cout<<" 5、退出系统"<<endl;cout<<"#########################################"<<endl;cin>>c;switch(c){case 5:break;case 4:find_book_interface();break;case 3:book_manage();break;case 2:b.REG();library_interface();break;case 1:landing();break;default:break;}}void yuding(){a.read_book();string name;cout<<"请输入预订书籍名称:";cin>>name;int q=-1;for(int n=0;n<_m;n++){ if(name==a.getbname(n)) {q=n;if(a.getnumber(q)==0)cout<<"预订成功!"<<endl;else cout<<"本书尚在馆内,无需预订!"<<endl;break;}}if(q==-1)cout<<"你预订的书籍本馆暂无"<<endl;}void landing_interface(){ ///////登陆之后的界面int a;cout<<"########################################"<<endl;cout<<" 欢迎来到长沙学院图书馆"<<endl;cout<<" 请按键选择功能"<<endl;cout<<"########################################"<<endl;cout<<"1、借书 2.还书"<<endl;cout<<"3、图书检索4、图书预定"<<endl;cout<<" 5.注销"<<endl;cout<<"#########################################"<<endl;cin>>a;switch(a){case 1:borrow_book_interface();break;case 2:break;case 3:find_book_interface();break;case 4:yuding();landing_interface();break;case 5:library_interface();break;}}void borrow_book(){ ////////////借书b.read_reader();a.read_book();string c;int _c;_c=b.getborrowbook(get_j());_c++;ofstream out("read.txt",ios::out);for(int a=0;a<_m;a++){ if(a==getj()) { b.setborrow(a,_c);b.setb_name(a,_c-1,get_j());}out<<endl<<b.getname(a)<<"\t"<<b.getreadid(a)<<"\t"<<b.getdepartment(a)<<"\t"<<b.getsort(a) <<"\t"<<b.getborrowbook(a)<<"\t"<<b.getydbook(a)<<"\t"<<b.getb_name(a,0)<<"\t"<<b.getb_name(a,1)<<"\t"<<b.getb_name(a,2)<<"\t"<<b.getb_name(a, 3)<<"\t"<<b.getb_name(a,4)<<"\t"<<b.getb_name(a,5)<<"\t"<<b.gety_name(a,0)<<"\t"<<b.gety_name(a,1)<<"\t"<<b.gety_name(a,2);}}void _returnbook(){};void landing(){ ////////////////登陆string name,id;b.read_reader();int count=-1;cout<<"请输入名字:";cin>>name;cout<<"借书证号:";cin>>id;for(int n=0;n<_m;n++){if(b.getname(n)==name)if(b.getreadid(n)==id){ cout<<"登陆成功!"<<endl;count=n;setj(count);landing_interface(); }else {cout<<"借书证号错误!请重新输入"<<endl;landing();}cout<<n<<endl;}if(count==-1) {cout<<"该账号尚未注册:"<<endl;library_interface();}}void book_manage(){ ////////////图书管理a.read_book();cout<<"1、添加书籍"<<endl;cout<<"2、显示所有书籍"<<endl;cout<<"3、返回主菜单"<<endl;cout<<"--------------"<<endl;cout<<" 请选择" <<endl;int c;cin>>c;switch(c){case 2:a.show();book_manage();break;case 3:library_interface();break;case 1:a.add_book();book_manage();break;}}void borrow_book_interface(){ /////////借书界面pd=0;cout<<"1、按书名借阅图书" <<endl;cout<<"2、按出版社借阅图书" <<endl;cout<<"3、按书号借阅图书" <<endl;cout<<"4、按馆藏编号借阅图书" <<endl;cout<<"5、主菜单"<<endl;cout<<"----------------------------------"<<endl;cout<<"请你选择"<<endl;int way;cin>>way;switch(way){case 5: library_interface();borrow_book_interface();break;case 4:find_collection_number(pd);borrow_book_interface();break;case 3: find_isbn(pd);borrow_book_interface();break;case 2: find_press(pd);borrow_book_interface();break;case 1: find_name(pd);borrow_book_interface();break;}}void find_book_interface(){ ///图书检索界面pd=1;cout<<"1、按书名检索图书" <<endl;cout<<"2、按出版社检索图书" <<endl;cout<<"3、按书号检索图书" <<endl;cout<<"4、按馆藏编号检索图书" <<endl;cout<<"5、主菜单"<<endl;cout<<"----------------------------------"<<endl;cout<<"请你选择"<<endl;int way;cin>>way;switch(way){case 5: library_interface();break;case 4: find_collection_number(pd);break;case 3: find_isbn(pd);break;case 2: find_press(pd);break;case 1: find_name(pd);break;default:break;}}};int main(){// book a;// a.read_book();library b;//b.find_name(0);b.library_interface();//reader a;//a.read_reader();//system("pause");return 0;}X。
原创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语言程序#include<stdio.h>#include<string.h>#include<stdlib.h>struct book{char writer[20];char title[20];char publishinghouse[20];char number[10];float price;struct book *next;};struct book * Create_Book();void Insert(struct book* head);void Delete(struct book * head);void Print_Book(struct book* head);void search_book(struct book* head);void change_Book(struct book * head);void save(struct book * head);struct book * Create_Book(){struct book * head;head=(struct book *)malloc(sizeof(struct book));head->next=NULL;return head;}void save(struct book * head){struct book *p;FILE *fp;p=head;fp=fopen("kucun.txt","w+");fprintf(fp,"************************************************\n");fprintf(fp,"书号\t书名\t作者\t出版社\t价格\t \n");\n");fprintf(fp,"while(p->next!= NULL){p=p->next;fprintf(fp,"%s\t%s\t %s\t %s\t %.2f\t \n",p- >number,p->title,p->writer,p->publishinghouse,p->price);}fprintf(fp,"************************************************\n");fclose(fp);printf("已将图书数据保存到kucun.txt 文件\n");}//插入//void Insert(struct book*head){struct book *s, *p,*p1,*swap;char flag='Y';swap=(struct book *)malloc(sizeof(struct book)); p1=swap;p=head;while(flag=='Y'||flag=='y'){s=(struct book*)malloc(sizeof(struct book));printf("\nfflush(stdin);scanf("%s",s->number);printf("\nfflush(stdin);scanf("%s",s->title);printf("\nfflush(stdin);scanf("%s",s->writer);printf("\nfflush(stdin);scanf("%s",s->publishinghouse);请输入图书书号:");请输入图书书名:");请输入图书作者名:");请输入图书出版社:");请输入图书价格:"); printf("\nfflush(stdin);scanf("%f",&s->price);printf("\n");//排序//p1=p->next;if(head->next!=NULL)do{if(strcmp((p1->number),(s->number))>0){strcpy(swap->number,p1->number);strcpy(swap->title,p1->title);strcpy(swap->writer,p1->writer);strcpy(swap->publishinghouse,p1->publishinghouse);swap->price=p1->price;strcpy(p1->number,s->number);strcpy(p1->title,s->title);strcpy(p1->writer,s->writer);strcpy(p1->publishinghouse,s->publishinghouse);p1->price=s->price;strcpy(s->number,swap->number);strcpy(s->title,swap->title);strcpy(s->writer,swap->writer);strcpy(s->publishinghouse,swap->publishinghouse);s->price=swap->price;}p=p1;p1=p->next;}while(p1!=NULL);p->next=s;s->next=NULL;printf("******* 添加成功!*******"); printf("\n继续添加?(Y/N):"); fflush(stdin);scanf("%c",&flag);printf("\n");if(flag=='N'||flag=='n'){break;}else if(flag=='Y'||flag=='y'){continue;}}save(head);}//查找//void search_book(struct book*head){struct book *p;char temp[20];p=head;if(head==NULL||head->next==NULL){printf("******* 图书库为空!*******\n");} else{printf("请输入您要查找的书名: ");fflush(stdin);scanf("%s",temp);while(p->next!= NULL){p=p->next;if(strcmp(p->title,temp)==0){printf("\n图书已找到!\n");printf("\n");printf("书号:%s\t\n",p->number);- 6 -printf("书名:%s\t\n",p->title);printf("作者名: %s\t\n",p->writer);printf("出版社: %s\t\n",p->publishinghouse);printf("价格:%.2f\t\n",p->price);}if(p->next==NULL){printf("\n查询完毕!\n");}}}}void Print_Book(struct book*head){struct book *p;if(head==NULL||head->next==NULL){没有图书记录!printf("\n**************\n\n");}p=head;printf("*************************************\n");printf("书号\t 书名\t 作者\t 出版社\t 价格\t\n");printf("*************************************\n");while(p->next!= NULL){p=p->next;printf("%s\t%s\t%s\t%s\t%.2f\t\n",p->number,p->title,p->writer,p->publishinghouse,p->price);}printf("*************************************\n");printf("\n");}//更改//void change_Book(struct book * head){struct book *p;int panduan=0;char temp[20];p=head;printf("请输入要修改图书的书号:");scanf("%s",temp);while(p->next!= NULL){p=p->next;if(strcmp(p->number,temp)==0){printf("\nfflush(stdin);scanf("%s",p->title);printf("\nfflush(stdin);scanf("%s",p->writer);printf("\nfflush(stdin);scanf("%s",p->publishinghouse); printf("\nfflush(stdin);scanf("%f",&p->price);printf("\n");panduan=1;}}if(panduan==0)请输入图书书名:");请输入图书作者名:");请输入图书出版社:");请输入图书价格:");{printf("\n******没有图书记录!******\n\n");} } //删除//void Delete(struct book *head){struct book *s,*p;- 9 -char temp[20];int panduan;panduan=0;p=s=head;printf("[请输入您要删除的书名]:"); scanf("%s",temp);p=p->next;while(p!= NULL){if(strcmp(p->title,temp)==0){panduan=1;break;}p=p->next;}if(panduan==1){while(s->next!=p){s=s->next;}s->next=p->next;free(p);printf("\n******* 删除成功!*******\n");save(head);}else{printf("您输入的书目不存在,请确认后输入! \n");}}//主函数//void main(){struct book * head;int choice;head=NULL;while(1){printf("*************************************************\n");小型图书管理系统printf("**\n");printf("**\n");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]退出系统*\n");printf("*************************************************\n");请选择:"); printf("fflush(stdin);scanf("%d",&choice);switch(choice){case1:if(head==NULL){head=Create_Book();}Insert(head);break;case2:Print_Book(head);break;case3:search_book(head);break;case4:change_Book(head);break;case5:Delete(head);break;case6:printf("\n");感谢使用图书管理系统printf("*************\n");break;default:printf("******* 输入错误,请重新输入!*******");break;}}}。
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;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->price,ptr_b->autho r);}。
c语言课程设计图书馆管理系统一、教学目标本课程的教学目标是使学生掌握C语言编程基础,能够运用C语言设计简单的图书馆管理系统。
具体分为三个维度:1.知识目标:学生需要掌握C语言的基本语法、数据类型、运算符、控制结构、函数等编程基础。
2.技能目标:学生能够运用C语言进行程序设计,具备编写、调试和运行C语言程序的能力。
3.情感态度价值观目标:培养学生对计算机科学的兴趣,提高学生解决问题的能力,培养学生的创新精神和团队合作意识。
二、教学内容本课程的教学内容主要包括C语言的基本语法、数据类型、运算符、控制结构、函数等编程基础,以及图书馆管理系统的项目实践。
具体安排如下:1.第一章:C语言概述,介绍C语言的历史、特点和基本语法。
2.第二章:数据类型和运算符,学习基本数据类型、字符串、运算符及其优先级。
3.第三章:控制结构,学习条件语句、循环语句和跳转语句。
4.第四章:函数,学习函数的定义、声明和调用,以及常用标准库函数。
5.第五章:数组和字符串,学习一维数组、多维数组、字符串的基本操作。
6.第六章:指针,学习指针的概念、运算和应用。
7.第七章:结构体和文件,学习结构体的定义和应用,以及文件的读写操作。
8.第八章:图书馆管理系统项目实践,运用所学知识设计并实现一个简单的图书馆管理系统。
三、教学方法本课程采用多种教学方法相结合的方式,包括:1.讲授法:讲解C语言的基本语法、数据类型、运算符、控制结构、函数等编程基础。
2.案例分析法:通过分析典型的图书馆管理场景,引导学生运用C语言进行程序设计。
3.实验法:让学生动手编写、调试和运行C语言程序,提高学生的实践能力。
4.小组讨论法:分组进行项目实践,培养学生的团队合作意识和问题解决能力。
四、教学资源1.教材:《C程序设计语言》(K&R)或《C语言 Primer》(第五版)。
2.参考书:《C语言编程思想》、《C语言深度探索》。
3.多媒体资料:课件、教学视频、在线教程。
实操考核:用C#开发一个图书管理系统引言图书管理系统是一个常见的管理系统,在图书馆、学校和其他机构中被广泛使用。
通过使用C#语言开发一个图书管理系统,我们能够练习和巩固我们在C#编程方面的知识和技能。
本文将引导你从头开始构建一个基本的图书管理系统,并提供一些相关的代码示例和实操建议。
1. 项目概述1.1 项目背景图书管理系统主要用于记录和管理图书的信息,包括书名、作者、出版社、ISBN等。
用户可以通过系统进行图书的借阅、归还、查询等操作。
这个系统需要能够在存储和管理大量图书信息的同时,提供快速和准确的查询结果。
1.2 项目目标本项目的目标是通过C#语言开发一个简单但功能完整的图书管理系统。
系统应具备以下基本功能: - 记录和管理图书信息:包括书名、作者、出版社、ISBN等; - 借阅和归还图书:用户能够借阅和归还图书,并记录借阅和归还的时间; -查询图书信息:用户能够通过书名、作者、ISBN等关键字查询图书信息; - 统计和报表功能:系统能够生成各种统计信息和报表,如借阅次数、出版社统计等。
2. 系统设计2.1 数据模型设计在开发图书管理系统之前,我们首先需要设计系统的数据模型。
数据模型定义了系统中的实体及其之间的关系。
在本系统中,我们可以定义以下几个实体:- 图书(Book):包括书名、作者、出版日期、出版社、ISBN等属性; - 用户(User):包括用户名、密码、角色等属性; - 借阅记录(BorrowRecord):包括借阅时间、归还时间、借阅状态等属性。
2.2 系统架构设计系统架构设计是指确定系统的整体结构和组成部分。
在本项目中,我们可以采用三层架构设计,将系统分为表示层、业务逻辑层和数据访问层。
•表示层(Presentation Layer):负责与用户进行交互,接收用户的输入和展示查询结果等。
•业务逻辑层(Business Logic Layer):负责处理系统的业务逻辑,例如借阅、归还、查询等操作。
C程序设计报告图书管理系统设计题目:图书管理系统设计要求:利用C语言实现小型的图书管理系统,能够满足基本的借阅功能。
1.1问题提出:本人计划编写一个图书管理系统,主要是提供具有图书管理的程序。
本人的主要工作就是,编写出一个正确的程序,使其正常运行,实现图书管理功能!1.2本系统主要会涉及的知识点:结构,数组,循环,函数,判断,指针等语句的应用。
1.3主要功能要求:功能分析:从图书馆的管理功能上分析,图书馆一共有三个方面的需求。
1 对用户的管理。
2 对图书的管理。
3 对借阅的管理。
因此,本系统也从以上三个方面进行了设计,以实现上面的功能。
具体分析如下1 注册用户管理(以学校为样体,用户为学生)学生信息包括:学生ID,学生姓名,学生学号,所在院系,所在班级,性别,年龄。
(1)学生加入需要依次输入学生ID,学生姓名,学生学号,所在院系,所在班级,性别,年龄。
不能为空。
(2)学生删除此处用一个查询功能,是你方便的找到要删除的学生,同时显示该学生的信息,并要求删除确认。
(3)学生信息修改使用系统提供的查找功能可以迅速的找到要修改的学生,并提示修改的信息。
2 图书信息管理图书信息包括:图书ID,图书名字,图书作者,在馆状态。
(1)新书入库需要填入图书ID,图书名字,图书作者,在馆状态;其中在馆状态需要填:true,表示图书在馆。
(2)旧书删除对不用的旧书可以执行该操作。
可以使用系统提供的查找符合条件的图书,并可以同步显示该图书的信息,以便确认所删图书的正确性。
(3)图书信息修改当图书的信息发生改变的时候可以使用该功能来更新图书的信息,以保证图书信息的正确性。
操作是只要用系统提供的查找功能找到该图书,就可以在信息显示栏中对图书信息做修改。
3 图书借阅管理:图书借阅信息包括:借阅号,图书ID,学生ID,是否借出,借出日期,是否归还,归还日期。
(1)图书借阅:需要图书ID,学生ID。
(2)图书归还:需要图书ID,学生ID。
C语言课程设计-小型书店管理系统简介本文档旨在设计一个小型书店管理系统,使用C语言实现。
该系统将提供以下功能:1. 登录:管理员和员工可以使用自己的账号和密码登录系统。
2. 书籍管理:管理员可以添加、编辑和删除书籍信息。
3. 销售管理:员工可以记录每一笔销售,包括售出的书籍、销售时间和销售数量。
4. 会员管理:系统可以管理会员信息,包括会员的姓名、手机号码和积分等。
5. 库存管理:系统可以记录书籍的库存信息,包括书籍的数量和位置。
功能说明登录- 系统启动时,提示用户输入账号和密码。
- 系统验证账号和密码是否正确,允许管理员和员工登录。
- 登录成功后,进入主菜单。
书籍管理- 管理员在主菜单选择书籍管理,可以进行以下操作:- 添加书籍:输入书籍的名称、作者、出版社和价格等信息,保存到系统中。
- 编辑书籍:选择要编辑的书籍,并修改相关信息。
- 删除书籍:选择要删除的书籍,并从系统中删除。
- 查看书籍列表:显示系统中所有的书籍信息。
销售管理- 员工在主菜单选择销售管理,可以进行以下操作:- 记录销售:选择要销售的书籍,并输入销售的数量。
- 系统更新库存信息,并生成销售记录,包括销售时间、图书名称和数量等。
- 销售记录可以用于后续的统计和分析。
会员管理- 管理员在主菜单选择会员管理,可以进行以下操作:- 添加会员:输入会员的姓名、手机号码和积分等信息,保存到系统中。
- 编辑会员信息:选择要编辑的会员,并修改相关信息。
- 删除会员:选择要删除的会员,并从系统中删除。
- 查看会员列表:显示系统中所有的会员信息。
库存管理- 系统会记录每本书籍的库存数量和位置。
- 当员工记录销售时,系统会自动更新库存信息。
- 员工可以在主菜单选择库存管理,查看当前库存情况。
技术实现本系统将使用C语言进行开发,主要使用以下技术:1. 数据结构:使用结构体来表示书籍、会员和销售记录等信息。
2. 文件操作:使用文件保存和读取数据,以实现数据的持久化。
图书管理系统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语言图书管理系统流程图概述:C语言图书管理系统是一个用于管理图书馆或书店的系统,它可以实现图书的添加、删除、查询和借还等功能。
本文将通过详细的流程图,介绍C语言图书管理系统的运行流程。
1. 添加图书:- 用户输入图书信息,包括书名、作者、出版日期和价格等。
- 系统接收用户输入的信息,并生成一个唯一的图书编号。
- 系统将图书信息和图书编号存储到数据库中。
2. 删除图书:- 用户输入要删除的图书编号。
- 系统在数据库中查找并验证该图书编号是否存在。
- 如果存在,则从数据库中删除该图书信息。
3. 查询图书:- 用户输入要查询的图书名称或作者等信息。
- 系统在数据库中查找与用户输入信息匹配的图书。
- 系统将符合条件的图书信息显示给用户。
4. 借阅图书:- 用户输入要借阅的图书编号。
- 系统在数据库中查找并验证该图书编号是否存在。
- 如果该图书可借,则系统记录借阅人的信息,标记该图书为已借出状态。
5. 归还图书:- 用户输入要归还的图书编号。
- 系统在数据库中查找并验证该图书编号是否存在,并检查该图书是否已借出。
- 如果该图书已借出且由用户借出,则系统记录归还时间,将该图书状态标记为可借。
6. 统计功能:- 用户选择统计功能入口。
- 系统提供多种统计选项,例如按照作者统计、按照出版日期统计、按照价格区间统计等。
- 系统在数据库中进行相应的查询并展示统计结果。
7. 备份与恢复:- 用户选择备份或恢复功能入口。
- 备份功能:系统将数据库中的图书信息备份到指定的文件中。
- 恢复功能:系统从指定的备份文件中还原图书信息到数据库中。
8. 系统维护:- 用户选择系统维护功能入口。
- 维护功能包括数据库清理、数据完整性检查、系统日志管理等。
- 用户可以根据需求选择相应的维护操作。
总结: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 课程设计图书馆系统一、课程目标知识目标:1. 学生能理解图书馆系统的基本概念,掌握其主要功能模块,如图书检索、借阅管理、用户管理等。
2. 学生能了解数据库的基础知识,学会使用SQL语句进行简单的数据操作。
3. 学生能了解软件工程的基本原理,通过分析图书馆系统的需求,学会进行模块划分和功能设计。
技能目标:1. 学生能运用所学知识,设计并实现一个简单的图书馆系统,具备基本的图书检索、借阅管理等功能。
2. 学生能通过小组合作,进行需求分析、系统设计、编码实现和测试,提高团队协作能力和沟通能力。
3. 学生能运用数据库技术,实现对图书馆数据的存储和管理,提高数据处理能力。
情感态度价值观目标:1. 学生通过本课程的学习,培养对信息科学的兴趣,激发探索精神。
2. 学生在图书馆系统的设计与实现过程中,培养严谨、细致的工作态度,提高解决问题的能力。
3. 学生通过小组合作,学会尊重他人意见,培养团队协作精神和责任感。
课程性质:本课程属于信息技术领域,结合软件工程、数据库和编程知识,培养学生的实际操作能力和团队协作能力。
学生特点:六年级学生具有一定的信息技术基础,对新鲜事物充满好奇,具备一定的自主学习能力和合作能力。
教学要求:结合学生特点,注重实践操作,鼓励学生主动探索,提高其运用信息技术解决实际问题的能力。
在教学过程中,关注学生的个体差异,提供有针对性的指导,确保每个学生都能达到课程目标。
通过课程学习,使学生将所学知识内化为实际操作能力,提高其综合素质。
二、教学内容1. 图书馆系统概述:介绍图书馆系统的基本概念、功能模块及其作用,关联教材第2章“信息系统简介”。
- 图书检索模块- 借阅管理模块- 用户管理模块2. 数据库基础知识:讲解数据库的基本概念、关系型数据库的组成及SQL语句的使用,关联教材第4章“数据库技术”。
- 数据库基本概念- 关系型数据库- SQL语句操作3. 软件工程基础:介绍软件工程的基本原理,重点讲解需求分析、系统设计和模块划分,关联教材第6章“软件工程”。
#include "stdio.h"#include "conio.h"#include "stdlib.h"#include "string.h"#define MAX 10/*定义图书信息结构体数组*/typedef struct{long No; /*图书编号*/char name[10]; /*图书名称*/char sort[10]; /*图书类别*/int sum; /*图书总量*/char writer[10]; /*图书作者*/char publish[20]; /*图书出版社*/int time; /*图书出版时间*/char lend[10]; /*图书借阅信息*/}Message;/*读取图书信息*/int read_book(Message Book[]){int i=0;FILE *fp;fp=fopen("d:\\book.txt","r");if(fp==NULL) {printf("该文件不存在!\n");return -1;}while(!feof(fp)){fscanf(fp,"%d%s%s%d%s%s%d\n",&Book[i].No,&Book[i].name,&Book[i].sort,&Book[i].s um,&Book[i].writer,&Book[i].publish,&Book[i].time);i++;printf("\n");}return i;}/*输出图书信息*/void print_book(Message Book[],int i){int k;printf(" 图书编号------名称------类别------数量-----作者--------出版社-----出版日期\n");for(k=0;k<i+1;k++)printf(" %ld %s %s %d %s %s %d\n",Book[k].No,Book[k].name,Book[k].sort,Book[k].sum,Book[k].writer,Book[k].publish,Book[k].time);printf("--------------------------------------------------------------------------\n"); printf("按任意键返回主菜单!");getch();}/*按图书编号升序排列*/void sort_book1(Message Book[],int cnt){Message t;int i,j;for(i=0;i<cnt-1;i++)for(j=i+1;j<cnt;j++)if(Book[i].No>Book[j].No){t=Book[i];Book[i]=Book[j];Book[j]=t;}}/*按图书类别排序*/void sort_book2(Message Book[],int cnt){Message t;int i,j;for(i=0;i<cnt-1;i++)for(j=i+1;j<cnt;j++)if((strcmp(Book[i].sort,Book[j].sort))>0){t=Book[i];Book[i]=Book[j];Book[j]=t;}}/*添加新书信息*/int add_book(Message Book[],int i){ FILE *fp;char ch;printf("*************************************************************************\n"); do{printf("请输入新书编号:");scanf("%ld",&Book[i].No);printf("请输入新书书名:");scanf("%s",&Book[i].name);printf("请输入新书类别:");scanf("%s",&Book[i].sort);printf("请输入新书总量:");scanf("%d",&Book[i].sum);printf("请输入新书作者:");scanf("%s",&Book[i].writer);printf("请输入新书出版社:");scanf("%s",&Book[i].publish);printf("请输入新书出版时间:");scanf("%ld",&Book[i].time);strcpy(Book[i].lend,"可借");fp=fopen("d:\\book.txt","a");fprintf(fp,"%ld %s %s %d %s %s %d\n",Book[i].No,Book[i].name,Book[i].sort,Book[i].sum,Book[i].writer,Book[i].publish,Book[i].time);fclose(fp);i++;printf("输入完毕!\n是否还要添加?(请输入Y/N):");flushall();scanf("%c",&ch);}while(ch=='Y');return i;}/*修改图书信息*/void change_book(Message Book[],int count){int i,sum;long no,num,time;FILE *fp;char name[10],sort[10],writer[10],publish[20];printf("*************************************************************************\n");printf("请输入要修改图书的编号:");scanf("%ld",&no);for(i=0;i<count;i++)if(no==Book[i].No) { printf("请输入新书编号:");scanf("%ld",&num);Book[i].No=num;printf("请输入新书书名:");scanf("%s",name);strcpy(Book[i].name,name);printf("请输入新书类别:");scanf("%s",sort);strcpy(Book[i].sort,sort);printf("请输入新书总量:");scanf("%d",&sum);Book[i].sum=sum;printf("请输入新书作者:");scanf("%s",writer);strcpy(Book[i].writer,writer);printf("请输入新书出版社:");scanf("%s",publish);strcpy(Book[i].publish,publish); printf("请输入新书出版时间:");scanf("%ld",&time);Book[i].time=time;break;}fp=fopen("d:\\book.txt","w");for(i=0;i<count;i++)fprintf(fp,"%ld %s %s %d %s %s%d\n",Book[i].No,Book[i].name,Book[i].sort,Book[i].sum,Book[i].writer,Book[i].publish,Book[i].time);fclose(fp);}/*按图书类别查询书目*/void inquir_book1(Message Book[],int count){char a[10],ch;int i=0,k,cnt=0;long no;printf("请输入查询图书类别(不可含空格):");scanf("%s",a);flushall();for(k=0;k<count;k++){if(strcmp(a,Book[k].sort)==0){printf(" 图书编号------名称------类别------数量-----作者--------出版社-----出版日期\n");printf(" %ld %s %s %d %s %s%d\n",Book[k].No,Book[k].name,Book[k].sort,Book[k].sum,Book[k].writer,Book[k].publish,Book[k].time);printf("--------------------------------------------------------------------------\n");printf("\n");cnt++;}}if(cnt==0&&k==count) {printf("您所查询的图书不存在!\n");getch();exit(1);}printf("您是否借阅该书?(请输入Y/N)\n");scanf("%c",&ch);if(ch=='Y') {if(cnt>1) {printf("请输入要借阅图书的编号:");scanf("%ld",&no);for(i=0;i<count;i++)if(Book[i].No==no){if(strcmp(Book[i].lend,"借出")==0) {printf("对不起,该书已被借阅!");printf("按任意键返回主菜单!");getch();}else {strcpy(Book[i].lend,"借出");printf("借阅成功!");printf("按任意键返回主菜单!");}break;}}else if(strcmp(Book[k-1].lend,"借阅")==0) {printf("对不起,该书已被借阅!");printf("按任意键返回主菜单!");getch();}else {strcpy(Book[k-1].lend,"借阅");printf("借阅成功!\n");printf("按任意键返回主菜单!\n");}}if(ch=='N') printf("按任意键返回主菜单!");getch();}/*按图书书名查询*/void inquir_book2(Message Book[],int count){char a[10],ch;int i=0,k,cnt=0;long no;printf("请输入查询图书书名(不可含空格):");scanf("%s",a);flushall();for(k=0;k<count;k++){if(strcmp(a,Book[k].name)==0){printf(" 图书编号------名称------类别------数量-----作者--------出版社-----出版日期\n");printf(" %ld %s %s %d %s %s %d\n",Book[k].No,Book[k].name,Book[k].sort,Book[k].sum,Book[k].writer,Book[k].publish,Book[k].time);printf("--------------------------------------------------------------------------\n"); printf("\n");cnt++;}}if(cnt==0&&k==count) {printf("您所查询的图书不存在!\n");getch();exit(1);}printf("您是否借阅该书?(请输入Y/N)\n");scanf("%c",&ch);if(ch=='Y') {if(cnt>1) {printf("请输入要借阅图书的编号:");scanf("%ld",&no);for(i=0;i<count;i++)if(Book[i].No==no){if(strcmp(Book[i].lend,"借出")==0) {printf("对不起,该书已被借阅!");printf("按任意键返回主菜单!");getch();}else {strcpy(Book[i].lend,"借出");printf("借阅成功!\n");printf("按任意键返回主菜单!");}break;}}else if(strcmp(Book[k-1].lend,"借出")==0) {printf("对不起,该书已被借阅!");printf("按任意键返回主菜单!");getch();}else {strcpy(Book[k-1].lend,"借出");printf("借阅成功!\n");printf("按任意键返回主菜单!");}}if(ch=='N') printf("按任意键返回主菜单!");getch();}/*图书借阅管理*/void lend_book(Message book[],int count){int i;printf("*************************************************************************\n");printf(" 图书编号---------------书名---------------借阅信息\n\n");for(i=0;i<count;i++)printf(" %ld %s %s\n",book[i].No,book[i].name,book[i].lend);printf("按任意键返回主菜单!");getch();}void main(){int cnt,cnt1,i,choice,choice1,choice2;Message book[MAX];cnt=read_book(book);cnt1=cnt;for(i=0;i<cnt;i++)strcpy(book[i].lend,"可借");if(cnt==-1) {getch();exit(1);}else{do{system("cls");printf("\n\n\n");printf(" *****************************图书管理系统********************************\n\n");printf(" 1.查看书目信息\n\n");printf(" 2.添加新书信息\n\n");printf(" 3.修改图书信息\n\n"); printf(" 4.查询书目信息\n\n");printf(" 5.借阅管理信息\n\n");printf(" 6.退出系统\n\n");printf(" 请选择(1-6):");scanf("%d",&choice);switch(choice){case 1: if(cnt==0){printf("馆中无书籍,请添加!\n(按任意键返回主菜单添加!)");getch();break;}else{printf(" -----------------------------书目查询方法-------------------------------\n\n");printf(" 1.按图书编号升序排列\n\n");printf(" 2.按图书类别排序\n\n"); printf("------------------------------------------------------------------------\n\n"); printf(" 请选择书目排序方法(1或2):");scanf("%d",&choice1);switch(choice1){case 1:sort_book1(book,cnt1);print_book(book,cnt1-1);break;case 2:sort_book2(book,cnt1);print_book(book,cnt1-1);break;}}break;case 2:cnt1=add_book(book,cnt);printf("按任意键返回主菜单!");getch();break;case 3:change_book(book,cnt1);print_book(book,cnt1-1);break;case 4:printf(" -----------------------------书目排序方法-------------------------------\n\n");printf(" 1.按图书类别查询书目\n\n");printf(" 2.按图书书名查询\n\n"); printf("------------------------------------------------------------------------\n\n"); printf(" 请选择书目查询方法(1或2):");。
课程设计(大作业)报告课程名称:数据结构课程设计设计题目:小型图书馆管理系统院系:信息技术学院班级:计算机科学与技术3班设计者:学号:*******指导教师:***设计时间:2012.12.24--28昆明学院课程设计(大作业)任务书一、题目分析本题是一个图书馆管理系统,涉及到c语言的一些基本操作,比如,构造结构体,插入,查找等!这个程序包括构造一个结构体,域为:书号,书名,作者,出版商,出版日期。
运用文件操作的方式实现文件的保存与调用!用菜单界面来操作整个过程!先写每个功能的程序,然后再组合起来,这样显得调理清晰,不容易乱!二、基本理论C语言的基本知识,比如结构体的构造,链表的操作,文件的操作三、总体设计函数功能:struct books_list * Create_Books_Doc(); /*新建链表*/void InsertDoc(struct books_list * head); /*插入*/void DeleteDoc(struct books_list * head , int num);/*删除*/void Print_Book_Doc(struct books_list * head);/*浏览*/void search_book(struct books_list * head); /*查询*/void info_change(struct books_list * head);/*修改*/void save(struct books_list * head);/*保存数据至文件*/四、实验器材Pc机五、方法步骤1. 创建主函数main()2新建数据文件create()2.1为节点分配内存2.2创建二进制文件用于存储图书信息2.3通过一个循环一次录入图书信息2.4关闭文件3.编写删除数据纪录函数delete()3.1打开文件3.2遍历文件找到与指定图书信息匹配的记录并删除3.3关闭文件4.编写浏览数据记录函数Print_Book_Doc()4.1打开文件4.2遍历整个数据。
#include <iostream>#include <string>#include <conio.h>#include <iomanip>using namespace std;class reader;class base{ protected:string name,number;};class book:public base{ protected:string author;book *next;public:friend class reader;};class reader:public base{ public:void outputreader();book *borrow();book *giveback(book *head);void show(book *head);protected:int amount;};void reader::outputreader(){ cout<<endl<<" 读者:"; cin>>name;cout<<" 卡号:"; cin>>number;}book *reader::borrow(){ clrscr();book *p1,*p2,*h;h=NULL;cout<<endl<<"欲借书数目:";cin>>amount;if((amount<0)||(amount>5)){ cout<<endl<<"输入错误!请重新输入(0<=N<=5)!"<<endl<<"欲借书数目:";cin>>amount;}if(amount!=0){ h=new book;p1=h;for(int i=1;i<=amount;i++){ cout<<endl<<"书名:";cin>>p1->name;cout<<"编号:";cin>>p1->number;cout<<"作者:";cin>>p1->author;p2=new book;p1->next=p2;p1=p2;}p2=NULL;}return h;}book *reader::giveback(book *head){ clrscr();book *p3,*p4;if(head!=NULL){ string num;cout<<endl<<"欲还书的编号:"; cin>>num;p3=head;while(num!=p3->number&&p3->next!=NULL){ p4=p3;p3=p3->next; }if(num==p3->number){ if(p3==head) { head=p3->next; delete p3;}else { p4->next=p3->next; delete p3;}cout<<"还书成功!"<<endl<<"回车键返回!";}elsecout<<"暂无找到编号为"<<num<<"的书"<<endl<<"回车键返回!"; }else cout<<name<<"暂无借书!"<<endl<<"回车键返回!";getchar();getchar();return head;}void reader::show(book *head){ book *p;p=head;if(head){ clrscr();cout<<name<<"同学借书情况如下:"<<endl<<endl;while(p->next!=NULL){ cout<<"书名:"<<p->name<<endl;cout<<"编号:"<<p->number<<endl;cout<<"作者:"<<p->author<<endl<<endl;p=p->next;}}else{ clrscr();cout<<name<<"暂无借书!";}cout<<endl<<"回车键返回!";getchar();getchar();}int main(){ int choice=1;reader unknow;book *head=NULL;unknow.outputreader();while(choice){ clrscr();cout<<endl<<endl<<endl<<endl<<endl<<endl;cout<<setw(45)<<"==================="<<endl;cout<<setw(45)<<"| |"<<endl;cout<<setw(45)<<"| 1.借书|"<<endl;cout<<setw(45)<<"| 2.还书|"<<endl;cout<<setw(45)<<"| 3.浏览|"<<endl;cout<<setw(45)<<"| 0.退出|"<<endl;cout<<setw(45)<<"| |"<<endl;cout<<setw(45)<<"==================="<<endl;cout<<setw(45)<<" 请选择:"; cin>>choice;if(choice!=1&&choice!=2&&choice!=3&&choice!=0){ cout<<"请重新选择:"; cin>>choice;}switch(choice){ case 1: head=unknow.borrow(); break;case 2: head=unknow.giveback(head); break;case 3: unknow.show(head); break;}}return 0;}#include<iostream.h>#include<fstream.h>#include<string.h>#include<stdio.h>#include<stdlib.h>#include<time.h>#include<iomanip.h>#define MAX 20class Reader{public:char tag;int num,book_sum;char name[10];int book_num[5];time_t time1[5];};class Reader_source:public Reader{public:void show();void save();Reader reader[MAX];int n;int Findreader(int readernum,char*readername); Reader_source();int Get_time(char *,int);int Get_date(char *);int Get_booksum(char *);int Borrow(char*,char *);int Put_back(char*,int,char *);void Show_Book(char*);void Addreader(char*);void chang(int );void Delreader(int);~Reader_source();};class Book{public:int book_sum,book_out;char book_name[20],LOGIN[4],writer_name[10]; int booknum;char tag;};class Book_source:public Book{public:void save();Book book[MAX];int n;int AddBooknum(int);void Check_Book(int);int Putback(int num,char*bookname);int borrow(char*bookname);int AddBookkind(char *,char *,char *);void ShowBook();void Addbook(char*,char*,char*);void DelBook(char*LOGIN_num);void chang(char*LOGIN_num);int is_Having(char*);void show();Book_source();~Book_source();};Book_source book; //定义书变量Reader_source reader; //定义读者变量Book_source::~Book_source() //析构函数{ofstream outfile;outfile.open("book_lib.txt");for(int i=0;i<n;i++)outfile.write((char*)(book+i),sizeof(Book)); outfile.close();}Book_source::Book_source() //载入图书信息{ifstream infile;infile.open("book_lib.txt");n=0;while(!infile.eof()){infile.read((char*)(book+n),sizeof(Book));if(book[n].booknum!=0)n++;}}void Book_source::Addbook(char*LOGIN,char*Bookname,char*writername ) //增加新书{int p;if(p=is_Having(LOGIN)){AddBooknum(p);cout<<"该书已存在!\n";}else{if(AddBookkind(Bookname,writername,LOGIN))cout<<"新书添加成功!\n";else cout<<"添加失败!\n";}}void Book_source::Check_Book(int num) //查找图书{for(int i=0;i<n;i++)if(book.booknum==num&&book.tag!='0'){cout<<" 书号:"<<book.booknum<<" \n书目编号:"<<book.LOGIN<<" \n书名:"<<book.book_name<<"\n作者:"<<book.writer_name<<" \n图书总数:"<<book.book_sum< <" \n借出: "<<book.book_out<<"本 "<<endl;cout<<"此书现库存有"<<book.book_sum-book.book_out<<"本"<<endl;return ;}cout<<"操作失败!不存在此书!"<<endl;return ;}void Book_source::DelBook(char*LOGIN_num) //删除图书{ if(is_Having(LOGIN_num)==0){cout<<"\n@@@@@@@@@@@@@@@操作失败没有此书";retur n;}int i=is_Having(LOGIN_num);book.tag='0';n--;cout<<"\n@@@@@@@@@@@@@@@@@@Congratulation!!!!!!!删除成功";return;}void Book_source::chang(char*LOGIN_num){ if(is_Having(LOGIN_num)==0){cout<<"\n@@@@@@@@@@@@@@@操作失败没有此书";retur n;}int i=is_Having(LOGIN_num);cout<<"请输入你要修改的书名\n";cin>>book.book_name;cout<<"书目编号\n";cin>>boo k.LOGIN;cout<<"作者名\n";cin>>book.writer_name;cout<<"\n@@@@@@@@@@@@@@@@@@Congratulation!!!!!!!修改成功!";return;}int Book_source::is_Having(char*LOGIN_num) //查找是否存在图书{int i=0;for(i;i<=n;i++){if(strcmp(LOGIN_num,book.LOGIN)==0){ if(book.tag=='1')return i+1;}}return 0;}void Book_source::ShowBook() //显示图书{cout<<setiosflags(ios::right)<<setw(5)<<"书号"<<setw(10)<<"书目编号"<<setw (15)<<"书名"<<setw(15)<<"作者"<<setw(10)<<"本数"<<setw(8)<<"借出数"<<endl;for(int i=0;i<n;i++){if(book.booknum!=0&&book.tag!='0'){cout<<setiosflags(ios::right)<<setw(5)<<book.booknum<<setw(10)<<book.LOGIN<<setw(18)<<book.book_name<<setw(14)<<book.writer_name<<setw(5)<<book.bo ok_sum<<setw(8)<<book.book_out<<endl;}}}Reader_source::Reader_source() //载入读者信息{ifstream infile;infile.open("bookreader.txt");n=0;while(!infile.eof()){infile.read((char*)(reader+n),sizeof(Reader));if(reader[n].num!=0&&reader[n].tag!='0')n++;}}Reader_source::~Reader_source() //析构函数{ofstream outfile;outfile.open("bookreader.txt");for(int i=0;i<n;i++){outfile.write((char*)(reader+i),sizeof(Reader));}outfile.close();}int Reader_source::Get_date(char *readername){for(int i=0;i<n;i++)if(strcmp(readername,)==0)return i;return 0;}int Reader_source::Get_time(char *readername,int booknum) //获得借书时长{int i=Get_date(readername);for(int a=0;a<reader.book_sum;a++)if(reader.book_num[a]==booknum){struct tm *mt;time_t t;t=time(NULL);t=t-reader.time1[a];mt=localtime(&t);cout<<"书号:"<<reader.book_num[a]<<"借书时长: "<<mt->tm_yday<<"天"<<mt ->tm_hour+8<<"小时"<<endl;return 1;}return 0;}int Reader_source::Get_booksum(char *readername) //获得图书数量{for(int i=0;i<n;i++)if(strcmp(,readername)==0)if(reader.book_sum==5){cout<<"借书已满5本!\n";return 0;}else{return 1;}return 0;}int Reader_source::Borrow(char*bookname,char *readername) //借书{int i;for(i=0;i<n;i++)if(strcmp(,readername)==0)if(book.borrow(bookname)){if(reader.book_sum<5){time_t t;t=time(NULL);reader.time1[reader.book_sum]=t;reader.book_sum++;return 1;}return 0;}return 0;}int Reader_source::Put_back(char*bookname,int booknum,char *readername) //还书函数{int i;for(i=0;i<n;i++)if(strcmp(,readername)==0)if(book.Putback(booknum,bookname)){for(int m=0;m<reader.book_sum;m++)if(reader.book_num[m]==booknum){if(Get_time(readername,booknum))reader.book_sum--;return 1;}elsereturn 0;}return 0;}void Reader_source::Addreader(char*newer_name) //增加读者{strcpy(reader[n].name,newer_name);reader[n].num=reader[n-1].num+1;reader[n].book_sum=0;for(int i=0;i<5;i++){reader[n].book_num=0;reader[n].time1=0;}cout<<"添加成功";cout<<"该添加读者的借书号为:"<<reader[n].num;n++; }void Reader_source::Delreader(int reader_num) //删除读者{for(int m=0;m<n;m++)if(reader_num==reader[m].num){reader[m].num=0;reader[m].tag='0';cout<<"CONGRATULATION!!!!!!删除成功"<<endl;return;}cout<<"没有这个借书号的人存在!请查正!"<<endl;return ;}void Reader_source::chang(int reader_num){for(int m=0;m<n;m++)if(reader_num==reader[m].num){ char name[10];cout<<"请输入你要改的读者名"; cin>>reader[m].name; cout<<"\nCongratulation s!!!!!!!修改成功"; return;}cout<<"没有这个借书号的人存在!请查正!"<<endl;return ;}void Reader_source::Show_Book(char*readername) //显示图书{for(int i=0;i<n;i++)if(strcmp(readername,)==0){cout<<"借书号: "<<reader.num<<"姓名: "<<<<endl;cout<<"现在已借书"<<reader.book_sum<<"本";cout<<"\n还可以借"<<5-reader.book_sum< <"本";for(int m=0;m<reader.book_sum;m++){struct tm *mtt;mtt=localtime(&reader.time1[m]);cout<<"借书情况如下\n";cout<<"书号:"<<reader.book_num[m]<<"借书时间:"<<asctime(mtt)<< endl;}}}int Book_source::AddBooknum(int m) //增加图书数量{book[m-1].book_sum++;return 1;}int Book_source::AddBookkind(char *bookname,char *writername,char *LPISBN) //增加新图书{strcpy(book[n].book_name,bookname);strcpy(book[n].writer_name,writername);strcpy(book[n].LOGIN,LPISBN);book[n].book_sum=1;book[n].book_out=0;book[n].booknum=book[n-1].booknum+1;book[n].tag='1';n++;return 1;}void Book_source::save() //保存图书信息{ofstream outfile;outfile.open("book_lib.txt");for(int i=0;i<n;i++){if(book.booknum!=0&&book.tag!='0')outfile.write((char*)(book+i),sizeof(Book)); }outfile.flush();ifstream infile;infile.open("book_lib.txt");n=0;while(!infile.eof()){infile.read((char*)(book+n),sizeof(Book)); if(book[n].booknum!=0)n++;}}int Reader_source::Findreader(int readernum,char*readername) //查找读者{for(int i=0;i<n;i++)if(strcmp(,readername)==0&&reader.num==readernum&&reader.tag!='0 '){return i;}else{cout<<"没有此人!\n";return 0;}}void Reader_source::show()cout<<setw(10)<<"姓名"<<" "<<setw(5)<<"借书号\n";for(int i=0;i<n;i++)cout<<setw(10)<<<<" "<<setw(5)<<reader.num<<endl;}void Book_source::show(){cout<<setw(10)<<"书名"<<" "<<setw(5)<<"作者名"<<" "<<setw(5)<<"书目编号"<<" "<<setw(5)<<"图书总数\n";for(int i=0;i<n;i++)cout<<setw(10)<<book.book_name<<" "<<setw(5)<<book.writer_name<<" "<<setw (5)<<book.LOGIN<<" "<<setw(5)<<book.book_sum<<endl;}int Book_source::borrow(char*bookname){for(int i=0;i<n;i++){if(strcmp(bookname,book.book_name)==0){if(book.book_sum==book.book_out)return 0;book.book_out++;return 1;}}return 0;}int Book_source::Putback(int num,char*bookname) ////图书库的还书操作函数{for(int i=0;i<n;i++){if(strcmp(bookname,book.book_name)==0&&book.booknum==num){if(book.book_out<=0)return 0;book.book_out--;return 1;}}return 0;}void Reader_source::save() //读者信息保存函数{ofstream outfile;outfile.open("bookreader.txt");for(int i=0;i<n;i++){if(reader.num!=0&&reader.tag!='0')outfile.write((char*)(reader+i),sizeof(Reader));}outfile.flush();ifstream infile;infile.open("bookreader.txt");n=0;while(!infile.eof()){infile.read((char*)(reader+n),sizeof(Reader));if(reader[n].num!=0)n++;}}void add_book() //读者增加函数{char LOGIN[4],writername[10],Bookname[20];cout<<"输入所要增加图书的书目编号:";cin>>LOGIN;cout<<"\n输入所要增加图书的作者名字:";cin>>writername; cout<<"\n输入所要增加图书的书名:";cin>>Bookname;book.Addbook(LOGIN,Bookname,writername );book.save();}void checkbook() //图书查找函数{int num;cout<<"\n输入所要查询图书的书号:";cin>>num; book.Check_Book(num);}void Delbook() //图书删除函数{char LOGIN[4];cout<<"\n输入所要删除图书的书目编号:";cin>>LOGIN; book.DelBook(LOGIN);book.save();}void Changbook(){ char LOGIN[4];cout<<"\n输入所要修改的图书的书目编号:";cin>>LOGIN; book.chang(LOGIN);book.save();}void showbook(){book.show();}void Lib_man() //图书库管理{system("cls");while(1){ system("color 06f");cout<<"\n输入要进行的操作:\n\n1.新增图书\n 2.图书查询\n 3.删除图书\n 4.修改图书\n 5.显示已有图书列表\n 6.退出当前操作\n\n 输入操作选项代码:";int ch;cin>>ch;switch(ch){case 1:add_book();break;case 2:checkbook();break;case 3:Delbook();break;case 4:Changbook();break;case 5:showbook();break;default:return;}}}void addreader() //增加读者函数{char name[10];cout<<"\n输入所要增加的读者的姓名:";cin>>name; reader.Addreader(name);reader.save();}void Delreader() //读者删除函数{int num;cout<<"\n输入所要删除读者的借书号:";cin>>num; reader.Delreader(num);reader.save();}void Changreader(){int num;cout<<"\n输入所要修改读者的借书号:";cin>>num; reader.chang(num);reader.save();}void showreader(){reader.show();}void reader_man() //读者信息的管理{system("cls");while(1){system("color 02a");cout<<"\n输入所要进行的操作:\n1.增加读者\n 2.删除读者\n 3.显示已经存在的读者列表\n 4.修改读者信息\n 5.退出本操作\n\n请选择数字代码:";int ch;cin>>ch;switch(ch){case 1:addreader();break;case 2:Delreader();break;case 3:showreader();break;case 4:Changreader();break;default:return;}}}void Borrow() //调用借书函数{char name[10];int num;cout<<"\n输入借书人的姓名和借书号"; cout<<"\n\n\n 姓名:";cin>>name;cout <<" \n借书号:";cin>>num;char bookname[20];int booknum;cout<<"\n输入书名:";cin>>bookname;if(reader.Borrow(bookname,name))cout<<"借书成功!\n";else cout<<"&&&&&&&&&&& &&&&很抱歉输入信息有误借书操作失败请重新输入!&&&&&&&&&&&&&!\n";book.save();reader.save();}void return_book() //还书函数{char name[10];int num;cout<<"\n输入借书人的姓名和借书号";cout<<"\n姓名:";cin>>name;cout<<" 借书号:";cin>>num;char bookname[20];int booknum;cout<<"\n输入书名:";cin>>bookname;cout<<" \n输入书号:";cin>>booknum;if(reader.Put_back(bookname,booknum,name))cout<<"操作成功!\n";else cout<<"& &&&&&&&&&&&&&&很抱歉输入信息有误还书操作失败&&&&&&&&&&&&&&&&&&\n";reader.save();book.save();}void showreaderbook() //显示读者信息{char readername[10];cout<<"\n输入借书人的姓名:";cin>>readername;reader.Show_Book(readername);}void showbooklibbook() //显示书库信息{book.ShowBook();}void show_book() //图书{system("cls");while(1){system("color 01f");int ch;cout<<"\n选择要进行的操作:\n\n1.查询读者的借书状态\n 2.检查图书馆图书储存状态\n 3.退出本操作\n\n请选择数字代码:";cin>>ch;switch(ch){case 1:showreaderbook();break;case 2:showbooklibbook();break;default:return;}}}void main() //主函数{ cout<<" &&&&& &&&&&\n";cout<<" WELCOME \n\n";cout<<"\n THANK YOU FOY LOG IN \n";cout<<" &~&图书管理系统&~&\n\n\n";while(1){system("color 03a");system("cls");cout<<"\n@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ "; cout<<"\n^^^^ 1、读者信息的管理 @ @ ";cout<<"\n^^^^^^ 2、图书库的修改和维护 @ @"; cout<<"\n^^^^^^^^ 3、进行借书的操作 @ @";cout<<"\n^^^^^^^^^^ 4、进行还书的操作 @ @";cout<<"\n^^^^^^^ 5、查询功能 @ @";cout<<"\n^^^^^输入其他数字.退出该程序 @ @ @ @ @ @ @ ";cout<<"\n\n\n \n你要进行的操作(输入选项的数字代码):";int ch;cin>>ch;switch(ch){case 1:reader_man();break;case 2:Lib_man();break;case 3:Borrow(); break;case 4:return_book(); break;case 5:show_book(); break;default:return;}system("cls");}}。