图书管理系统程序源代码

合集下载

图书管理系统程序源代码

图书管理系统程序源代码

源程序1.主窗体Private Sub add_back_Click()frmbackbookinfo.ShowEnd SubPrivate Sub add_binf_Click()frmaddbookinfo.ShowEnd SubPrivate Sub add_book_style_Click()frmaddbookstyle。

ShowEnd SubPrivate Sub add_manager_Click()frmadduser.ShowEnd SubPrivate Sub add_rinf_Click() frmaddreaderinfo.ShowEnd SubPrivate Sub add_rstyle_Click()frmaddreaderstyle.ShowEnd SubPrivate Sub change_binf_Click() frmmodifybookinfo。

ShowEnd SubPrivate Sub change_book_style_Click()frmmodifybookstyle。

ShowEnd SubPrivate Sub delete_binf_Click()frmmodifybookinfo。

ShowEnd SubPrivate Sub delete_book_style_Click()frmmodifybookstyle.ShowEnd SubPrivate Sub delete_rstyle_Click()frmmodifyreaderstyle。

ShowEnd SubPrivate Sub exit_Click()EndEnd SubPrivate Sub find_binf_Click()frmfindbook。

ShowEnd SubPrivate Sub find_lend_Click()frmfindborrowinfo。

ShowEnd SubPrivate Sub find_rinf_Click()frmfindreader.ShowEnd SubPrivate Sub password_Click()frmchangepwd。

C语言课程设计图书馆管理系统程序代码

C语言课程设计图书馆管理系统程序代码

#include〈stdio.h〉#include<windows.h〉#include〈string。

h〉#include<conio。

h>#define M 100struct books{char tsmc[12];inttsbh;float dj;char zz[12];char czzt[12];char xm[12];char xb[12];intxh; }s[M];int N;bool flag;intmain (){intsele;flag=0;sele=1;void sr();void cx();void sc();void js();void hs();void tc();void jsh();//system ("tsgl”);printf("\n\n");printf(" ************************\n"); printf(" 1:输入2:查询3:删除\n");printf(”4:借书5:还书0:退出\n");printf(” ************************\n"); while(1){printf(”\n\n请输入功能序号:");scanf (”%d",&sele);if(sele>=0 && sele<=5){switch(sele){case 1:sr();break;case 2:cx();break;case 3:sc();break;case 4:js();break;case 5:hs();break;case 0:jsh();break;}if(flag)break;printf(”\n\n");printf(” ************************\n”); printf(" 1:输入2:查询3:删除\n");printf(”4:借书5:还书0:退出\n”);printf(” ************************\n”);}else{printf(”输入错误请再次输入|\n\n");printf("\n\n");printf(” ************************\n”);printf(" 1:输入2:查询3:删除\n”);printf(”4:借书5:还书0:退出\n");printf(" ************************\n");}printf("\n\n让任意键继续\n”);} //wr_file();}/******主函数***//*********输入*********/void sr(){intn,i;N=0;printf("可输入的书本数:");scanf("%d",&n);N=n+N;printf("请输入相关信息:\n");for(i=1;i<=n;i++){printf(”图书名称:”);scanf(”%s",s[N-n-1+i]。

图书管理系统程序代码

图书管理系统程序代码

#include <stdio.h>#include <string.h>#include <stdlib.h>#define SIZE (struct booklist *)malloc(sizeof(struct booklist))//建立已借阅图书信息结构体struct borrow{char borbook_num[10];char borbook_name[22];char return_time[15];char stu_num[15];char stu_name[15];struct borrow *next;};//建立预借图书信息结构体struct prebor_stu{char prebook_num[10];char prestu_num[15];struct prebor_stu *next;};//建立图书结构体struct booklist{char num[10];char name[22];char zuozhe[15];char leibie[10];char pub_time[10];char price[10];char condition[10];struct booklist *next;};struct booklist *create(void); /*创建图书信息链表*/struct borrow *borrow_creat(struct booklist *head); //创建已借阅图书信息链表int pre_creat(struct booklist *head); //学生登录系统预借图书并将信息存入文件prebor_stulist.txtstruct prebor_stu *prebor_creat(void); //创建预借阅图书信息链表void printf1_(struct booklist *); //输出单个基本图书的数据void store(struct booklist *head); /*保存链表中的图书信息到文件booklist.txt*/void printfb1_(struct borrow *); //输出单个借出图书的部分数据void printfb_(struct borrow *p); //输出单个借出图书的数据void printfp1_(struct prebor_stu *); //输出单个被预借出图书的部分数据void printfp_(struct prebor_stu *); //输出单个被预借出图书的数据void printf_(struct booklist *,struct borrow *,struct prebor_stu *); /*2---输出链表中的图书信息*/struct booklist *load(void); //5---从文件读入图书信息struct booklist *num_paixu(struct booklist *); //4---按编号排序struct booklist *price_paixu(struct booklist *); //3---按价格顺序排序int kcnum(struct booklist *head); //6---统计库存数void chaxun1_(struct booklist *,struct borrow *,struct prebor_stu *); //7---查询图书的编号图书的信息,并输出void chaxun2_(struct booklist *,struct prebor_stu *,struct borrow *);//7---按作者查询信息并输出void chaxun3_(struct booklist *,struct prebor_stu *,struct borrow *); //7---查询某类别图书信息并自动输出void chaxun4_(struct borrow *,prebor_stu *,struct booklist *); //7---按学号查询借阅信息struct booklist *shanchu(struct booklist *,struct borrow *,struct prebor_stu *); //9---删除数据struct borrow *shanchu2_(struct borrow *,struct borrow *); //删除一个 struct borrow 结构体的数据struct prebor_stu *shanchu3_(struct prebor_stu *,struct prebor_stu *); //删除一个 struct prebor_stu 结构体的数据void xiugai(struct booklist *,struct borrow *,struct prebor_stu *); //10---修改数据void borstore(struct borrow *borrow_head); //保存已借阅图书信息到文件borrowlist.txt//重新保存修改后的预借阅信息到文件 prebor_stulist.txt (全部覆盖)void prestore(struct prebor_stu *pre_head);struct borrow *borload(void); //从文件提取信息创建已借阅图书源信息链表struct booklist *charu(struct booklist *head,struct borrow *borrow_head); //8---将图书的数据到顺序排放的链表中.且插入后也是顺序排放的struct booklist *scanf1_(void); // 输入单个图书源数据void exchange(struct booklist *,struct booklist *) ;//交换两个结构体内的内容struct borrow *tianjia1_(struct borrow *borrow_head,struct booklist *p); //添加一个 struct borrow 结构体的数据int main(void){int n, n1, x , k = 0, flag, flag1, x1;char ch;struct booklist *head = NULL; //图书信息链表头指针struct borrow *borrow_head = NULL ; //已借阅图书信息链表头指针struct prebor_stu *pre_head = NULL ; //预借图书信息链表头指针flag1 = 0; x = x1 = 1;while(x){system("cls");printf("***************************************************************************\n");printf("* >>>>>>>>>>>>>欢迎使用君宁图书管理系统<<<<<<<<<<<<<<< *\n");printf("* 0---退出系统 5---从文件录入数据 *\n");printf("* 1---录入数据 6---统计库存数 *\n");printf("* 2---输出信息 10---修改数据 7---查询功能 *\n");printf("* 3---按价格排序 8---增加数据 *\n");printf("* 4---按编号排序 9---删除数据 *\n");printf("***************************************************************************\n");printf("请选择功能:");scanf("%d", &n);getchar();switch(n){case 0: //0---退出系统{x = 0;printf("*******谢谢使用君宁图书管理系统!******\n");printf("****** 欢迎下次使用! ******\n");break;}case 1: //1---录入数据{while(x1){system("cls");printf("*******欢迎使用君宁图书信息录入系统*******\n");printf("*** 0---放弃录入 ****\n");printf("** 1---录入图书源信息 **\n");printf("* 2---录入借出图书信息 *\n");printf("** 3---录入预借图书信息 **\n");printf("******** 祝您使用愉快 ********\n");printf("请选择功能:");scanf("%d", &n1);getchar();switch(n1){case 0:{x1 = 0;break;}case 1:{head = create( ); /*创建图书信息链表*/printf("是否将源图书信息保存到文件booklist.txt!...(Y/N) :");ch = getchar();if(ch == 'y' || ch == 'Y')store(head);getchar();break;}case 2:{if(head == NULL ){printf("请先录入图书源信息!\n");getchar();break;}else{borrow_head = borrow_creat(head); //创建已借阅图书信息链表printf("是否将源图书信息保存到文件borrowlist.txt!...(Y/N) :" );ch = getchar();if(ch == 'y' || ch == 'Y')borstore(borrow_head);getchar();break;}}case 3:{if(head == NULL ){printf("请先录入图书源信息!\n");getchar();break;}else{flag = pre_creat(head);if(flag == 1)printf("没有录入预借图书信息!\n\n");if(flag == 2)pre_head = prebor_creat(); //创建预借阅图书信息链表getchar();break;}}default :{printf("输入错误指示!\n\n");break;}}}}case 2: //2---输出信息{if(head == NULL ){printf("请先录入图书信息!\n");getchar();break;}else{printf_(head,borrow_head,pre_head);break;}}case 3: //3---按价格排序{if(head == NULL ){printf("请先录入图书信息!\n");getchar();break;}else{head = price_paixu(head);printf("是否将排序后的源图书信息保存到文件booklist.txt!...(Y/N) :");ch = getchar();if(ch == 'y' || ch == 'Y')store(head);getchar();break;}}case 4: //4---按编号排序{if(head == NULL ){printf("请先录入图书信息!\n");getchar();break;}else{head = num_paixu(head);printf("是否将排序后的源图书信息保存到文件booklist.txt!...(Y/N) :");ch = getchar();if(ch == 'y' || ch == 'Y')store(head);getchar();break;}}case 5: //11---从文件读取数据{head = load();if(head == NULL ){printf("请先录入图书信息!\n");getchar();break;}else{borrow_head = borload(); //从文件提取信息创建已借阅图书源信息链表pre_head = prebor_creat(); //创建预借阅图书信息链表getchar();break;}}case 6: //6---统计库存数{if(head == NULL ){printf("请先录入图书信息!\n");getchar();break;}else{k = kcnum(head);printf("总共有%3d本图书!\n\n", k);getchar();break;}}case 7: //7---查询信息{if(head == NULL ){printf("请先录入图书信息!\n");getchar();break;}else{while(x1){system("cls");printf("*******欢迎使用君宁图书信息查询系统*******\n");printf("****** 0---退出查询******\n");printf("***** 1---按编号*****\n");printf("**** 2---按作者****\n");printf("***** 3---按类别*****\n");printf("****** 4---按学号******\n");printf("******** 祝您使用愉快********\n");printf("******************\n");printf("********************\n");printf("请选择功能:");scanf("%d", &n1);getchar();switch(n1){case 0:{x1 = 0;break;}case 1:{chaxun1_(head,borrow_head,pre_head);getchar();break;}case 2:{chaxun2_(head,pre_head,borrow_head);getchar();break;}case 3:{chaxun3_(head,pre_head,borrow_head);getchar();break;}case 4:{chaxun4_(borrow_head,pre_head,head);getchar();break;}default :{printf("输入指示有误!\n\n");break;}}}}x1 = 1;break;}case 8:{if(head == NULL ){printf("请先录入图书信息!\n");getchar();break;}else{head = charu(head,borrow_head);printf("是否将源图书信息保存到文件booklist.txt!...(Y/N) :");ch = getchar();if(ch == 'y' || ch == 'Y')store(head);getchar();break;}}case 9: //9---删除数据{if(head == NULL ){printf("请先录入图书信息!\n");getchar();break;}else{head = shanchu(head,borrow_head,pre_head);borrow_head = borload();pre_head = prebor_creat();break;}}case 10: //10---修改数据{if(head == NULL ){printf("请先录入图书信息!\n");getchar();break;}else{xiugai(head,borrow_head,pre_head);borrow_head = borload();getchar();break;}}default :{printf("输入错误指示.请重新输入!");getchar();break;}}}return 0;}/*创建图书源信息信息链表*/struct booklist *create(void){struct booklist *head, *tail, *p;char num[10],name[22], zuozhe[15], leibie[10], pub_time[10], price[10],condition[10];head = tail = p = NULL;printf("当输入图书编号为0时结束信息输入\n");printf("请输入图书编号:");gets(num);while(strcmp(num,"0") != 0){p = SIZE;printf("请输入书名:");gets(name);printf("请输入作者:");gets(zuozhe);printf("请输入类别:");gets(leibie);printf("请输入出版时间:");gets(pub_time);printf("请输入价格:");gets(price);printf("请输入借阅情况:");gets(condition);printf("\n");strcpy(p -> num, num);strcpy(p -> name, name);strcpy(p -> zuozhe, zuozhe);strcpy(p -> leibie, leibie);strcpy(p -> pub_time, pub_time);strcpy(p -> price, price);strcpy(p -> condition, condition);p -> next = NULL;if(head == NULL)head = p;elsetail -> next = p;tail = p;printf("请输入图书编号:");gets(num);}printf("图书源信息已建立链条!\n");return head;}//创建已借阅图书源信息链表struct borrow *borrow_creat(struct booklist *head) {struct booklist *p;struct borrow *borrow_head , *p1, *tail;borrow_head = p1 = tail = NULL;for(p = head; p != NULL; p = p -> next){p1 = (struct borrow *)malloc(sizeof(struct borrow));if(strcmp(p -> condition,"借出") == 0){printf("创建借出信息:\n");strcpy(p1 -> borbook_num ,p -> num);strcpy(p1 -> borbook_name ,p -> name);getchar();printf("借阅编号为%s的图书的借阅信息:\n",p -> num);printf("请输入应归还时间:");gets(p1 -> return_time);printf("请输入学生学号:");gets(p1 -> stu_num);printf("请输入学生姓名:");gets(p1 -> stu_name);printf("\n");p1 -> next = NULL;if(borrow_head == NULL)borrow_head = p1;elsetail -> next = p1;tail = p1;}}printf("成功创建已借出信息链表!\n\n");getchar();return borrow_head;}//保存已借阅图书信息到文件 borrowlist.txtvoid borstore(struct borrow *borrow_head){FILE *fp;struct borrow *p;if((fp = fopen("borrowlist.txt","w")) == NULL){printf("File open error! \n");exit(0);}p = borrow_head;while(p != NULL){fprintf(fp,"%16s%26s%16s%16s%16s\n",p -> borbook_num, p -> borbook_name, p -> return_time,p -> stu_num, p -> stu_name);p = p -> next;}fclose(fp);printf("文件成功保存到 borrowlist.txt 中!\n");getchar();}//从文件提取信息创建已借阅图书源信息链表struct borrow *borload(void){struct borrow *p, *tail, *head;FILE *fp;head = p = tail = NULL;if((fp = fopen("borrowlist.txt","r")) == NULL){printf("文件 borrowlist.txt 打开失败!\n");getchar();exit(0);}while(!feof(fp)){p = (struct borrow *)malloc(sizeof(struct borrow));fscanf(fp,"%16s%26s%16s%16s%16s\n",p -> borbook_num, p -> borbook_name, p -> return_time,p -> stu_num, p -> stu_name);if(head == NULL)head = p;elsetail -> next = p;tail = p;}tail -> next = NULL;fclose(fp);printf("已成功从文件 borrowlist.txt 提取信息创建已借阅图书源信息!\n");return head;}//录入预借图书信息并将信息存入文件 prebor_stulist.txtint pre_creat(struct booklist *head){struct booklist *b;struct prebor_stu *p;char a[10], c[15];int n, x = 1, flag = 1;FILE *fp;b = head;p = (struct prebor_stu *)malloc(sizeof(struct prebor_stu));printf("进入预借图书!(按回车键继续、、、)\n");getchar();while(x){printf("请输入要预借阅的图书编号:");gets(a);while((strcmp(b -> num ,a) != 0) && b -> next != NULL){b = b -> next;}if(strcmp(b -> num ,a) != 0){printf("没有找到编号为%s的图书!\n", a);printf("输入--0 结束录入!(输入其他数字继续录入...)\n\n");printf("请选择功能:");scanf("%d", &n);getchar();if(n == 0){x = 0;}getchar();}else{printf("请输入学号:");gets(c);strcpy(p -> prebook_num, a);strcpy(p -> prestu_num, c);if((fp = fopen("prebor_stulist.txt","a+")) == NULL){printf("File open error! \n");exit(0);}fprintf(fp,"%16s%16s\n",p -> prebook_num, p -> prestu_num);fclose(fp);flag = 2;printf("输入--0 结束录入!(输入其他数字继续录入...)\n\n");printf("请选择功能:");scanf("%d", &n);getchar();if(n == 0){x = 0;getchar();}}}return flag;}//重新保存修改后的预借阅信息到文件 prebor_stulist.txt (全部覆盖)void prestore(struct prebor_stu *pre_head){struct prebor_stu *p;FILE *fp;p = pre_head;if((fp = fopen("prebor_stulist.txt","w")) == NULL){printf("File open error! \n");exit(0);}while(p != NULL){fprintf(fp,"%16s%16s\n",p -> prebook_num, p -> prestu_num); p = p -> next;}fclose(fp);printf("文件成功保存到 prebor_stulist.txt 中!\n");getchar();}//从文件 prebor_stulist.txt创建预借阅图书信息链表struct prebor_stu *prebor_creat(void){struct prebor_stu *p, *tail, *head;FILE *fp;head = p = tail = NULL;if((fp = fopen("prebor_stulist.txt","r")) == NULL){printf("文件 prebor_stulist.txt 打开失败!\n");getchar();}while(!feof(fp)){p = (struct prebor_stu *)malloc(sizeof(struct prebor_stu));fscanf(fp,"%16s%16s\n",p -> prebook_num, p -> prestu_num);if(head == NULL)head = p;elsetail -> next = p;tail = p;}tail -> next = NULL;fclose(fp);printf("已从文件 prebor_stulist.txt 成功读取并建立预借阅图书信息!\n");getchar();return head;}/*2---保存链表中的图书信息到文件booklist.txt*/void store(struct booklist *head){FILE *fp;struct booklist *p;if((fp = fopen("booklist.txt","w")) == NULL){printf("File open error! \n");exit(0);}p = head;while(p != NULL){fprintf(fp,"%16s%26s%16s%16s%16s%16s%16s\n",p -> num, p -> name, p -> zuozhe, p -> leibie,p -> pub_time, p -> price, p -> condition);p = p -> next;}fclose(fp);printf("文件成功保存到 booklist.txt 中!\n");getchar();}// 输入单个图书源数据struct booklist *scanf1_(void) {struct booklist *p;p = SIZE;printf("请输入图书编号:");gets(p -> num);printf("请输入书名:");gets(p -> name);printf("请输入作者:");gets(p -> zuozhe);printf("请输入类别:");gets(p -> leibie);printf("请输入出版时间:");gets(p -> pub_time);printf("请输入价格:");gets(p -> price);printf("请输入借阅情况:");gets(p -> condition);return p;}//输出单个图书的数据void printf1_(struct booklist *p) {printf("编号:");puts(p -> num);printf("书名:");puts(p -> name);printf("作者:");puts(p -> zuozhe);printf("类别:");puts(p -> leibie);printf("出版时间:");puts(p -> pub_time);printf("价格:");puts(p -> price);printf("借阅情况:");}//输出单个借出图书的部分数据void printfb1_(struct borrow *p) {printf("应归还时间:");puts(p -> return_time);printf("借阅学生学号:");puts(p -> stu_num);printf("借阅学生姓名:");puts(p -> stu_name);}//输出单个借出图书的数据void printfb_(struct borrow *p) {printf("图书编号:");puts(p -> borbook_num);printf("书名:");puts(p -> borbook_name);printf("应归还时间:");puts(p -> return_time);printf("借阅学生学号:");puts(p -> stu_num);printf("借阅学生姓名:");puts(p -> stu_name);}//输出单个被预借出图书的部分数据void printfp1_(struct prebor_stu *p) {printf("预借图书的学生学号:"); puts(p -> prestu_num);}//输出单个被预借出图书的数据void printfp_(struct prebor_stu *p) {printf("图书编号:");printf("预借阅图书的学生学号:");puts(p -> prestu_num);}/*3---输出链表中的图书信息*/void printf_(struct booklist *head, struct borrow *borrow_head,struct prebor_stu *pre_head){struct booklist *p;struct borrow *b;struct prebor_stu *pre;int x = 1, n;p = head; b = borrow_head; pre = pre_head;while(x == 1){system("cls");printf("*******欢迎使用君宁图书信息输出系统*******\n");printf("* 0---退出 *\n");printf("* 1---输出图书源信息 *\n");printf("* 2---输出借出图书信息 *\n");printf("* 3---输出预借借图书信息 *\n");printf("******** 祝您使用愉快 ********\n");printf("请选择功能:");scanf("%d", &n);getchar();switch(n){case 0:{x = 0;break;}case 1:{if(head != NULL){printf("图书源信息如下:\n");do{printf1_(p);printf("\n\n");p = p -> next;}while(p != NULL);}getchar();break;}case 2:{if(borrow_head == NULL){printf("没有借出图书信息(按回车键继续、、、)!\n");getchar();break;}else{printf("借出图书信息如下:\n");do{printfb_(b);printf("\n\n");b = b -> next;}while(b != NULL);}printf("按回车键继续、、\n");getchar();break;}case 3:{if(pre_head == NULL){printf("没有预借图书信息(按回车键继续、、、)!\n");getchar();getchar();break;}else{printf("预借借图书信息如下:\n");do{printfp_(pre);printf("\n\n");pre = pre -> next;}while(pre != NULL);}printf("按回车键继续、、\n");getchar();break;}default :{printf("输入错误(按回车键继续、、、)!\n");getchar();break;}}}}//11---从文件读入图书信息struct booklist *load(void){struct booklist *p, *tail, *head;FILE *fp;head = p = tail = NULL;if((fp = fopen("booklist.txt","r")) == NULL){printf("文件 booklist.txt 打开失败!\n");getchar();exit(0);}while(!feof(fp)){p = SIZE;fscanf(fp,"%16s%26s%16s%16s%16s%16s%16s\n",p -> num, p -> name, p -> zuozhe, p -> leibie,p -> pub_time, p -> price,p -> condition);if(head == NULL)head = p;elsetail -> next = p;tail = p;}tail -> next = NULL;fclose(fp);printf("已成功读取文件 booklist.txt ,建立源图书信息链表!\n");return head;}//4---按编号排序并输出struct booklist *num_paixu(struct booklist *head){struct booklist *p, *p1, *tail;p1 = NULL;tail = SIZE;for(p = head;p -> next != NULL; p = p -> next){for(p1 = p ->next; p1 != NULL; p1 = p1 ->next){if(strcmp(p -> num,p1 -> num) > 0){exchange(tail,p1);exchange(p1,p);exchange(p,tail);}}}printf("图书已按编号排序成功,具体信息如下:\n");for(p = head; p != NULL; p = p -> next){printf1_(p);printf("\n");}return head;}//3---按价格排序struct booklist *price_paixu(struct booklist *head) {struct booklist *p, *p1, *tail;p1 = NULL;tail = SIZE;for(p = head;p -> next != NULL; p = p -> next){for(p1 = p ->next; p1 != NULL; p1 = p1 ->next){if(strcmp(p -> price,p1 -> price) > 0){exchange(tail,p1);exchange(p1,p);exchange(p,tail);}}}printf("图书已按价格排序成功,具体信息如下:\n");for(p = head; p != NULL; p = p -> next){printf1_(p);printf("\n");}return head;}//6---统计库存数int kcnum(struct booklist *head){int i = 0;struct booklist *p;for(p = head;p != NULL; p = p -> next)i++;return i;}//7---按编号查询信息并输出void chaxun1_(struct booklist *head,struct borrow *borrow_head,struct prebor_stu *pre_head){char a[10];struct booklist *p;struct borrow *b;struct prebor_stu *p1;int x1, x2;p = head; x1 = x2 = 0;printf("请输入要查询的图书编号:");gets(a);while((strcmp(p -> num ,a) != 0) && p -> next != NULL){p = p -> next;}if(strcmp(p -> num ,a) != 0)printf("没有找到编号为%s的图书!\n", a);else{for(b = borrow_head;b != NULL; b = b -> next){if(strcmp(b -> borbook_num ,a) == 0){x1 = 1;printf("您要查询的书已借出,其具体信息如下:\n");printfb1_(b); //输出单个借出图书的数据printf1_(p);}}for(p1 = pre_head;p1 != NULL; p1 = p1 -> next){if(strcmp(p1 -> prebook_num ,a) == 0){ x2 = 1;printf("您要查询的书已预借,其具体信息如下:\n");printfp1_(p1); //输出单个被预借出图书的数据printf1_(p);}}if(x1 == 0 && x2 == 0){printf("此书未被预借!\n\n");printf("您要查询的图书信息如下:\n");printf1_(p);}}}//7---按作者查询信息void chaxun2_(struct booklist *head,struct prebor_stu *pre_head,struct borrow *borrow_head){char a[10];struct booklist *p;struct borrow *b;struct prebor_stu *pre;int flag = 1, x1 ;printf("请输入要查询的图书的作者:");gets(a);for(p = head;p != NULL; p = p -> next){if(strcmp(p -> zuozhe,a) == 0){if(flag == 1){printf("您查询的%s的所有图书信息如下:\n\n",a);flag = -1;}printf1_(p);for(b = borrow_head;b != NULL; b = b -> next){if(strcmp(b -> borbook_num ,p -> num) == 0){printfb1_(b);}}x1 = 0;for(pre = pre_head; pre != NULL; pre = pre -> next){if(strcmp(pre -> prebook_num, p -> num) == 0){printf("此书已被%s学号的学生预借!\n",pre -> prestu_num );x1 = 1;}}if(x1 == 0){printf("此书未被预借!\n");x1 = 1;}printf("\n\n");}}if(flag == 1)printf("没有找到您要查询的的图书信息!\n\n");}//7---查询某类别图书信息并自动输出void chaxun3_(struct booklist *head,struct prebor_stu *pre_head,struct borrow *borrow_head){char a[10];struct booklist *p;struct prebor_stu *pre;struct borrow *b;int flag = 1 , x1;printf("请输入要查询的图书的类别:");gets(a);for(p = head;p != NULL; p = p -> next){if(strcmp(p -> leibie,a) == 0){if(flag == 1){printf("您查询的%s的所有图书信息如下:\n\n",a);flag = -1;}printf1_(p);for(b = borrow_head;b != NULL; b = b -> next){if(strcmp(b -> borbook_num ,p -> num) == 0){printfb1_(b);}}x1 = 0;for(pre = pre_head; pre != NULL; pre = pre -> next){if(strcmp(pre -> prebook_num, p -> num) == 0){printf("此书已被%s学号的学生预借!\n",pre -> prestu_num );x1 = 1;}}if(x1 == 0){printf("此书未被预借!\n");x1 = 1;}printf("\n\n");}}if(flag == 1)printf("没有找到您要查询的的图书信息!\n\n");}//7---按学号查询图书借阅信息并自动输出void chaxun4_(struct borrow *borrow_head,struct prebor_stu *pre_head,struct booklist *head){//建立图书编号结构体struct book_num{char booknum[10];struct book_num *next;};struct prebor_stu *p ;struct borrow *b;struct booklist *p2;char a[15];int i, j;i = j = 0;struct book_num *bnumhead1, *bnumhead2, *tail, *p1;bnumhead1 = bnumhead2 = tail = p1 = NULL;printf("请输入学生学号:");gets(a);for(p = pre_head; p != NULL; p = p -> next){if(strcmp(p -> prestu_num,a) ==0){i++;p1 = (struct book_num *)malloc(sizeof(struct book_num)); strcpy( p1 -> booknum, p ->prebook_num);if(bnumhead1 == NULL)bnumhead1 = p1;elsetail -> next = p1;tail = p1;p1 -> next = NULL;}}for(b = borrow_head;b != NULL; b = b -> next){if(strcmp(b -> stu_num,a) ==0){j++;p1 = (struct book_num *)malloc(sizeof(struct book_num)); strcpy( p1 -> booknum, b ->borbook_num);if(bnumhead2 == NULL)bnumhead2 = p1;elsetail -> next = p1;tail = p1;p1 -> next = NULL;}}if(i == 0 && j == 0)printf("没有您要查询学生的借阅信息!");else{if( j != 0){printf("该生一共借了%d本书,其借阅书的信息如下:\n", j);for( p1 = bnumhead2; p1 != NULL; p1 = p1 -> next){for(p2 = head; p2 != NULL; p2 = p2 -> next){if(strcmp(p1 -> booknum, p2 -> num) == 0){printf1_(p2);if(strcmp(p2 -> condition,"借出") ==0){for(b = borrow_head;b != NULL; b = b -> next)if(strcmp(b -> borbook_num,p2 -> num) ==0)printfb1_(b);}printf("\n");}}}}if( i != 0){printf("该生一共预借借了%d本书,其借阅书的信息如下:\n", i);for( p1 = bnumhead1; p1 != NULL; p1 = p1 -> next){for(p2 = head; p2 != NULL; p2 = p2 -> next){if(strcmp(p1 -> booknum, p2 -> num) == 0){printf1_(p2);if(strcmp(p2 -> condition,"借出") ==0){for(b = borrow_head;b != NULL; b = b -> next)if(strcmp(b -> borbook_num,p2 -> num) ==0)printfb1_(b);}printf("\n");}}}}}}//9---删除数据struct booklist *shanchu(struct booklist *head,struct borrow *borrow_head,struct prebor_stu *pre_head){struct booklist *p1 , *p2;struct borrow *b;struct prebor_stu *p;char a[10];p1 = p2 = head;printf("请输入要删除的图书编号:");gets(a);while((strcmp(p1 -> num ,a) != 0) && p1 -> next != NULL) {p2 = p1;p1 = p1 -> next;}if(strcmp(p1 -> num ,a) != 0)printf("没有找到要删除的图书信息!\n");else if(p1 == head){head = p1 -> next;printf("删除成功!\n");store(head);for(b = borrow_head; b != NULL; b = b -> next){if(strcmp(b -> borbook_num,a) == 0)borrow_head = shanchu2_(borrow_head,b);}for(p = pre_head; p != NULL; p = p -> next){if(strcmp(p -> prebook_num,a) == 0)pre_head = shanchu3_(pre_head,p);}}else{p2 -> next = p1 -> next;printf("删除成功!\n");store(head);for(b = borrow_head; b != NULL; b = b -> next){if(strcmp(b -> borbook_num,a) == 0)borrow_head = shanchu2_(borrow_head,b);}for(p = pre_head; p != NULL; p = p -> next){if(strcmp(p -> prebook_num,a) == 0)pre_head = shanchu3_(pre_head,p);}}return head;}//删除一个 struct borrow 结构体的数据struct borrow *shanchu2_(struct borrow *borrow_head,struct borrow *p) {struct borrow *p1 , *p2;p1 = p2 = borrow_head;while(strcmp(p1 -> borbook_num ,p -> borbook_num) != 0) {p2 = p1;p1 = p1 -> next;}if(p1 == borrow_head){borrow_head = p1 -> next;borstore(borrow_head);}else{p2 -> next = p1 -> next;borstore(borrow_head);}getchar();return borrow_head;}//添加一个 struct borrow 结构体的数据。

c++图书管理系统源代码

c++图书管理系统源代码

//本文章来源于网络。

// 图书管理系统.cpp : 定义控制台应用程序的入口点。

////#include "stdafx.h"#include "iostream"#include "fstream"#include "string.h"#include "iomanip"using namespace std;/*int _tmain(int argc, _TCHAR* argv[]){return 0;}*//*int mark0=0;//用于标记是否找到要找的信息int mark1=0;//用于标记是否找到要找的信息*/struct Reathur{//记录书籍的书名信息char bookname[20];//书名struct Reathur* Lnode;//指向下一图书节点};struct Reader{//记录读者信息char Readername[20];//读者名称struct Reathur* next;//指向该读者借的书struct Reader* Lreader,*Right,*Lift;//下一个读者节点};struct Libray{//记录图书的详细信息char bookname[20];//书名char bookno[20];//编号char bookreathur[20];//作者名int booknum;//现有册数struct Libray* Llink,* Rlink,*Lnext;//下一图书的左右节点struct Reader* read;//指向借阅该书的读者};void bsinsert(struct Libray* s,struct Libray* &t)//{将s所指结点插入到根结点指针为t的树中} {if (t==NULL)t=s;elseif(strcmp(s->bookname,t->bookname)==1){bsinsert(s,t->Rlink);}else {bsinsert(s,t->Llink);}}void Rnorder( struct Reader* T){//中序遍历所有的读者链的所有节点if(T!=NULL){Rnorder( T->Lift);struct Reathur* u;u=T->next;cout<<setw(12)<<"读者名称:"<<T->Readername<<"\n";while(u!=NULL){cout<<setw(12)<<"书名:"<<"《"<<u->bookname<<"》"<<"\n";u=u->Lnode;}Rnorder( T->Right);}}/////////////////////////////////////////////////////////////////////////按中序遍历遍历二叉排序树进行检索///////////void Rnorder_name( struct Reader* T,char name[],int &vetex){//中序遍历读者链的所有节点int i=vetex;if(T!=NULL){Rnorder_name( T->Lift,name,i);if(strcmp(T->Readername,name)==0){struct Reathur* u;u=T->next;cout<<setw(12)<<"读者名称:"<<T->Readername<<"\n";while(u!=NULL){cout<<setw(12)<<"书名:"<<"《"<<u->bookname<<"》"<<"\n";u=u->Lnode;}vetex=1;}Rnorder_name( T->Right,name,i);}}/////////////////////////////////////////////////////////////////////////按中序遍历遍历二叉排序树进行检索///////////void Inorder( struct Libray* T){//中序遍历所有的图书节点if(T!=NULL){Inorder( T->Llink);struct Reader* u;u=T->read;cout<<setw(12)<<"书名:"<<"《"<<T->bookname<<"》\n";cout<<setw(12)<<"现有册数:"<<T->booknum<<"\n";cout<<setw(12)<<"作者名称:"<<T->bookreathur<<"\n";while(u!=NULL){cout<<setw(12)<<"读者名称:"<<u->Readername<<"\n";u=u->Lreader;}Inorder( T->Rlink);}}void Inorder_search( struct Libray* T,char bookname[20],int &vetex){//按书名检索int i=vetex;char cname[20];strcpy(cname,bookname);if(T!=NULL){Inorder_search( T->Llink ,cname,i);if(strcmp(cname,T->bookname)==0){struct Reader* u;u=T->read;cout<<setw(12)<<"书名:"<<"《"<<T->bookname<<"》\n";cout<<setw(12)<<"书目编号:"<<T->bookno<<"\n";cout<<setw(12)<<"现有册数:"<<T->booknum<<"\n";cout<<setw(12)<<"作者名称:"<<T->bookreathur<<"\n";while(u!=NULL){cout<<setw(12)<<"读者名称:"<<u->Readername<<"\n";u=u->Lreader;}vetex=1;}Inorder_search( T->Rlink,cname,i);}}void Inorder_searchNo( struct Libray* T,char bookno[20],int &vetex){//按书目编号检索int i=vetex;char cno[20];strcpy(cno,bookno);if(T!=NULL){Inorder_searchNo( T->Llink ,cno,i);if(strcmp(cno,T->bookno)==0){struct Reader* u;u=T->read;cout<<setw(12)<<"书名:"<<"《"<<T->bookname<<"》\n";cout<<setw(12)<<"现有册数:"<<T->booknum<<"\n";cout<<setw(12)<<"作者名称:"<<T->bookreathur<<"\n";while(u!=NULL){cout<<setw(12)<<"读者名称:"<<u->Readername<<"\n";u=u->Lreader;}vetex=1;}Inorder_searchNo( T->Rlink,cno,i);}}struct Libray* sortree(struct Libray* r)//建立一个含有m 个结点的二叉排序树,p为指向二叉树根结点的指针{struct Libray* temp=new struct Libray;struct Libray* p=new struct Libray;struct Libray* q=new struct Libray;if(r->Lnext!=NULL){temp=r->Lnext;strcpy(q->bookname,temp->bookname);strcpy(q->bookno,temp->bookno);strcpy(q->bookreathur,temp->bookreathur);q->booknum=temp->booknum;q->read=temp->read;q->Llink=NULL;q->Rlink=NULL; ;p=q;}temp=temp->Lnext;while(temp!=NULL){struct Libray* q=new struct Libray;strcpy(q->bookname,temp->bookname);strcpy(q->bookno,temp->bookno);strcpy(q->bookreathur,temp->bookreathur);q->booknum=temp->booknum;q->read=temp->read;q->Llink=NULL;q->Rlink=NULL;bsinsert(q,p);temp=temp->Lnext;}return p;}/////////////////////////////////////////////////////////////////////////往二叉排序树中插入记录///////////void Book_insert(struct Libray* &t,char bookname[],char bookno[],char bookreathur[],int booknum){struct Libray* j;int B=1;struct Libray* p=NULL;j=t;while((j!=NULL)&&(B==1)){switch(strcmp(bookname,j->bookname)){case 1:p=j;j=j->Rlink;break;case -1:p=j;j=j->Llink;break;case 0:cout<<"该记录已经存在,无需新建该记录....\n";B=0;break;}}if(B==1) {struct Libray* j=new struct Libray;strcpy(j->bookname,bookname);strcpy(j->bookno,bookno);strcpy(j->bookreathur,bookreathur);j->booknum=booknum;j->Llink=NULL;j->Rlink=NULL;j->read=NULL;if(t==NULL)t=j;if(strcmp(bookname,p->bookname)==1)p->Rlink=j;if(strcmp(bookname,p->bookname)==-1)p->Llink=j;}}/////////////////////////////////////////////////////////////////////////往二叉排序树中删除记录///////////void Book_delete(struct Libray* t,char bookname[])//{j指向被删结点,p指向其双亲,假设树不空}{struct Libray* q,*s;struct Libray* j;struct Libray* p=NULL;int B=1;j=t;while((j!=NULL)&&(B==1)){switch(strcmp(bookname,j->bookname)){case 1:p=j;j=j->Rlink;break;case -1:p=j;j=j->Llink;break;case 0:B=0;break;}}if(B==0) {if(j->Llink==NULL)//{被删结点无左子树}s=j->Rlink;elseif(j->Rlink==NULL)s=j->Llink;else{q=j;s=q->Llink;while(s->Rlink!=NULL){q=s;s=s->Rlink;};s->Rlink=j->Rlink;if (q!=j){q->Rlink=s->Llink;s->Llink=j->Llink;}}if(p==NULL)t=s;elseif (j==p->Llink)p->Llink=s;elsep->Rlink=s;}}//////////////////////////////////////////////////////////////////寻找重复的读者名称////////////////////void search_name(struct Reader* T,char name[],struct Reader* &p){if(T!=NULL){search_name( T->Lift,name,p);if(strcmp(T->Readername,name)==0){p=T;goto mark;}elsep=NULL;search_name( T->Right,name,p);}mark:;}void Rsinsert(struct Reader* s,struct Reader* &t)//{将s所指结点插入到根结点指针为t的树中} {if (t==NULL)t=s;elseif(strcmp(s->Readername,t->Readername)==1){Rsinsert(s,t->Right);}else {Rsinsert(s,t->Lift);}}/////////////////////////////////////////////////////////////////////////建立读者链的二叉排序树///////////struct Reader* Build_reader(struct Libray* book){struct Reader* vetex=new struct Reader;;struct Reader* q;struct Reader* Rroot=new struct Reader;struct Reader* temp=new struct Reader;struct Reathur* u=new struct Reathur;struct Reathur* v;struct Libray* p=new struct Libray;char bname[20];p=book->Lnext;strcpy(u->bookname,p->bookname);u->Lnode=NULL;q=p->read;if(q!=NULL){strcpy(temp->Readername,q->Readername);temp->next=u;temp->Lift=NULL;temp->Right=NULL;}Rroot=temp;q=q->Lreader;while(q!=NULL){struct Reathur* u=new struct Reathur;struct Reader* temp=new struct Reader;u->Lnode=NULL;strcpy(u->bookname,p->bookname);strcpy(temp->Readername,q->Readername);temp->next=u;temp->Lift=NULL;temp->Right=NULL;Rsinsert(temp,Rroot);q=q->Lreader;}p=p->Lnext;while(p!=NULL){q=p->read;while(q!=NULL){search_name(Rroot,q->Readername,vetex);struct Reathur* u=new struct Reathur;strcpy(u->bookname,p->bookname);u->Lnode=NULL;if(vetex!=NULL){u->Lnode=vetex->next;vetex->next=u;q=q->Lreader;continue;}struct Reader* temp=new struct Reader;strcpy(temp->Readername,q->Readername);temp->next=u;temp->Lift=NULL;temp->Right=NULL;Rsinsert(temp,Rroot);q=q->Lreader;}p=p->Lnext;}return Rroot;}////////////////////////////////////////////////////////////////////////////////////寻找读者想借阅的书籍////////////struct Libray* Book_search(struct Libray* &t,char bookname[]){struct Libray* j;struct Libray* p=NULL;int B=1;j=t;while((j!=NULL)&&(B==1)){switch(strcmp(bookname,j->bookname)){case 1:p=j;j=j->Rlink;break;case -1:p=j;j=j->Llink;break;case 0:B=0;break;}}if(B==0&&j->booknum>0){cout<<"已经在到你要寻找的书籍,可以借阅....\n";return j;}if(B==1){cout<<"Sorroy!没有你要寻找的书籍....\n";return NULL;}}////////////////////////////////////////////////////////////////////////////////////寻找读者信息,若无则建立新节点///struct Reader* Reader_sea(struct Reader* &t,char bookname[],char readername[]){ struct Reader* j,*q;struct Reathur* p;int B=1;j=t;while((j!=NULL)&&(B==1)){switch(strcmp(readername,j->Readername)){case 1:q=j;j=j->Right;break;case -1:q=j;j=j->Lift;break;case 0:B=0;break;}}if(B==0){p=j->next;while(p!=NULL){if(strcmp(bookname,p->bookname)==0){cout<<"Sorroy!你已经借阅了该书籍,不能重复借阅....\n";return NULL;}p=p->Lnode;}return j;}else{struct Reader* j=new struct Reader;strcpy(j->Readername,readername);j->Lift=NULL;j->Right=NULL;j->next=NULL;if(t==NULL)t=j;if(strcmp(readername,q->Readername)==1)q->Right=j;if(strcmp(readername,q->Readername)==-1)q->Lift=j;return j;}}/////////////////////////////////////////////////////////////////////////读者借书///////////void Borrow_book(struct Libray* &book,struct Reader* &Readeroot){ char Rname[20],Bname[20];struct Libray* p=book;struct Reader* q=Readeroot;struct Libray* u;struct Reader* v;cout<<"请输入用户名!\n";cin>>Rname;cout<<"请输入书籍名!\n";cin>>Bname;u=Book_search(p,Bname);v=Reader_sea(q,Bname,Rname);if(u==NULL){return;}else{if(v==NULL){return;}else{struct Reader* temp=new struct Reader;struct Reathur* tp=new struct Reathur;strcpy(temp->Readername,Rname);u->booknum--;temp->Lreader=u->read;u->read=temp;strcpy(tp->bookname,Bname);tp->Lnode=v->next;v->next=tp;}}}////////////////////////////////////////////////////////////////////////////////////寻找读者想借阅的书籍////////////void B_search(struct Libray* &t,char bookname[],char Rname[]){ struct Libray* j;struct Libray* p=NULL;struct Reader* u,*v;int B=1;j=t;while((j!=NULL)&&(B==1)){switch(strcmp(bookname,j->bookname)){case 1:p=j;j=j->Rlink;break;case -1:p=j;j=j->Llink;break;case 0:B=0;break;}}if(B==0){cout<<"已经找到该书籍的有关记录,更新记录....\n";j->booknum++;u=j->read;if(strcmp(Rname,u->Readername)==0){j->read=u->Lreader;delete(u);return;}v=u;u=u->Lreader;while(u!=NULL){if(strcmp(Rname,u->Readername)==0){v->Lreader=u->Lreader;delete(u);return;}v=u;u=u->Lreader;}if(B==1){cout<<"Sorroy!没有找到该书籍的有关记录....\n";return;}}}//////////////////////////////////////////////////////////寻找读者信息/////////////void R_sea(struct Reader* &t,char readername[],char bname[]){ struct Reader* j,*s,*q;struct Reathur* v,*u;struct Reader* p=NULL;int B=1;j=t;while((j!=NULL)&&(B==1)){switch(strcmp(readername,j->Readername)){case 1:p=j;j=j->Right;break;case -1:p=j;j=j->Lift;break;case 0:B=0;break;}}if(B==0){cout<<"已经找到该读者的有关记录,更新记录....\n";u=j->next;if(strcmp(bname,u->bookname)==0){if(u->Lnode==NULL){if(j->Lift==NULL)//{被删结点无左子树}s=j->Right;elseif(j->Right==NULL)s=j->Lift;else{q=j;s=q->Lift;while(s->Right!=NULL){q=s;s=s->Right;};s->Right=j->Right;if (q!=j){q->Right=s->Lift;s->Lift=j->Lift;}}if(p==NULL)t=s;elseif (j==p->Lift)p->Lift=s;elsep->Right=s;}elsej->next=u->Lnode;delete(u);return;}else{v=u;u=u->Lnode;while(u!=NULL){if(strcmp(bname,u->bookname)==0){v->Lnode=u->Lnode;delete(u);return;}u=u->Lnode;}}}else{cout<<"Sorroy!没有找到该读者的有关记录....\n";return;}}///////////////////////////////////////////////////////////读者还书/////////////////////////void Return_book(struct Libray* &book,struct Reader* &Readeroot){ char Rname[20],Bname[20];struct Libray* p=book;struct Reader* q=Readeroot;cout<<"请输入用户名!\n";cin>>Rname;cout<<"请输入书籍名!\n";cin>>Bname;B_search(p,Bname,Rname);R_sea(q,Rname,Bname);}/////////////////////////////////////////////////////////////////////////将新纪录写入到文件当中///////////void write_file(struct Libray* &T){int i;struct Libray* p=new struct Libray;struct Libray* s[50];fstream ofile;ofile.open("C:\\Documents and Settings\\dufan\\My Documents\\V isual Studio 2008\\Projects\\mdata.txt",ios::out);if(!ofile){cout<<"The file can not open!\n";return;}if(T==NULL)return;else {i=0;p=T;}do{while(p!=NULL){i=i+1;s[i]=p;p=p->Llink;}if(i!=0){p=s[i];i=i-1;struct Reader* u;u=p->read;ofile<<"书名:"<<p->bookname<<"\n";ofile<<"书目编号:"<<p->bookno<<"\n";ofile<<"作者名称:"<<p->bookreathur<<"\n";ofile<<"现有册数:"<<p->booknum<<"\n";while(u!=NULL){ofile<<"借阅读者:"<<u->Readername<<"\n";u=u->Lreader;}p=p->Rlink;}}while (i!=0 || p!=NULL);}int main(){char ch;int cnum,i=0;char temp[5],cname[20],cno[20],creathur[20],cborrow[20];struct Libray* book=new struct Libray;struct Libray* p;struct Reader* r=new struct Reader;//用于指向读者链struct Reader* Readeroot=new struct Reader;//用于指向读者链二叉排序树fstream ifile;ifile.open("C:\\Documents and Settings\\dufan\\My Documents\\V isual Studio 2008\\Projects\\mdata.txt",ios::in);if(!ifile){cout<<"The file can not open!\n";return 0;}p=book;while(!ifile.eof()){struct Libray* booktemp=new struct Libray;struct Reader* rtemp;rtemp=r;ifile.ignore(20,':');ifile.getline(cname,20);strcpy(booktemp->bookname,cname);//读取书籍名称ifile.ignore(20,':');ifile.getline(cno,20);strcpy(booktemp->bookno,cno);//读取书籍编号ifile.ignore(20,':');ifile.getline(creathur,20);strcpy(booktemp->bookreathur,creathur);//读取作者名称ifile.ignore(20,':');ifile.getline(temp,20);cnum=atol(temp);booktemp->booknum=cnum;//读取现有册数while(ifile.get(ch)){//读取借阅者名称if((int)ch==-54)break;ifile.ignore(20,':');struct Reader* q=new struct Reader;//读者节点ifile.getline(cborrow,20);strcpy(q->Readername,cborrow);//读取读者姓名q->Lreader=NULL;rtemp->Lreader=q;rtemp=rtemp->Lreader;}booktemp->read=r->Lreader;booktemp->Lnext=NULL;p->Lnext=booktemp;p=p->Lnext;}ifile.close();delete(r);Readeroot=Build_reader(book);book=sortree(book);//Inorder(book);//Rnorder(Readeroot);int fun;while(1){cout<<"/********** 图书管理系统功能说明表**********\n";cout<<"/** 1添加新书\n";cout<<"/** 2删除旧书\n";cout<<"/** 3按书名检索\n";cout<<"/** 4按书目编号检索\n";cout<<"/** 5查询读者信息\n";cout<<"/** 6读者借书\n";cout<<"/** 7读者还书\n";cout<<"/** 8更新文件记录\n";cout<<"/** 0退出图书管理系统\n";cout<<"/** 请选择要执行的操作\n";cin>>fun;switch(fun){case 1:cout<<"/** 请依次输入书名,书目编号,作者名称,现有册数,并用空格隔开!\n";cin>>cname;cin>>cno;cin>>creathur;cin>>cnum;Book_insert(book,cname,cno,creathur,cnum);break;case 2:cout<<"/** 请输入书名:";cin>>cname;Book_delete(book,cname);break;case 3:cout<<"/** 请输入书名:";cin>>cname;//Inorder(book);Inorder_search( book,cname,i);if(i!=1){cout<<"没有找到符合条件的信息,是否要新建该记录....\n\n";}break;case 4:cout<<"/** 请输入书目编号:";cin>>cno;Inorder_searchNo( book,cno,i);//cout<<i;if(i!=1){cout<<"没有找到符合条件的信息,是否要新建该记录....\n\n";}break;case 5:cout<<"/** 请输入读者名:";cin>>cname;Rnorder_name(Readeroot,cname,i);if(i!=1){cout<<"没有找到符合条件的信息,是否要新建该记录....\n\n";}break;case 6:Borrow_book(book,Readeroot);break;case 7:Return_book(book,Readeroot);break;case 8:write_file(book);cout<<"更新成功!\n";break;case 0:exit(0);break;}}}。

(完整word版)图书管理系统源代码

(完整word版)图书管理系统源代码

图书管理系统源代码(一)程序代码1。

主窗口界面import java.awt。

*;import java.awt。

event.*;import javax。

swing.*;import javax.swing.border.TitledBorder;import java.awt。

Font;import javax.swing。

JMenu;public class MainWindow extends JFrame implements ActionListener { private static final long serialVersionUID = 1L;static String loginName;static String loginNo;JLabel mlabel;JPanel jp=new JPanel();//建立菜单栏JMenu a=new JMenu();JMenu b=new JMenu();JMenu c=new JMenu();//建立系统管理菜单组JMenuItem aa=new JMenuItem();JMenuItem ab=new JMenuItem();JMenuItem ac=new JMenuItem();//建立读者管理菜单组JMenuItem bb=new JMenuItem();//建立书籍管理菜单组JMenuItem ca=new JMenuItem();JMenuItem cb=new JMenuItem();JMenuItem cc=new JMenuItem();JMenuItem cd=new JMenuItem();public MainWindow(){super(”图书管理系统");addWindowListener(new WindowAdapter(){System.exit(0);}});Container d=getContentPane();this。

图书借阅管理系统代码图书管理系统源代码

图书借阅管理系统代码图书管理系统源代码

#include<stdio。

h>#include 〈stdlib。

h>#include <string.h>#define num 7 //全局定义void showmain() //显示菜单{printf("\n\n 欢迎使用图书借阅管理系统\n\n");printf(" 1、查询所有图书\n\n");printf(" 2、归还现有图书\n\n");printf(" 3、租借现有图书\n\n”);printf(”0、退出借书系统\n\n");printf(”请输入您所需的服务编号:”);}void viewbooks(int score[num],char name[num][100],char writter[num][100],double yajin[num],int free[num],double jiage[num],int flag[num]){int i;int j;for(i=1;i〈7;i++)//设置编号score[i]=i;yajin[1]=26.00;//将原图书的各项值保存yajin[2]=28.50;yajin[3]=98。

00;yajin[4]=79.80;yajin[5]=49。

00;yajin[6]=15.00;for(i=1;i<7;i++)//将原图书的各项值保存{free[i]=30;jiage[i]=0.5;}flag[1]=0; //flag为0代表已借出,为1代表未借出flag[2]=1;flag[3]=1;flag[4]=0;flag[5]=1;flag[6]=1;printf("编号\t|书名\t |作者\t|押金\t|免费天数\t|收费价格\t|出租状态\n"); //制表同时输出printf(”—--——-—---——-------—--——-————-——-———-—-—————--—————-—--——-——————-—-—---——-—\n”);for(i=1;i<7;i++){printf(”%d\t|%s\t|%s\t|%。

图书管理系统源代码

图书管理系统源代码
{
char tsname[60];
char tsbh[6];
char xm[10];
char tel[13];
char sfc[20];
int tssl;
int tsyj;
}js[n];
void main()
{
load();
help: //帮助系统
system("time /t");
system("color 2f");
printf("\t\t ");
printf("\n\t\t\t欢迎使用本系统: << %s >> ",user1);
system("time /t");
printf("\n");
printf("\t\t\t◢※※※※※※※※※※※※※※※◣\n");
printf("\t\t\t※※※※※※※※※※※※※※※※※\n");
printf("\t\t\t※ ※\n");
printf("\t\t\t※ ◎ (1) 图 书 查 询 ★ ※\n"); //有没有书名和书的总量
first1 = time(NULL); /* Gets system time */
system("cls");
system("date /t");
system("time /t");
system("color 47");
printf("\n");

图书管理系统源代码--纯C语言.

图书管理系统源代码--纯C语言.

#include<stdio.h>#include<stdlib.h>#include<string.h>#include<ctype.h>#define NULL 0#define LEN sizeof(Book)struct A{char Name[20];int all,left,borrow;struct A *next;};typedef struct A Book;int Display_Main_Menu(); /*主菜单显示*/Book *Create(); /*功能函数声明*/void Display(Book *head);Book *Insert(Book *head,Book *s);Book *Insert_a_record(Book *head);Book *Delete(Book *head,char *name);Book *Delete_a_record(Book *head);Book *Borrow(Book *head,char *name,int sum);Book *Borrow_a_Book(Book *head);Book *Return(Book *head,char *name,int sum);Book *Return_a_Book(Book *head);Book *Query(Book *head,char *name);void Query_a_record(Book *head);Book *AddfromText(Book *head,char *filename);Book *WritetoText(Book *head,char *filename);void Quit(Book *head);void main() /*主函数部分*/{Book *head; /*定义变量*/char filename[20];int keyword=111,a;printf("Please input keyword:");scanf("%d",&a);if(a!=keyword) exit(0);else printf("Welcome!");head=NULL; /*置首指针为空*/for(;;){switch(Display_MainMenu()){case 1:printf("1.Create BookList\n"); /*调用Create函数创建链表*/ head=Create();system("pause");break;case 2:printf("Display All Books\n");Display(head); /*调用Display函数显示所有*/system("pause");break;case 3:printf("Insert a Record\n");head=Insert_a_record(head);/*调用Insert_a_record函数插入*/system("pause");break;case 4:printf("Delete a Book\n");head=Delete_a_record(head);/*调用Delete_a_record函数删除*/ system("pause");break;case 5:printf("Borrow a Book\nInput BookName and sum you borrow:");head=Borrow_a_Book(head);system("pause");break;case 6:printf("Return a Book\nInput BookName and sum you return:");head=Return_a_Book(head);system("pause");break;case 7:printf("Query\nInput the BookName you want:");Query_a_record(head);/*调用查询函数*/system("pause");break;case 8:printf("Input the name of Text File\n");scanf("%s",filename);/*输入文件名*/head=AddfromText(head,filename);system("pause");break;case 9:printf("Input the name of the NewText File\n");scanf("%s",filename);/*输入要写入的文件名*/head=WritetoText(head,filename);system("pause");break;case 0:printf("Goodbye\n");Quit(head);exit(0);}}}int Display_MainMenu() /*显示菜单的函数*/{char x;do{system("cls");printf("************************\n");printf("1.Create BookList\n");printf("2.Display All Books\n");printf("3.Insert a BookInformation\n");printf("4.Delete a Book\n");printf("5.Borrow a Book\n");printf("6.Return a Book\n");printf("7.Query\n");printf("8.Add Records From a File\n");printf("9.Write to a File\n");printf("0.Goodbye\n");printf("************************\n");printf("Please choose from 0-9:");printf("\n");x=getchar();}while(x<'0'||x>'9');return(x-'0');}Book *Create() /*创建链表的函数,返回首指针*/{Book *head,*newrecord;char ch;printf("Input a Book\n");head=NULL;/*首指针置空*/do{newrecord=(Book *)malloc(LEN); /*动态分配存储空间*/scanf("%s%d",newrecord->Name,&newrecord->all);newrecord->left=newrecord->all;newrecord->borrow=0;head=Insert(head,newrecord); /*调用Insert函数判断位置插入*/getchar(); / *接收最后输入的回车符*/printf("Add another Book Y/N?\n");ch=getchar();getchar(); /*接收回车符*/ }while(ch!='n'&&ch!='N'); /*判断是否继续*/return(head);}Book *Insert(Book *head,Book *s)/*插入结点的函数*/{ Book *p0,*p1,*p2;p1=head;p0=s;if(head==NULL){head=p0;p0->next=NULL;}while(strcmp(p0->Name,p1->Name)>0&&(p1->next!=NULL)){p2=p p1=p1->next;}if(strcmp(p0->Name,p1->Name)<=0){p0->next=p1;if(head==p1) head=p0;else p2->next=p0;}else{p1->next=p0;p0->next=NULL;}return(head);}Book *Insert_a_record(Book *head){ Book *newrecord;newrecord=(Book *)malloc(LEN); /*动态分配存储空间*/scanf("%s%d",newrecord->Name,&newrecord->all);newrecord->borrow=0;newrecord->left=newrecord->all;head=Insert(head,newrecord);printf("Insert successfully\n");/*输出插入成功的信息*/return(head);}Book *Delete(Book *head,char *name) /*删除功能函数*/{ Book *p1,*p2;if(head==NULL)printf("Sorry No record!\n");p1=head;while(strcmp(p1->Name,name)!=0&&p1->next!=NULL) / {p2=p1;p1=p1->next;} if(strcmp(p1->Name,name)==0){if(p1==head)head=p1->next;else {p2->next=p1->next;printf("delete %s successfully\n",name);}}return(head);}Book *Delete_a_record(Book *head){ char name[20],ch;Book *p;scanf("%s",name);getchar();p=Query(head,name);if(p==NULL) printf("Cannot Find %s\n",name);else {printf("Delete %s, Y/N?\n",name);ch=getchar();system("pause");if(ch=='y'||ch=='Y')while(p!=NULL){head=Delete(head,name);p=Query(head,name);}}return(head);}Book *Borrow_a_Book(Book *head){ char name[20],ch;int n;Book *p;scanf("%s%d",name,&n);getchar(); /p=Query(head,name);if(p==NULL) printf("Cannot Find %s\n",name);else printf("Are you sure to borrow? %s, Y/N?\n",name);ch=getchar();system("pause");if(ch=='y'||ch=='Y')head=Borrow(head,name,n);return(head);}Book *Borrow(Book *head,char *name,int sum){ Book *p1;p1=head;while(strcmp(p1->Name,name)!=0&&p1->next!=NULL){p1=p1->next;}if(strcmp(p1->Name,name)==0)p1->borrow=sum;p1->left=p1->all-sum;return(head);}Book *Return_a_Book(Book *head){ char name[20],ch;int n;Book *p;scanf("%s%d",name,&n);getchar(); /*接收回车*/ p=Query(head,name);if(p==NULL) printf("Cannot Find %s\n",name); /*找不到结点*/ else printf("Are you sure to return? %s, Y/N?\n",name);ch=getchar();system("pause");if(ch=='y'||ch=='Y')head=Return(head,name,n);return(head);}Book *Return(Book *head,char *name,int sum){ Book *p1;p1=head;while(strcmp(p1->Name,name)!=0&&p1->next!=NULL) /*p1不是要找的结点,且后面还有结点*/{p1=p1->next;} /*p1后移一个结点*/if(strcmp(p1->Name,name)==0) /*找到了*/p1->borrow=p1->borrow-sum;p1->left=p1->left+sum;return(head);}void Display(Book *head){ Book *p;int i;p=head;printf("Num BookName Total Left Borrow\n");for(i=1;p!=NULL;i++){printf("%-5d%-14s%-10d%-10d%-5d\n",i,p->Name,p->all,p->left,p->borrow);p=p->next;if(i%10==0){system("pause"); /*按回车继续显示*/printf("Num BookName total left borrow\n");}}}Book *Query(Book *head,char *name){ Book *p;p=head;while(strcmp(name,p->Name)!=0&&p->next!=NULL)p=p->next;if(strcmp(name,p->Name)==0) /*找到了,返回结点地址*/return(p);else /*找不到返回空指针*/return(NULL);}void Query_a_record(Book *head){ char name[20];Book *p;scanf("%s",name);p=Query(head,name);if(p!=NULL) /*找到了*/{ printf("Find successfully\n%s total:%d left:%d borrow:%d\n",p->Name,p->all,p->left,p->borrow);}elseprintf("Can't find the records of %s\n",name); /*找不到*/}Book *AddfromText(Book *head,char *filename){ FILE *fp;int n,i;if((fp=fopen(filename,"r"))==NULL){printf("Cannot find file:%s\n",filename); /*打不开所指定文件*/return(head);}fscanf(fp,"%d",&n); /*待插入记录个数*/for(i=0;i<n;i++){Book *p;p=(Book *)malloc(LEN);fgetc(fp); /*读取换行符*/fscanf(fp,"%s%d%d%d",p->Name,&p->all,&p->left,&p->borrow);head=Insert(head,p); /*插入结点*/}printf("Add from %s successfully\n",filename);fclose(fp);return(head);}Book *WritetoText(Book *head,char *filename){FILE *fp;Book *p;if(head==NULL){printf("No Record!\n");return(head);}fp=fopen(filename,"w"); /*打开文件*/p=head;while(p!=NULL){ fprintf(fp,"%-14s%-10d%-10d%-10d\n\n",p->Name,p->all,p->left,p->borrow); /*文件输出*/p=p->next;}printf("Write to %s successfully\n",filename); /*输出写到文件完毕的信息*/ fclose(fp);return(head);}void Quit(Book *head){Book *p,*p1,*p2;FILE *fp;char filename[]="last";p2=p1=head;if(head!=NULL){fp=fopen(filename,"w"); /*打开文件*/p=head;while(p!=NULL){ fprintf(fp,"%s %d %d %d\n",p->Name,p->all,p->left,p->borrow); /*文件输出*/p=p->next;}printf("Write to %s successfully\n",filename); /*输出写到文件完毕的信息*/ fclose(fp);}while(p1!=NULL) /*p1指向的结点不是空指针*/{p2=p1->next;free(p1); /*释放存储空间*/p1=p2; /*p1后移一个结点*/}}。

图书信息管理系统设计源代码

图书信息管理系统设计源代码

头函数名:#include<stdio.h>#include<stdlib.h>#include<string.h>/*********图书信息结构体*********//***包括登录号,书名,作者名,分类号,出版单位,出版时间,价格等***/ struct bookinf{ int num; ******************************************************登录号char bname[20];***************************************书名char wname[10];***************************************作者名char clanum[14];***************************************分类号char pubcom[10];***************************************出版单位char pubtime[10];***************************************出版时间float price;*********************************************价格};一管理员登录系统模块:(1)来到图书信息管理系统页面void index(){char input; 注释:运行时printf("\n\n\t\t\t*****************************\n"); 直接进入printf("\t\t\t 图书信息管理系统\n"); 这个页面printf("\t\t\t*****************************\n\n\n");printf(" ------------------------------------------------------------------------------\n");printf("\t<按任意键进入>\n\t");input=getchar();}(2)管理员登陆进入功能菜单页面FILE *fp;struct manage pswd;if ((fp=fopen("password.txt","r"))==NULL) {printf("\n\n\n\tCannot open file!\n\t");}else{do{printf("\n\n\t请输入管理员帐号:");scanf("%s",name);printf("\n\n\t请输入管理员密码:");scanf("%s",password);fp=fopen("password.txt","r");fread(&pswd,sizeof(struct manage),1,fp);fclose(fp);w=strcmp(pswd.manage_name,name);k=strcmp(pswd.password,password);adm_servelist();}while (w!=0||k!=0);adm_servelist();}}(3)来到功能菜单页面{void book_add();void book_view();void change();void del();void book_search();void login();void pwchange();int in; 注释:菜单列出的服务种类char input; 从1,2,3,4,5,6 do 所对应的功能进行选择{printf("\n\n\n\t--欢迎使用信息管理系统--");printf("\n\n\t1.图书信息录入\n");printf("\t2.图书信息浏览\n");printf("\t3.图书信息查询\n");printf("\t4.图书信息删除\n");printf("\t5.图书信息修改\n");printf("\t6.退出管理模式\n");printf("\n\t请选择服务种类:");scanf("%d",&in);if (in!=1&&in!=2&&in!=3&&in!=4&&in!=5&&in!=6){printf("\n\t没有这项服务~\n");printf("\t按任意键重新选择");input=getchar();}}while (in!=1&&in!=2&&in!=3&&in!=4&&in!=5&&in!=6);switch (in){case 1: book_add(); break; 注释:选择自己所需要case 2: book_view(); break; 后摁下数字键则case 3: book_search(); break; 则进入此功能页面case 4: del(); break;case 5: change();break;case 6: login(); break;}}(3)图书信息录入功能模块void book_add(){void book_add();int i=0,j;FILE *fp;char input; 注释:输入的图书信息struct bookinf books; 是通过文件进行struct bookinf book_taxis[30]; 保存的printf("\n\n\n\t---请输入图书信息---\n\n");printf("\t登录号:");scanf("%d",&books.num);printf("\n\t书名:");scanf("%s",books.bname);printf("\n\t作者名:");scanf("%s",books.wname);printf("\n\t分类号:");scanf("%s",books.clanum);printf("\n\t出版单位:");scanf("%s",books.pubcom);printf("\n\t出版时间:");scanf("%s",books.pubtime);printf("\n\t价格:");scanf("%f",&books.price);if ((fp=fopen("book.txt","r"))!=NULL){do{fread(&book_taxis[i],sizeof(struct bookinf),1,fp);i=i+1;}while(!feof(fp));fclose(fp);for (j=0;j<=i;j++)if (books.num==book_taxis[j].num){printf("\n\n\n\t对不起,这个编号已经使用过了~\n");printf("\t按任意键返回管理菜单~");input=getchar();adm_servelist();break;}}if ((fp=fopen("book.txt","r"))==NULL){fp=fopen("book.txt","w");}else{fclose(fp);fp=fopen("book.txt","a");}fwrite(&books,sizeof(struct bookinf),1,fp);fclose(fp);printf("\n\n\n\t信息输入完毕~按任意键继续\n");input=getchar();adm_servelist();}(4)图书信息浏览功能模块void book_view(){void adm_servelist();void book_view();int inp,i=0,n=0;FILE *fp;char input;struct bookinf bookview[20];if ((fp=fopen("book.txt","r"))==NULL){printf("\n\n\n\t数据尚未初始化~~\n\n\t请在管理菜单中增加图书信息~~~\n"); printf("\n\t<按任意键返回管理菜单>\n\t");input=getchar();adm_servelist();}else{do{fread(&bookview[i],sizeof(struct bookinf),1,fp);i=i+1;}while (!feof(fp));fclose(fp);do{printf("\n\t--------共有%d条记录--------",i-1);printf("\n\n\t登录号: %d\n",bookview[n].num);printf("\n\t书名: %s\n",bookview[n].bname);printf("\n\t作者名: %s\n",bookview[n].wname);printf("\n\t分类号: %s\n",bookview[n].clanum);printf("\n\t出版单位: %s\n",bookview[n].pubcom);printf("\n\t出版时间: %s\n",bookview[n].pubtime);printf("\n\t价格: %f\n",bookview[n].price);printf("\n\n\t1.上一页\t2.下一页\t3.回目录\n");printf("\n\t请选择:");scanf("%d",&inp);switch (inp){case 1:{if (n==0){printf("\n\t已到达首页\n\t按任意键重新选择");input=getchar();}else n=n-1; break;}case 2:{if (n==i-2){printf("\n\t已到达最末页\n\t按任意键重新选择");input=getchar();}else n=n+1; break;}case 3:{adm_servelist();break;}default:{printf("\n\t没有这项服务\n\t按任意键重新选择");input=getchar();}}}while (inp!=3);}}(5)图书信息修改与删除功能模块修改:void change(int x){int inp,i=0,j;void book_search();FILE *fp,*fp1;char input;struct bookinf books,book_taxis[20];do{printf("\n\n\n\t注意:您确定要修改该记录吗?\n"); printf("\n\t1.是\t2.否\n");printf("\n\t请输入:");scanf("%d",&inp);if (inp!=1&&inp!=2){printf("\n\t对不起~没有这项服务~\n");printf("\t按任意键重新选择\n\t");input=getchar();}}while (inp!=1&&inp!=2);if (inp==2)book_search();if (inp==1){printf("\n\n\n\t---请输入图书信息---\n\n");printf("\t登录号:");scanf("%d",&books.num);printf("\n\t书名:");scanf("%s",books.bname);printf("\n\t作者名:");scanf("%s",books.wname);printf("\n\t分类号:");scanf("%s",books.clanum);printf("\n\t出版单位:");scanf("%s",books.pubcom);printf("\n\t出版时间:");scanf("%s",books.pubtime);printf("\n\t价格:");scanf("%f",&books.price);if ((fp1=fopen("book.txt","r"))!=NULL){do{fread(&book_taxis[i],sizeof(struct bookinf),1,fp1);i=i+1;}while(!feof(fp1));fclose(fp1);for (j=0;j<x;j++)if (books.num==book_taxis[j].num){printf("\n\n\n\t对不起,这个编号已经使用过了~\n");printf("\t按任意键返回管理菜单~");printf("0");input=getchar();book_search();break;}for (j=x+1;j<i-2;j++)if (books.num==book_taxis[j].num){printf("\n\n\n\t对不起,这个编号已经使用过了~\n");printf("1");printf("\t按任意键返回管理菜单~");input=getchar();book_search();break;}}book_taxis[x]=books;fp=fopen("book.txt","w");for (j=0;j<i-1;j++)fwrite(&book_taxis[j],sizeof(struct bookinf),1,fp);fclose(fp);printf("\n\n\t信息修改完成!按任意键返回");input=getchar();book_search();}}S删除:void del(int y){char input;FILE *fp;int inp,i=0,j;struct bookinf book_taxis[20];void book_search();void adm_servelist();do{printf("\n\n\n\t注意:您确定要删除该记录吗?\n"); printf("\n\t1.是\t2.否\n");printf("\n\t请输入:");scanf("%d",&inp);if (inp!=1&&inp!=2){printf("\n\t对不起~没有这项服务~\n");printf("\t按任意键重新选择\n\t");input=getchar();}}while (inp!=1&&inp!=2);if (inp==2)book_search();if (inp==1){if ((fp=fopen("book.txt","r"))!=NULL){do{fread(&book_taxis[i],sizeof(struct bookinf),1,fp);i=i+1;}while(!feof(fp));fclose(fp);}if (i>2){fp=fopen("book.txt","w");for (j=0;j<y;j++)fwrite(&book_taxis[j],sizeof(struct bookinf),1,fp);fclose(fp);fp=fopen("book.txt","a");for (j=y+1;j<i-1;j++)fwrite(&book_taxis[j],sizeof(struct bookinf),1,fp);fclose(fp);}else{remove("book.txt");}printf("\n\n\t记录已删除!\n\n\t按任意键返回\n\t");input=getchar();adm_servelist();}}(6)图书信息查询功能模块void book_search(){void adm_servelist();void id_search();void wr_search();void bn_search();char input;FILE *fp;int inp;if ((fp=fopen("book.txt","r"))==NULL){printf("\n\n\n\t数据尚未初始化~~\n\n\t请在管理菜单中增加图书信息~~~\n"); printf("\n\t<按任意键返回管理菜单>\n\t");input=getchar();adm_servelist();}else{do{printf("\n\n\n\t1.按图书登录号查询\n");printf("\n\t2.按图书作者查询\n");printf("\n\t3.按图书名查询\n");printf("\n\t4.回到主菜单\n");printf("\n\n\t请选择查询类别:");scanf("%d",&inp);if (inp!=1&&inp!=2&&inp!=3&&inp!=4){printf("\n\n\t没有这项服务~\n\t按任意键重新选择~");input=getchar();}}while (inp!=1&&inp!=2&&inp!=3&&inp!=4);fclose(fp);switch (inp){case 1: id_search(); break;case 2: wr_search(); break;case 3: bn_search(); break;case 4: adm_servelist(); break;}}}。

图书管理系统源代码 (3)

图书管理系统源代码 (3)

图书管理系统源代码1. 简介图书管理系统是一种用于管理图书馆或书店中图书信息的软件系统。

它主要提供了图书的添加、编辑、删除、查询等功能,便于管理人员对图书信息进行集中管理,同时也能方便读者进行图书的查询和借阅操作。

本文档将介绍一个基于Python的简单图书管理系统的源代码,以及其使用说明和功能演示。

2. 系统设计2.1 使用的库该图书管理系统使用了以下Python库来实现不同功能:•Tkinter:用于GUI界面的设计和实现。

•SQLite3:用于图书信息的持久化存储。

2.2 数据库设计在该图书管理系统中,我们使用了一个简单的图书信息表来存储图书的相关信息。

该表包含以下字段:•book_id:图书ID,唯一标识一个图书。

•book_title:图书标题,描述图书的名称。

•book_author:图书作者,描述图书的作者信息。

•book_publisher:图书出版商,描述图书的出版商信息。

2.3 功能设计该图书管理系统实现了以下功能:•添加图书:管理员可以添加一本新的图书到系统中。

•编辑图书:管理员可以编辑已存在的图书信息。

•删除图书:管理员可以从系统中删除指定的图书。

•查询图书:管理员和读者都可以根据图书的标题、作者或出版商来查询图书信息。

3. 源代码以下是该图书管理系统的源代码(使用Python编写):```python import tkinter as tk import sqlite3连接到数据库conn = sqlite3.connect(’library.db’) c = conn.cursor()创建图书信息表c.execute(’’’ CREATE TABLE IF NOT EXISTS books ( book_id INTEGER PRIMARY KEY AUTOINCREMENT, book_title TEXT, book_author TEXT, book_publisher TEXT ) ’’’)窗口初始化window = () window.title(。

图书管理系统程序代码

图书管理系统程序代码

#include<fstream〉#include<iostream〉#include<stdlib.h〉#include〈ctime〉#include<cmath>#include〈termios.h〉#include <sstream〉#include<string。

h〉#include<assert.h〉//改变字体颜色#define NONE "\033[m"#define RED "\033[0;32;31m”#define GREEN ”\033[0;32;32m”#define BLUE "\033[0;32;34m”#define YELLOW ”\033[1;33m”#define LIGHT_RED ”\033[1;31m”#define LIGHT_GREEN "\033[1;32m"#define LIGHT_BLUE "\033[1;34m”/*程序导读:1。

程序中对书的操作,可通过书名,编号来进行,flag=0按书名来操作,flag=1按书编号来操作2.程序中对用户的操作,也可通过姓名,用户ID号或编号两种方式来进行,flag=0按姓名来操作,flag=1按用户ID号或编号来操作3。

本程序分5个部分,具体已标识如(1)图书管理。

.*/using namespace std;class Book{public:string book_name;string book_num;//编号string book_pre;//出版社string book_aut;//作者int book_con;//这样的书还有几本int book_mux;//这样的书总共有几本public:Book(){book_con=0;book_mux=0;}void show_book();};/****************************************(1)图书管理*******************************************/void Book::show_book(){cout<〈"书名:”<〈book_name<〈endl;cout〈〈”出版社:"〈<book_pre〈〈endl;cout<<”此书的作者:"〈<book_aut〈<endl;cout〈<”ISBN编号:”<〈book_num<〈endl;cout<<"此书共有"〈<book_mux<<”本”〈〈endl;cout<<”还有"<<book_con〈〈”本书未借出!"〈<endl;}class BookNode{public:Book book;BookNode *next;};BookNode *headbook=NULL;class BookManage{public:int totolbook;public:BookManage(){totolbook=0;}void addbook();void delbook(string s,int num,int flag);void findbook(string s,int flag);//查询图书};void BookManage::addbook(){string h;cout〈〈"添加输入0,退出输入—1"<〈endl;cin>>h;if(h==”-1”)return;else if(h=="0”)while(1){if(h==”-1”)break;else if(h==”0”){string na,nu,p1,aut;int con;BookNode *p=new BookNode;cout<<”请输入书名:"〈〈endl;cin〉>na;p—〉book.book_name=na;cout<〈"请输入ISBN编号:”<<endl;cin>〉nu;p->book。

图书管理系统(源代码)

图书管理系统(源代码)

#include"stdio.h"#include"stdlib.h"#include"string.h"#define MENU_ADMIN_COUNT 2#define MENU_SEARCH_BOOK_COUNT 6 #define MENU_USER_COUNT 7#define BOOK_FILE "books.dat"#define USER_FILE "user.dat"#define MAX_BOOK_NAME 20#define MAX_PUBLISHER 20#define MAX_DATE 10#define MAX_AUTHOR 20#define MAX_ISBN 20typedef struct _book_info{ char book_name[MAX_BOOK_NAME]; char author[MAX_AUTHOR];char publisher[MAX_PUBLISHER];char pub_date[MAX_DA TE];char ISBN[MAX_ISBN];int pages;}book_info;typedef struct _book{ book_info bi;struct _book* next;}book;#define MAX_USERNAME 10#define MAX_PASSWORD 10typedef enum _USER_TYPE{ADMIN=0,USER}USER_TYPE;typedef struct _user_info{char username[MAX_USERNAME];char password[MAX_PASSWORD]; USER_TYPE user_type;}user_info;typedef struct _user{ user_info ui;struct _user* next;}user;void init_user();void load_users();USER_TYPE login();void add_user();void search_user();void save_users();void clear_users();void save_users_to_file();user* get_last_user();user* get_previous_user(user* p);user* find_user(char* name);void show_user(user_info* info);void input_user(user_info* info);void delete_user(user* p);void update_user(user* p);void init_book();void load_books();void add_book();void view_book();void delete_book();void save_books();void clear_books();void search_book_by_name();void search_book_by_author();void search_book_by_publisher();void search_book_by_pubdate();void search_book_by_isbn();int findstr(char *source,char *str);void save_books_to_file();book* get_last_book();book* get_previous_book(book* p);void input_book(book_info* info);void show_book(book_info* info);void show_admin_menu();void show_search_book_menu();void show_user_menu();void admin_exit();void user_exit();book *first_book=NULL;user* first_user=NULL;char menu_title[]="=========================================\n" "| 图书管理系统|\n""+---------------------------------------+\n";char menu_admin[]="| |\n" "| (1)图书管理|\n" "| (2)用户管理|\n" "| (3)退出系统|\n" "+---------------------------------------+\n";char admin_menu1[]="-----------------------------------------\n""| 图书管理|\n" "----------------------------------------|\n""| <1>新增图书|\n" "| <2>浏览图书|\n" "| <3>查找图书|\n" "| <4>删除图书|\n" "| <5>保存图书|\n" "| <0>返回主菜单|\n" "-----------------------------------------\n";char admin_menu2[]="----------------------------------------\n"" 用户管理|\n" "----------------------------------------|\n""| <1>新增用户|\n" "| <2>查找用户|\n" "| <3>保存用户|\n" "| <0>返回主菜单|\n" "|---------------------------------------|\n";void(*menu1_fun[])()={add_book,view_book,show_search_book_menu,delete_book,save_books,};void(*menu2_func[])()={add_user,search_user,save_users,};char menu_admin_search_book[]="| 查找图书:|\n" "| <1>按书名查找|\n" "| <2>按作者查找|\n" "| <3>按出版社查找|\n" "| <4>按出版日期查找|\n" "| <5>按国际标准书号(ISBN)查找|\n" "| <0>返回主菜单|\n" "+--------------------------------------+\n";void (*admin_search_book_func[])()={search_book_by_name,search_book_by_author,search_book_by_publisher,search_book_by_pubdate,search_book_by_isbn,};char menu_user[]="| <1>浏览图书|\n" "| <2>按书名查找图书|\n" "| <3>按作者查找图书|\n" "| <4>按出版社查找图书|\n" "| <5>按出版日期查找图书|\n" "| <6>按国际标准书号(ISBN)查找图书|\n" "| <0>退出系统|\n" "+--------------------------------------+\n";void (*user_func[])()={view_book,search_book_by_name,search_book_by_author,search_book_by_publisher,search_book_by_pubdate,search_book_by_isbn,user_exit};void add_book(){ char try_again='Y';book *p=NULL;book *new_book=NULL;while(try_again=='Y' || try_again=='y'){ new_book=(book*)malloc(sizeof(book));memset(new_book,0,sizeof(book));new_book->next=NULL;printf(">新增图书...\n");input_book(&(new_book->bi));p=get_last_book();if(p==NULL){ first_book=new_book;}else{ p->next=new_book;}printf(">继续添加图书吗?(y or n):");getchar();try_again=getchar();}}void view_book(){ book *p=NULL;char input='Y';int count=0;while(input=='y' || input=='Y'){ count=0;p=first_book;printf("+---------------------------------------+\n");printf("| 书名| 作者|\n");printf("+---------------------------------------+\n");while(p!=NULL){ printf("|%20s|%20s|\n",p->bi.book_name,p->bi.author);printf("+-------------------------------------+\n");count++;if(count==5){ count=0;printf(">显示下一页吗?(y or n):");getchar();input=getchar();if(input!='y' && input!='Y'){ break;}}p=p->next;}printf(">再次浏览图书吗?(y or n):");getchar();input=getchar();}}void search_book_by_name(){ book *p=NULL;char s[MAX_BOOK_NAME]={0};char input='Y';int count=0;int i=0;printf(">查找图书...\n");while(input=='Y' || input=='y'){ count=0;p=first_book;memset(s,0,MAX_BOOK_NAME);printf(">请输入书名(最大长度为%d):",MAX_BOOK_NAME);scanf("%s",s);while(p!=NULL){ if(findstr(p->bi.book_name,s)!=-1){ show_book(&(p->bi));count++;}p=p->next;}if(count==0){ printf(">没有找到图书%s。

图书管理系统的设计(C语言)

图书管理系统的设计(C语言)

图书管理系统设计图书管理信息包括:图书名称、图书编号、单价、作者、存在状态、借书人姓名、性别、学号等功能描述:1 .新进熟土基本信息的输入2 .图书基本信息的查询3 .对撤销图书信息的删除4 .为借书人办理注册5 .办理借书手续6 .办理换书手续要求:以文件方式存储数据,系统以菜单方式工作。

这是本人大一第二学期初 C 语言课程设计的作品,嘿嘿,本来以为已经找不到原稿了,今天无意中居然在QQ 网络硬盘中找到了当初的teta 版,发布于此,以作记念。

C 源代码如下:#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。

图书管理系统源代码(原创)

图书管理系统源代码(原创)

#include<stdio.h>#include<stdlib.h>#include<string.h>struct book{int num;char bname[50];char wname[20];char press[50];char sort[50];int time;float price;struct book *next;};struct book *creatbook(); //创建链表struct book *addbook(struct book *head); //添加图书int yanzheng(struct book *head,int m); //验证新添加的图书编码是否已存在void deletebook(struct book *head); //删除图书void fprint(struct book *head); //将链表写入文件struct book *load(); //从文件中读取信息并建成链表void print_book(struct book *head); //将链表信息输出void chaxun(struct book *head); //查询图书信息void num_chaxun(struct book *head); //按图书编号查询图书void wname_chaxun(struct book *head); //按作者名查询图书void sort_chaxun(struct book *head); //按类别查询图书void time_chaxun(struct book *head); //按出版时间查询图书void bname_chaxun(struct book *head); //按图书名查询图书void xiugai(struct book *head); //修改图书信息void paixu(struct book *head); //对图书进行排序void num_paixu(struct book *head); //按图书编号排序void time_paixu(struct book *head); //按图书出版时间排序void price_paixu(struct book *head); //按图书价格排序void bname_paixu(struct book *head); //按图书名排序void wname_paixu(struct book *head); //按作者名排序int main(){int choice,n,x,y=1,c,c1=1;char a,d,b[10],b1[10]="1";struct book *head=NULL;while(y){system("cls");printf("\n\n\n\n\n");printf(" ----------------------------------------------------------------------\n");printf(" --- ||-------------||-------图书信息管理系统--------||-----------||---\n");printf(" --- ||-------------||------- 登陆界面--------||-----------||---\n");printf(" ----------------------------------------------------------------------\n");printf("\n");printf(" ============1-进入系统===========\n");printf(" ============0-退出系统===========\n");printf(" ----------------------------------------------------------------------\n");printf(" 请输入选择:");scanf("%d",&n);printf("\n");getchar();switch(n){case 0:y=0;break;case 1:printf(" 请输入您的用户名(输入1即可):");gets(b);printf("\n");printf(" 请输入您的密码(输入1即可):");scanf("%d",&c);printf("\n");if(strcmp(b,b1)!=0||c!=c1){printf(" 验证失败,请重新输入!\n");scanf("%c",&d);getchar();system("cls");}else{printf(" 验证通过!请按Enter键进入!\n");scanf("%c",&d);getchar();x=1;while(x){system("cls");system ("color 1F");printf(" ----------------------------------------------------------------------\n\n");printf(" --- ||-------------||-------图书信息管理系统--------||-----------||---\n\n");printf(" --- ||-------------||-----------操作界面------------||-----------||---\n\n");printf(" ----------------------------------------------------------------------\n\n");printf(" ----------------------------------------------\n");printf(" ----||-----------系统菜单选项-----------||----\n");printf(" ----------------------------------------------\n");printf(" -|| 1-添加图书删除图书-2 ||-\n\n");printf(" -|| 3-图书列表图书排序-4 ||-\n\n");printf(" -|| 5-查询图书修改图书-6 ||-\n\n");printf(" -|| 7-录入数据退出系统-0 ||-\n\n");printf(" ----------------------------------------------\n");printf(" ----------------------------------------------\n\n");printf("请输入所选择的序号:");scanf("%d",&choice);getchar();system("cls");switch(choice){case 0:x=0;break;case 1:head=load();if(head==NULL){printf("文件为空,请先录入数据!\n");getchar();break;}else{head=addbook(head);printf("添加成功!\n");printf("是否将新信息保存到文件?(y/n)\n");scanf("%c",&a);getchar();switch(a){case 'n':break;case 'y':fprint(head);printf("保存成功!\n");getchar();break;}break;}case 2:head=load();if(head==NULL){printf("文件为空,请先录入数据!\n");getchar();break;}else{deletebook(head);getchar();break;}break;case 3:head=load();if(head==NULL){printf("文件为空,请先录入数据!\n");getchar();break;}else{print_book(head);getchar();break;}case 4:head=load();if(head==NULL){printf("文件为空,请先录入数据!\n");getchar();break;}else{paixu(head);getchar();}break;case 5:head=load();if(head==NULL){printf("文件为空,请先录入数据!\n");getchar();break;}else{chaxun(head);getchar();}break;case 6:head=load();if(head==NULL){printf("文件为空,请先录入数据!\n");getchar();break;}else{xiugai(head);getchar();break;}break;case 7:printf("注意:输入图书编码为0时结束!\n");head=creatbook();printf("是否将输入的信息保存到文件以覆盖文件中已存在的信息?(y/n)\n");getchar();scanf("%c",&a);getchar();switch(a){case '0':break;case 'y':fprint(head);printf("保存成功!\n");getchar();break;}break;default:printf("输入有误,请重新输入!\n");getchar();break;}}}break;default:printf(" 输入有误,请重新输入!\n");getchar();break;}}}//录入数据并形成链表struct book *creatbook(){struct book *head,*tail,*p;int num,time,n;char bname[50],wname[20],press[50],sort[50];float price;int size=sizeof(struct book);head=tail=NULL;printf("请输入图书编号:");scanf("%d",&num);printf("请输入图书名:");scanf("%s",bname);getchar();printf("请输入作者名:");scanf("%s",wname);getchar();printf("请输入出版社:");scanf("%s",press);getchar();printf("请输入类别:");scanf("%s",sort);getchar();printf("请输入出版时间:");scanf("%d",&time);getchar();printf("请输入价格:");scanf("%f",&price);getchar();while(1){p=(struct book *)malloc(size);p->num=num;strcpy(p->bname,bname);strcpy(p->wname,wname);strcpy(p->press,press);strcpy(p->sort,sort);p->time=time;p->price=price;p->next=NULL;if(head==NULL)head=p;elsetail->next=p;tail=p;do{printf("请输入图书编号:");scanf("%d",&num);n=yanzheng(head,num);if(n==0)break;elseprintf("您输入的编号已存在,请重新输入!\n"); }while(1);if(num==0)break;else{printf("请输入图书名:");scanf("%s",bname);getchar();printf("请输入作者名:");scanf("%s",wname);getchar();printf("请输入出版社:");scanf("%s",press);getchar();printf("请输入类别:");scanf("%s",sort);getchar();printf("请输入出版时间:");scanf("%d",&time);getchar();printf("请输入价格:");scanf("%f",&price);getchar();}}return head;}//插入结点,并且插入后仍按一定顺序struct book *addbook(struct book *head){struct book *ptr,*p1,*p2,*p;char bname[50],wname[20],press[50],sort[50];int size=sizeof(struct book);int num,time,n=1;float price;do{printf("请输入图书编号:");scanf("%d",&num);n=yanzheng(head,num);if(n==0)break;elseprintf("您输入的编号已存在,请重新输入!\n");}while(1);printf("请输入图书名:");scanf("%s",bname);getchar();printf("请输入作者名:");scanf("%s",wname);getchar();printf("请输入出版社:");scanf("%s",press);getchar();printf("请输入类别:");scanf("%s",sort);getchar();printf("请输入出版时间:");scanf("%d",&time);getchar();printf("请输入价格:");scanf("%f",&price);getchar();p=(struct book *)malloc(size);p->num=num;strcpy(p->bname,bname);strcpy(p->wname,wname);strcpy(p->press,press);strcpy(p->sort,sort);p->time=time;p->price=price;p2=head;ptr=p;while((ptr->num>p2->num)&&(p2->next!=NULL)){ p1=p2;p2=p2->next;}if(ptr->num<=p2->num){if(head==p2)head=ptr;else{p1->next=ptr;p->next=p2;}}else{p2->next=ptr;p->next=NULL;}return head;}//验证添加的图书编号是否已存在int yanzheng(struct book *head,int m){struct book *p;p=head;while(p!=NULL){if(p->num==m)break;p=p->next;}if(p==NULL)return 0;elsereturn 1;}//将新链表写入文件中void fprint(struct book *head){FILE *fp;char ch='1';struct book *p1;if((fp=fopen("f1.txt","w"))==NULL){printf("File open error!\n");exit(0);}fputc(ch,fp);for(p1=head;p1;p1=p1->next){fprintf(fp,"%d %s %s %s %s %d %f\n",p1->num,p1->bname,p1->wname,p1->press,p1->sort ,p1->time,p1->price);}fclose(fp);}//从文件中读取图书信息struct book *load(){FILE *fp;char ch;struct book *head,*tail,*p1;head=tail=NULL;if((fp=fopen("f1.txt","r"))==NULL){printf("File open error!\n");exit(0);}ch=fgetc(fp);if(ch=='1'){while(!feof(fp)){p1=(struct book *)malloc(sizeof(struct book));fscanf(fp,"%d%s%s%s%s%d%f\n",&p1->num,p1->bname,p1->wname,p1->press,p1->sort,&p1-> time,&p1->price);if(head==NULL)head=p1;elsetail->next=p1;tail=p1;}tail->next=NULL;fclose(fp);return head;}elsereturn NULL;}//将整个链表的信息输出void print_book(struct book *head){struct book *ptr;if(head==NULL){printf("\n没有信息!\n");return;}printf(" 图书信息列表如下\n");printf("====================================================================== ======\n");printf(" 编号图书名作者名出版社类别出版时间价格\n");for(ptr=head;ptr;ptr=ptr->next)printf(" %3d %-12s %-8s %-14s %-2s %-4d %.2f\n", ptr->num,ptr->bname,ptr->wname,ptr->press,ptr->sort,ptr->time,ptr->price);printf("====================================================================== ======\n");}//删除图书信息void deletebook(struct book *head){int a;char b,ch='1';struct book *p1,*p2;FILE *fp;printf("请输入要删除的图书编号:");scanf("%d",&a);p1=head;if(p1->num==a&&p1->next==NULL){ //对于文件中只有一组数据printf("是否清空文件!(y/n)\n");getchar();scanf("%c",&b);getchar();switch(b){case 'n':break;case 'y':if((fp=fopen("f1.txt","w"))==NULL){printf("File open error!\n");exit(0);}fclose(fp);printf("文件已清空!\n");}}else{while(p1->num!=a&&p1->next!=NULL){p2=p1;p1=p1->next;}if(p1->next==NULL){if(p1->num==a){p2->next=NULL;printf("是否确定从文件中彻底删除该图书?(y/n)\n");getchar();scanf("%c",&b);switch(b){case 'n':break;case 'y':fprint(head);printf("删除成功!\n");getchar();break;}}else{printf("没有找到要删除的数据!\n");getchar();}}else if(p1==head){head=p1->next;printf("是否确定从文件中彻底删除该图书?(y/n)\n");getchar();scanf("%c",&b);switch(b){case 'n':break;case 'y':fprint(head);printf("删除成功!\n");getchar();break;}}else{p2->next=p1->next;printf("是否确定从文件中彻底删除该图书?(y/n)\n");getchar();scanf("%c",&b);switch(b){case 'n':break;case 'y':fprint(head);printf("删除成功!\n");getchar();break;}}}}//图书查询void chaxun(struct book *head){int a;printf("==========================================================\n");printf(" ** 1-按图书编号查询2-按图书名查询**\n");printf(" ** 3-按图书类别查询4-按作者名查询**\n");printf(" ** 5-按出版时间查询0-退出查询**\n");printf("==========================================================\n");printf("请输入所选择的编号:");scanf("%d",&a);getchar();switch(a){case 0:break;case 1:num_chaxun(head);break;case 2:bname_chaxun(head);break;case 3:sort_chaxun(head);break;case 4:wname_chaxun(head);break;case 5:time_chaxun(head);break;default:printf("您的输入有误!\n");break;}}//按编号查询图书信息void num_chaxun(struct book *head){int a;struct book *p;printf("请选择您要查询的图书编号:");scanf("%d",&a);getchar();p=head;while(p!=NULL){if(p->num==a)break;p=p->next;}if(p==NULL){printf("没有找到该编号的图书!\n");}else{printf(" 你所查询的图书信息如下\n");printf("====================================================================== ======\n");printf(" 编号图书名作者名出版社类别出版时间价格\n");printf(" %3d %-12s %-8s %-14s %-2s %-4d %.2f\n", p->num,p->bname,p->wname,p->press,p->sort,p->time,p->price);printf("====================================================================== ======\n");}}//按图书名查询图书信息void bname_chaxun(struct book *head){char a[50];int flag=0;struct book *p;printf("请选择您要查询的图书名:");gets(a);p=head;while(p!=NULL){if(strcmp(p->bname,a)==0){flag=1;break;}p=p->next;}if(flag==0){printf("没有找到该图书名的图书!\n");}else{printf(" 你所查询的图书信息如下\n");printf("====================================================================== ======\n");printf(" 编号图书名作者名出版社类别出版时间价格\n");while(p!=NULL){if(strcmp(p->bname,a)==0){printf(" %3d %-12s %-8s %-14s %-2s %-4d %.2f\n", p->num,p->bname,p->wname,p->press,p->sort,p->time,p->price);}p=p->next;}printf("====================================================================== ======\n");}}//按作者名查询图书信息void wname_chaxun(struct book *head){char a[50];int flag=0;struct book *p;printf("请选择您要查询的图书作者名:");gets(a);p=head;while(p!=NULL){if(strcmp(p->wname,a)==0){flag=1;break;}p=p->next;}if(flag==0){printf("没有找到该图书名的图书!\n");}else{printf(" 你所查询的图书信息如下\n");printf("====================================================================== ======\n");printf(" 编号图书名作者名出版社类别出版时间价格\n");while(p!=NULL){if(strcmp(p->wname,a)==0){printf(" %3d %-12s %-8s %-14s %-2s %-4d %.2f\n", p->num,p->bname,p->wname,p->press,p->sort,p->time,p->price);flag=1;}p=p->next;}printf("============================================================================\n");}}//按图书类别查询图书信息void sort_chaxun(struct book *head){char a[50];int flag=0;struct book *p;printf("请选择您要查询的图书类别:");gets(a);p=head;while(p!=NULL){if(strcmp(p->sort,a)==0){flag=1;break;}p=p->next;}if(flag==0){printf("没有找到该图书名的图书!\n");}else{printf(" 你所查询的图书信息如下\n");printf("====================================================================== ======\n");printf(" 编号图书名作者名出版社类别出版时间价格\n");while(p!=NULL){if(strcmp(p->sort,a)==0){printf(" %3d %-12s %-8s %-14s %-2s %-4d %.2f\n", p->num,p->bname,p->wname,p->press,p->sort,p->time,p->price);flag=1;}p=p->next;}printf("====================================================================== ======\n");}}//按图书出版时间查询图书信息void time_chaxun(struct book *head){int a,flag=0;struct book *p;printf("请选择您要查询的图书出版时间:");scanf("%d",&a);getchar();p=head;while(p!=NULL){if(p->time==a){flag=1;break;}p=p->next;}if(flag==0){printf("没有找到该图书名的图书!\n");}else{printf(" 你所查询的图书信息如下\n");printf("====================================================================== ======\n");printf(" 编号图书名作者名出版社类别出版时间价格\n");while(p!=NULL){if(p->time==a){printf(" %3d %-12s %-8s %-14s %-2s %-4d %.2f\n", p->num,p->bname,p->wname,p->press,p->sort,p->time,p->price);flag=1;}p=p->next;}printf("====================================================================== ======\n");}}//修改图书信息void xiugai(struct book *head){int a,b;char c;struct book *p;printf("请输入要修改的图书编号:");scanf("%d",&a);p=head;while(p!=NULL){if(p->num==a)break;p=p->next;}if(p==NULL){printf("没有找到该编号的图书!\n");getchar();}else{printf("============================================================\n");printf(" ** 1-编号2-图书名3-作者名**\n");printf(" ** 4-出版社5-类别6-出版时间**\n");printf(" ** 7-价格8-修改全部0-放弃修改**\n");printf("============================================================\n");printf("请选择你要修改的信息编号:");scanf("%d",&b);getchar();switch(b){case 1:printf("请输入新编号:");scanf("%d",&p->num);printf("修改成功!\n");getchar();break;case 2:printf("请输入新图书名:");gets(p->bname);printf("修改成功!\n");break;case 3:printf("请输入新作者名:");gets(p->wname);printf("修改成功!\n");break;case 4:printf("请输入新出版社:");gets(p->press);printf("修改成功!\n");break;case 5:printf("请输入新类别:");gets(p->sort);printf("修改成功!\n");break;case 6:printf("请输入新出版时间:");scanf("%d",&p->time);printf("修改成功!\n");getchar();break;case 7:printf("请输入新价格:");scanf("%f",&p->price);printf("修改成功!\n");getchar();break;case 8:printf("请输入新图书编号:");scanf("%d",&p->num);printf("请输入新图书名:");scanf("%s",p->bname);getchar();printf("请输入新作者名:");scanf("%s",p->wname);getchar();printf("请输入新出版社:");scanf("%s",p->press);getchar();printf("请输入新类别:");scanf("%s",p->sort);getchar();printf("请输入新出版时间:");scanf("%d",&p->time);getchar();printf("请输入新价格:");scanf("%f",&p->price);getchar();printf("修改成功!\n");getchar();break;case 0:break;default :printf("您的输入有误!\n");break;}printf("是否将修改后的信息保存到文件中?(y/n)\n");scanf("%c",&c);getchar();switch(c){case 'n':break;case 'y':fprint(head);printf("保存成功!\n");getchar();break;}}}//图书排序void paixu(struct book *head){int a;printf("================================================================\n");printf(" ** 1-按图书编号排序2-按出版时间排序**\n");printf(" ** 3-按图书价格排序4-按图书名排序**\n");printf(" ** 5-按作者名排序0-取消排序操作**\n");printf("================================================================\n");printf("请输入您选择的编号:");scanf("%d",&a);getchar();switch(a){case 0:break;case 1:num_paixu(head);break;case 2:time_paixu(head);break;case 3:price_paixu(head);break;case 4:bname_paixu(head);break;case 5:wname_paixu(head);break;default:printf("您的输入有误!\n");break;}}//按图书编号排序void num_paixu(struct book *head){struct book *a[1000],*p,*p1,*temp;int i,k,index,n=0;char b;p1=head;for(p=head;p;p=p->next)n++;for(i=0;i<n;i++){a[i]=p1;p1=p1->next;}for(k=0;k<n-1;k++){index=k;for(i=k+1;i<n;i++){if(a[i]->num<a[index]->num)index=i;}temp=a[index];a[index]=a[k];a[k]=temp;}printf("排序成功!\n");printf("是否显示排序结果?(y/n)\n");scanf("%s",&b);getchar();switch(b){case 'n':break;case 'y':printf("====================================================================== ======\n");printf(" 编号图书名作者名出版社类别出版时间价格\n");for(i=0;i<n;i++){printf(" %3d %-12s %-8s %-14s %-2s %-4d %.2f\n",a[i]->n um,a[i]->bname,a[i]->wname,a[i]->press,a[i]->sort,a[i]->time,a[i]->price);}printf("====================================================================== ======\n");break;default:printf("您的输入有误!\n");break;}}//按出版时间排序void time_paixu(struct book *head){struct book *a[1000],*p,*p1,*temp;int i,k,index,n=0;char b;p1=head;for(p=head;p;p=p->next)n++;for(i=0;i<n;i++){a[i]=p1;p1=p1->next;}for(k=0;k<n-1;k++){index=k;for(i=k+1;i<n;i++){if(a[i]->time<a[index]->time)index=i;}temp=a[index];a[index]=a[k];a[k]=temp;}printf("排序成功!\n");printf("是否显示排序结果?(y/n)\n");scanf("%s",&b);getchar();switch(b){case 'n':break;case 'y':printf("====================================================================== ======\n");printf(" 编号图书名作者名出版社类别出版时间价格\n");for(i=0;i<n;i++){printf(" %3d %-12s %-8s %-14s %-2s %-4d %.2f\n",a[i]->n um,a[i]->bname,a[i]->wname,a[i]->press,a[i]->sort,a[i]->time,a[i]->price);}printf("====================================================================== ======\n");break;default:printf("您的输入有误!\n");break;}}//按图书价格排序void price_paixu(struct book *head){struct book *a[1000],*p,*p1,*temp;int i,k,index,n=0;char b;p1=head;for(p=head;p;p=p->next)n++;for(i=0;i<n;i++){a[i]=p1;p1=p1->next;}for(k=0;k<n-1;k++){index=k;for(i=k+1;i<n;i++){if(a[i]->price<a[index]->price)index=i;}temp=a[index];a[index]=a[k];a[k]=temp;}printf("排序成功!\n");printf("是否显示排序结果?(y/n)\n");scanf("%s",&b);getchar();switch(b){case 'n':break;case 'y':printf("====================================================================== ======\n");printf(" 编号图书名作者名出版社类别出版时间价格\n");for(i=0;i<n;i++){printf(" %3d %-12s %-8s %-14s %-2s %-4d %.2f\n",a[i]->n um,a[i]->bname,a[i]->wname,a[i]->press,a[i]->sort,a[i]->time,a[i]->price);}printf("====================================================================== ======\n");break;default:printf("您的输入有误!\n");break;}}//按图书名排序void bname_paixu(struct book *head){struct book *a[1000],*p,*p1,*temp;int i,k,index,n=0;char b;p1=head;for(p=head;p;p=p->next)n++;for(i=0;i<n;i++){a[i]=p1;p1=p1->next;}for(k=0;k<n-1;k++){index=k;for(i=k+1;i<n;i++){if(strcmp(a[index]->bname,a[i]->bname)>0)index=i;}temp=a[index];a[index]=a[k];a[k]=temp;}printf("排序成功!\n");printf("是否显示排序结果?(y/n)\n");scanf("%s",&b);getchar();switch(b){case 'n':break;case 'y':printf("====================================================================== ======\n");printf(" 编号图书名作者名出版社类别出版时间价格\n");for(i=0;i<n;i++){printf(" %3d %-12s %-8s %-14s %-2s %-4d %.2f\n",a[i]->n um,a[i]->bname,a[i]->wname,a[i]->press,a[i]->sort,a[i]->time,a[i]->price);}printf("====================================================================== ======\n");break;default:printf("您的输入有误!\n");break;}}//按作者名排序void wname_paixu(struct book *head){struct book *a[1000],*p,*p1,*temp;int i,k,index,n=0;char b;p1=head;for(p=head;p;p=p->next)n++;for(i=0;i<n;i++){a[i]=p1;p1=p1->next;}for(k=0;k<n-1;k++){index=k;for(i=k+1;i<n;i++){if(strcmp(a[index]->wname,a[i]->wname)>0)index=i;}temp=a[index];a[index]=a[k];a[k]=temp;}printf("排序成功!\n");printf("是否显示排序结果?(y/n)\n");scanf("%s",&b);getchar();switch(b){case 'n':break;case 'y':printf("====================================================================== ======\n");printf(" 编号图书名作者名出版社类别出版时间价格\n");for(i=0;i<n;i++){printf(" %3d %-12s %-8s %-14s %-2s %-4d %.2f\n",a[i]->n um,a[i]->bname,a[i]->wname,a[i]->press,a[i]->sort,a[i]->time,a[i]->price);}printf("====================================================================== ======\n");break;default:printf("您的输入有误!\n");break;}}。

图书管理系统代码

图书管理系统代码

图书管理系统代码//***********************//图书馆管理系统//***********************#include<stdio.h>#include<string.h>#include<malloc.h>#define null 0#define max 65536static int n;//*********************// 图书结构体//*********************typedef struct{char num[10]; //书号char name[9]; //书名char addr[31]; //作者int Nowcounter; //现存量int Allcounter; //总库存量}datatype;datatype *x[max]; //定义两个指针数组datatype *p;//*****************************//图书功能函数列表//*****************************void redo(); //主递归函数void creatlist(datatype *x[]); //图书建立函数int menu_select(); //功能菜单函数void find(datatype *x[],int n); //查找函数void delnode(datatype *x[]); //插入函数void printlist(datatype *x[]); //显示函数void jieyue(datatype *x[],int n); //借阅函数void guihuan(datatype *x[],int n); //归还函数//*****************************//主递归函数程序//*****************************void redo(){int i=0,j,n1,k=0,flage;for( ; ;){switch( menu_select()){case 1: //选项1的实现printf("***********************\n");printf("* 图书的建立*\n");printf("***********************\n");creatlist(x);break;case 2: //选项2的实现printf("***********************\n");printf("* 新图书信息的添加*\n");printf("***********************\n");printf(" 插入的个数:");scanf("%d",&n1); //输入插入新图书的个数for(i=0;i<n1;i++){flage=0;p=(datatype *)malloc(sizeof(datatype)); //分配一个节点空间printf(" 书名: ");scanf("%s",p->name); //输入插入书的书名if(flage==0){for(j=0;j<n;j++){if(strcmp(x[j]->name,p->name) == 0 )//调用比较函数查看书名是否已知{x[j]->Allcounter++;x[j]->Nowcounter++;flage=1;}}if(flage==0){n++;printf(" 第%d 个图书数据:\n",n); //插入新的图书p=(datatype *)malloc(sizeof(datatype));x[n-1]=p;printf(" 书名:");scanf("%s",x[n-1]->name); //输入书名printf(" 编号:");scanf(" %s",x[n-1]->num); //输入书号printf(" 作者:");scanf(" %s",x[n-1]->addr); // 输入作者名printf(" 总库存量:");scanf("%d",&x[n-1]->Allcounter); //输入总库存量x[n-1]->Nowcounter=x[n-1]->Allcounter;}}}break;case 3:printf("***********************\n");printf("* 图书信息的查询*\n");printf("***********************\n");find(x,n);break;case 4:printf("************************\n");printf("* 图书信息的删除*\n");printf("************************\n");delnode(x);break;case 5:printf("************************\n");printf("* 图书信息的显示*\n");printf("************************\n");printlist(x);break;case 6:printf("************************\n");printf(" 图书的借阅\n");printf("************************\n");jieyue(x,n);break;case 7:printf("************************\n");printf(" 图书的归还\n");printf("************************\n");guihuan(x,n);break;case 0:printf("\t 谢谢使用,再见! \n");return;}}//*************************//主函数程序//*************************void main (){redo(); //调用主递归函数}//*************************//功能菜单函数//*************************int menu_select(){int i;printf(" 欢迎进入图书管理系统!\n");printf("===========================\n");printf(" 1. 图书信息的采集\n");printf(" 2. 新图书的插入\n");printf(" 3. 图书信息的查询\n");printf(" 4. 图书的删除\n");printf(" 5. 图书的显示\n");printf(" 6. 图书的借阅\n");printf(" 7. 图书的归还\n");printf(" 0. 退出管理系统\n");printf("===========================\n");printf(" 请选择0-7: ");scanf("%d",&i);while(i<0||i>7){printf("\n\t输入出错,重选0-7: ");scanf("%d",&i);}return i;}//********************************// 建立链表图书建造函数//********************************void creatlist(datatype *x[]){int i;printf(" 请输入要建立图书的个数:");scanf("%d",&n);for(i=0;i<n;i++)printf(" 第%d 个图书数据:\n",i+1);p=(datatype *)malloc(sizeof(datatype)); //分配一个节点空间x[i]=p;printf(" 书名:"); //输入图书各项内容scanf("%s",x[i]->name);printf(" 编号:");scanf(" %s",x[i]->num);printf(" 作者:");scanf(" %s",x[i]->addr);printf(" 总库存量:");scanf("%d",&x[i]->Allcounter);x[i]->Nowcounter=x[i]->Allcounter;}}//**********************************// 查找函数程序//*********************************void find(datatype *x[],int n){char num[10];char name[9];int t,i;printf("=================\n"); //输出查找方式printf(" 1.按编号查询\n");printf(" 2.按书名查询\n");printf("=================\n");printf(" 请选择: ");scanf("%d",&t); //输入选择信息if(t==1){printf(" 请输入要查找者的编号: ");scanf("%s",num); //输入书号for(i=0;i<n;i++){if(strcmp(x[i]->num,num)==0) //调用strcmp函数{printf(" 编号书名作者现库存量总库存量\n");//输出要查询书的信息printf(" %-10s%-10s%-10s%-10d%-10d\n",x[i]->num,x[i]->name,x[i]->addr,x[i]->Nowcounter,x[i]->Allcounter);elsecontinue;}}else{printf(" 请输入要查询的书名: ");scanf("%s",name); // 输入书名for(i=0;i<n;i++){if(strcmp(x[i]->name,name)==0){printf("编号书名作者现库存量总库存量\n"); //输出要查询书的信息printf(" %-10s%-10s%-10s%-10d%-10d\n",x[i]->num,x[i]->name,x[i]->addr,x[i ]->Nowcounter,x[i]->Allcounter);}elsecontinue;}}}//******************************//删除函数程序//******************************void delnode(datatype *x[]){char num1[10],name1[10]; //定义两个字符数组int i,j,m=1,p;printf(" 1.按编号删除\n"); //输出选择方式printf(" 2.按书名删除\n");printf(" 3.返回\n");printf(" 请选择:\n");scanf("%d",&p); //输入选择信息if(p>3||p<1){printf(" 您的输入有误,请重新输入!\n");scanf("%d",&p); //重新输入选择信息}switch(p) //实现删除程序{case 1:printf(" 输入要删除书的编号:\n");scanf(" %s",num1);for(i=0;i<n;i++){if(strcmp(x[i]->num,num1)==0) //调用strcmp函数{m=0;n--;for(j=i;j<n;j++)x[j]=x[j+1]; //将该书信息删除printf(" 该书已删除!\n");}}if(m==1)printf(" 没有这样的的图书\n");break;case 2:printf(" 输入要删除书的名字:\n");scanf("%s",&name1);for(i=0;i<n;i++){if(strcmp(x[i]->name,name1)==0) //调用strcmp函数{m=0;n--;for(j=i;j<n;j++) //将该书信息删除x[j]=x[j+1];printf(" 该书已删除!\n");}}if(m==1)printf(" 没有这样的的图书\n");break;case 3:break;}}//////////////////////////////借阅函数程序/////////////////////////void jieyue(datatype *x[],int n){int i,m=1,p;char name1[10],num1[10]; //定义两个字符数组printf(" 1.按名字借阅\n"); //输出选择方式printf(" 2.按编号借阅\n");printf(" 3.返回\n");printf(" 请选择\n");scanf("%d",&p); //输入选择信息if(p>3||p<1){printf(" 您的输入有误!\n");scanf("%d",&p); //重新输入选择信息}switch(p) //实现查询程序{case 1:printf(" 请输入你要的书的名字!\n");scanf("%s",&name1); // 输入书名for(i=0;i<n;i++){if(strcmp(x[i]->name,name1)==0) //调用strcmp函数{m=0;if(x[i]->Nowcounter!=0)x[i]->Nowcounter--;printf(" 借书成功!\n");if(x[i]->Nowcounter==0)printf(" 这本书已经没有了\n");}}if(m==1)printf(" 您要的书不存在!\n");break;case 2:printf(" 请输入你要的书的编号!\n");scanf("%s",&num1); // 输入书号for(i=0;i<n;i++){if(strcmp(x[i]->num,num1)==0) //调用strcmp函数{m=0;if(x[i]->Nowcounter!=0)x[i]->Nowcounter--; //现存书数量减1printf(" 借书成功!\n");if(x[i]->Nowcounter==0)printf(" 这本书已经没有了\n");}}if(m==1)printf(" 您要的书不存在!\n");break;case 3:break;}}////////////////////////////归还程序//////////////////////void guihuan(datatype *x[],int n){int i,q,m=1;char name1[10],num1[10]; //定义两个字符数组printf(" 1.按书名归还\n"); //输出可选择方式printf(" 2.按书号归还\n");printf(" 3.返回\n");printf(" 请选择\n");scanf("%d",&q); //输入选择信息if(q>3||q<1){printf(" 您的输入有误!\n");scanf("%d",&q); //重新输入选择信息}switch(q) //实现归还程序{case 1:printf(" 输入归还书的书名: ");scanf("%s",&name1); // 输入书名for(i=0;i<n;i++){if(strcmp(x[i]->name,name1)==0){m=0;x[i]->Nowcounter++;printf("此书归还成功!\n");printf("此书的存储情况\n");printf("编号书名作者现存量总存量\n"); printf("===============================================\n");printf(" %-10s%-10s%-10s%-10d%-10d\n",x[i]->num,x[i]->name,x[i]->addr,x[i]->Nowcounter,x[i]->Allcounter);printf("===============================================\n");}if(strcmp(x[i]->name,name1)==0)continue;}if(m==1)printf("此书不是图书馆的!\n");break;case 2:printf("输入归还书的书号\n");scanf("%s",&num1); // 输入书号for(i=0;i<n;i++){if(strcmp(x[i]->num,num1)==0){m=0;x[i]->Nowcounter++; //显存书增加1printf("此书归还成功!\n");printf("此书的存储情况\n");printf("编号书名作者现存量总存量\n"); printf("==============================================\n");printf(" %-10s%-10s%-10s%-10d%-10d\n",x[i]->num,x[i]->name,x[i]->addr,x[i]->Nowcounter,x[i]->Allcounter);printf("==============================================\n");}if(strcmp(x[i]->num,num1)==0) //调用strcmp 函数continue;}if(m==1)printf("此书不是图书馆的!\n");break;case 3:break;}}//**************************************// 输出程序//**************************************void printlist(datatype *x[]){int i;printf("编号书名作者现存量总存量\n");//输出图书各项信息for(i=0;i<n;i++){printf(" %-10s%-10s%-10s%-10d%-10d\n",x[i]->num,x[i]->name,x[i]->addr,x[i ]->Nowcounter,x[i]->Allcounter);}printf("===============================================\n");}。

C语言图书管理系统源代码

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. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

源程序1.主窗体Private Sub add_back_Click() frmbackbookinfo.ShowEnd SubPrivate Sub add_binf_Click() frmaddbookinfo.ShowEnd SubPrivate Sub add_book_style_Click() frmaddbookstyle.ShowEnd SubPrivate Sub add_manager_Click() frmadduser.ShowEnd SubPrivate Sub add_rinf_Click() frmaddreaderinfo.ShowEnd SubPrivate Sub add_rstyle_Click() frmaddreaderstyle.ShowEnd SubPrivate Sub change_binf_Click() frmmodifybookinfo.ShowEnd SubPrivate Sub change_book_style_Click() frmmodifybookstyle.ShowEnd SubPrivate Sub delete_binf_Click() frmmodifybookinfo.ShowEnd SubPrivate Sub delete_book_style_Click() frmmodifybookstyle.ShowEnd SubPrivate Sub delete_rstyle_Click() frmmodifyreaderstyle.ShowEnd SubPrivate Sub exit_Click()EndEnd SubPrivate Sub find_binf_Click() frmfindbook.ShowEnd SubPrivate Sub find_lend_Click() frmfindborrowinfo.ShowEnd SubPrivate Sub find_rinf_Click()frmfindreader.ShowEnd SubPrivate Sub password_Click()frmchangepwd.ShowEnd Sub2.LoginOption ExplicitPrivate Sub cmdOK_Click()Dim strUserName As StringDim strPassword As StringDim strTargetAsp As StringDim conn As ADODB.ConnectionDim rsLogin As ADODB.RecordsetDim strSQL As StringIf Trim(txtUserName.Text) = "" ThenMsgBox "“用户名”不能为空!"Exit SubElsestrUserName = Trim(txtUserName.Text)End IfIf Trim(txtPassword.Text) = "" ThenMsgBox "“口令”不能为空!"Exit SubElsestrPassword = Trim(txtPassword.Text)End If'检查口令、用户身份Set conn = New ADODB.Connectionconn.Provider = "Microsoft.jet.OLEDB.4.0"conn.ConnectionString = "D:\图书管理系统\book.mdb"conn.OpenstrUserName = Replace(strUserName, "'", "“")strSQL = "select*from 系统管理where 用户名='" & strUserName & "'and 密码='" & strPassword & "'"Set rsLogin = conn.Execute(strSQL)If rsLogin.EOF Or rsLogin.BOF ThenMsgBox "用户名或口令错误,请检查!"txtPassword.SelStart = 0txtPassword.SelLength = Len(txtPassword.Text)txtPassword.SetFocusElseSelect Case rsLogin("权限")Case "领导"strTargetAsp = "LeadersMain.asp"Case "主任"strTargetAsp = "ZhuRenMain.asp"Case "秘书"strTargetAsp = "MishuMain.asp"Case "图书管理员"strTargetAsp = "TuShuManagerMain.asp"Case ElsestrTargetAsp = "OtherMain.asp"End SelectSaveSetting "JGYOA", "Login", "UserName", strUserNameHyperlink.NavigateTo "HTTP://" & "/oa/" & strTargetAspEnd If'释放变量Set rsLogin = NothingSet conn = NothingEnd Sub3.frmaddbookinfoPrivate Sub Command1_Click()Dim rs_addbook As New ADODB.RecordsetDim sql As StringIf Trim(Combo1.Text) = " " ThenMsgBox "请选择图书种类", vbOKOnly + vbExclamation, ""Combo1.SetFocusExit SubEnd IfIf Trim(Text1.Text) = " " ThenMsgBox "图书编号不能为空", vbOKOnly + vbExclamation, ""Text1.SetFocusExit SubEnd IfIf Trim(Text2.Text) = " " ThenMsgBox "书名不能为空", vbOKOnly + vbExclamation, ""Text2.SetFocusExit SubEnd IfIf Not IsDate(Text5.Text) ThenMsgBox "请按照yyy-mm-dd格式输入日期", vbOKOnly + vbExclamation, ""Text5.SetFocusExit SubEnd IfIf Not IsDate(Text6.Text) ThenMsgBox "请按照yyy-mm-dd格式输入日期", vbOKOnly + vbExclamation, ""Text6.SetFocusExit SubEnd Ifsql = "select * from 书籍信息where 书籍编号='" & Text1.Text & "'" rs_addbook.Open sql, conn, adOpenKeyset, adLockPessimisticIf rs_addbook.EOF Thenrs_addbook.AddNewrs_addbook.Fields(0) = Trim(Text1.Text)rs_addbook.Fields(1) = Trim(Text2.Text)rs_addbook.Fields(2) = Trim(Combo1.Text)rs_addbook.Fields(3) = Trim(Text3.Text)rs_addbook.Fields(4) = Trim(Text4.Text)rs_addbook.Fields(5) = Trim(Text5.Text)rs_addbook.Fields(6) = Trim(Text6.Text)rs_addbook.Fields(7) = "否"rs_addbook.UpdateMsgBox "添加图书信息成功!", vbOKOnly, ""rs_addbook.CloseElseMsgBox "图书编号重复!", vbOKOnly + vbExclamation, ""Text1.SetFocusText1.Text = ""rs_addbook.CloseExit SubEnd IfEnd SubPrivate Sub Command2_Click()Unload MeEnd SubPrivate Sub Form_Load()Dim rs_leibie As New ADODB.RecordsetDim sql As Stringsql = "select * from 图书类别"rs_leibie.Open sql, conn, adOpenKeyset, adLockPessimisticrs_leibie.MoveFirstDo While Not rs_leibie.EOFCombo1.AddItem rs_leibie.Fields(0)rs_leibie.MoveNextLooprs_leibie.CloseEnd Sub4.frmaddbookstylePrivate Sub Command1_Click()Dim rs_bookstyle As New ADODB.RecordsetDim sql As StringIf Trim(Text1.Text) = "" ThenMsgBox "图书种类不能为空", vbOKOnly + vbExclamation, ""Text1.SetFocusExit SubEnd IfIf Trim(Text2.Text) = "" ThenMsgBox "种类编号不能为空", vbOKOnly + vbExclamation, ""Text2.SetFocusExit SubEnd Ifsql = " select * from 图书类别where 类别名称='" & Text1.Text & "'" rs_bookstyle.Open sql, conn, adOpenKeyset, adLockOptimisticIf rs_bookstyle.EOF Thenrs_bookstyle.AddNewrs_bookstyle.Fields(0) = Trim(Text1.Text)rs_bookstyle.Fields(1) = Trim(Text2.Text)rs_bookstyle.UpdateMsgBox "添加图书类别成功!", vbOKOnly, ""rs_bookstyle.CloseElseMsgBox "读者类别重复!", vbOKOnly + vbExclamation, ""Text1.SetFocusText1.Text = " "rs_bookstyle.CloseExit SubEnd IfEnd SubPrivate Sub Command2_Click()Unload MeEnd Sub5.frmaddreaderinfoOption ExplicitDim rs_addreader As New ADODB.RecordsetPrivate Sub Command1_Click()Dim sql As StringIf Trim(Combo1.Text) = "" ThenMsgBox "请选择读者种类", vbOKOnly + vbExclamation, ""Combo1.SetFocusExit SubEnd IfIf Trim(Text2.Text) = "" ThenMsgBox "读者姓名不能为空", vbOKOnly + vbExclamation, ""Text1.SetFocusExit SubEnd IfIf Trim(Text3.Text) = "" ThenMsgBox "读者编号不能为空", vbOKOnly + vbExclamation, ""Text2.SetFocusExit SubEnd Ifsql = "select * from 读者信息where 读者编号='" & Text2.Text & "'" rs_addreader.Open sql, conn, adOpenKeyset, adLockPessimisticIf rs_addreader.EOF Thenrs_addreader.AddNewrs_addreader.Fields(0) = Trim(Text2.Text)rs_addreader.Fields(1) = Trim(Text3.Text)rs_addreader.Fields(2) = Trim(Combo2.Text)rs_addreader.Fields(3) = Trim(Combo1.Text)rs_addreader.Fields(4) = Trim(Text5.Text)rs_addreader.Fields(5) = Trim(Text6.Text)rs_addreader.Fields(6) = Trim(Text4.Text)rs_addreader.Fields(7) = CDate(Text1.Text)rs_addreader.UpdateMsgBox "添加读者信息成功!", vbOKOnly, ""rs_addreader.CloseElseMsgBox "读者编号重复!", vbOKOnly + vbExclamation, ""Text1.SetFocusText1.Text = ""rs_addreader.CloseExit SubEnd IfEnd SubPrivate Sub Command2_Click()Unload MeEnd SubPrivate Sub Form_Load()Combo2.AddItem "男"Combo2.AddItem "女"Dim rs_leibie As New ADODB.RecordsetDim sql As Stringsql = "select * from 读者类别"rs_leibie.Open sql, conn, adOpenKeyset, adLockPessimisticrs_leibie.MoveFirstDo While Not rs_leibie.EOFCombo1.AddItem rs_leibie.Fields(0)rs_leibie.MoveNextLooprs_leibie.CloseEnd Sub6.frmaddreaderstyleOption ExplicitDim rs_readerstyle As New ADODB.RecordsetPrivate Sub Command1_Click()Dim sql As StringIf Trim(Text1.Text) = "" ThenMsgBox "读者种类不能为空!", vbOKOnly + vbExclamation, ""Text1.SetFocusExit SubEnd IfIf Trim(Text2.Text) = "" ThenMsgBox "借书数量不能为空!", vbOKOnly + vbExclamation, ""Text2.SetFocusExit SubEnd IfIf Trim(Text3.Text) = "" ThenMsgBox "借书期限不能为空!", vbOKOnly + vbExclamation, ""Text3.SetFocusExit SubEnd IfIf Trim(Text4.Text) = "" ThenMsgBox "有限期限不能为空!", vbOKOnly + vbExclamation, ""Text4.SetFocusExit SubEnd Ifsql = "select*from 读者类别where 种类名称='" & Text1.Text & "'" rs_readerstyle.Open sql, conn, adOpenKeyset, adLockPessimisticIf rs_readerstyle.EOF Thenrs_readerstyle.AddNewrs_readerstyle.Fields(0) = Trim(Text1.Text)rs_readerstyle.Fields(1) = Trim(Text2.Text)rs_readerstyle.Fields(2) = Trim(Text3.Text)rs_readerstyle.Fields(3) = Trim(Text4.Text)rs_readerstyle.UpdateMsgBox "添加读者类别成功!", vbOKOnly, ""rs_readerstyle.CloseElseMsgBox "读者类别重复!", vbOKOnly + vbExclamation, ""Text1.SetFocusText1.Text = ""rs_readerstyle.CloseExit SubEnd IfEnd SubPrivate Sub Command2_Click()Unload MeEnd Sub7.frmadduserPrivate Sub Command1_Click()Dim sql As StringDim rs_add As New ADODB.RecordsetIf Trim(Text1.Text) = "" ThenMsgBox "用户名不能为空", vbOKOnly + vbExclamation, ""Exit SubText1.SetFocusElsesql = "select * from 系统管理"rs_add.Open sql, conn, adOpenKeyset, adLockPessimisticWhile (rs_add.EOF = False)If Trim(rs_add.Fields(0)) = Trim(Text1.Text) ThenMsgBox "已有这个用户", vbOKOnly + vbExclamation, ""Text1.SetFocusText1.Text = ""Text2.Text = ""Text3.Text = ""Combo1.Text = ""Exit SubElsers_add.MoveNextEnd IfWendIf Trim(Text2.Text) <> Trim(Text3.Text) ThenMsgBox "两次密码不一致", vbOKOnly + vbExclamation, ""Text2.SetFocusText2.Text = ""Text3.Text = ""Exit SubElseIf Trim(Combo1.Text) <> "system" And Trim(Combo1.Text) <> "guest" Then MsgBox "请选择正确的用户权限", vbOKOnly + vbExclamation, ""Combo1.SetFocusCombo1.Text = ""Exit SubElsers_add.AddNewrs_add.Fields(0) = Text1.Textrs_add.Fields(1) = Text2.Textrs_add.Updaters_add.CloseMsgBox "添加用户成功", vbOKOnly + vbExclamation, ""Unload MeEnd IfEnd IfEnd IfEnd SubPrivate Sub Command2_Click()Unload MeEnd SubPrivate Sub Form_Load()Combo1.AddItem "system"Combo1.AddItem "guest"End Sub8.frmbackbookinfoPrivate Sub Combo1_Click()Combo2.ListIndex = Combo1.ListIndexEnd SubPrivate Sub Combo2_Click()Combo1.ListIndex = Combo2.ListIndexEnd SubPrivate Sub Combo3_Click()Combo4.ListIndex = Combo3.ListIndexEnd SubPrivate Sub Combo4_Click()Combo3.ListIndex = Combo4.ListIndexEnd SubPrivate Sub Command1_Click()Dim book_num As StringDim reader_num As StringDim answer As StringDim rs_back As New ADODB.RecordsetDim sql As StringOn Error GoTo delerrorbook_num = DataGrid1.Columns(3).CellV alue(DataGrid1.Bookmark) reader_num = DataGrid1.Columns(1).CellV alue(DataGrid1.Bookmark) answer = MsgBox("确定要还这本书吗?", vbY esNo, "")If answer = vbY es Thensql = "select * from 借阅信息where 书籍编号='" & book_num & "'"rs_back.CursorLocation = adUseClientrs_back.Open sql, conn, adOpenKeyset, adLockPessimisticrs_back.Deleters_back.Updaters_back.Closesql = "select * from 书籍信息where 书籍编号='" & book_num & "'"rs_back.CursorLocation = adUseClientrs_back.Open sql, conn, adOpenKeyset, adLockPessimisticrs_back.Fields(7) = "否"rs_back.Updaters_back.Closesql = "select * from 读者信息where 读者编号='" & reader_num & "'"rs_back.CursorLocation = adUseClientrs_back.Open sql, conn, adOpenKeyset, adLockPessimisticrs_back.Fields(8) = rs_back.Fields(8) - 1rs_back.Updaters_back.CloseIf findform = True ThenCommand1_ClickElseCommand2_ClickEnd IfMsgBox "成功删除!", vbOKOnly + vbExclamation, ""DataGrid1.AllowDelete = FalseElseExit SubEnd Ifdelerror:If Err.Number <> 0 ThenMsgBox Err.DescriptionEnd IfEnd SubPrivate Sub Command2_Click()Unload MeEnd SubPrivate Sub Command3_Click()Dim rs_reader As New ADODB.RecordsetDim sql As Stringfindform = Turesql = "select*from 借阅信息where 读者姓名='" & Combo2.Text & "'" rs_reader.CursorLocation = adUseClientrs_reader.Open sql, conn, adOpenKeyset, adLockPessimisticSet DataGrid1.DataSource = rs_readerDataGrid1.AllowAddNew = FalseDataGrid1.AllowDelete = FalseDataGrid1.AllowUpdate = FalseEnd SubPrivate Sub Command4_Click()Dim rs_book As New ADODB.RecordsetDim sql As Stringfindform = Falsesql = "select * from 借阅信息where 书籍编号='" & Combo3.Text & "'" rs_book.CursorLocation = adUseClientrs_book.Open sql, conn, adOpenKeyset, adLockPessimisticSet DataGrid1.DataSource = rs_bookDataGrid1.AllowAddNew = FalseDataGrid1.AllowDelete = FalseDataGrid1.AllowUpdate = FalseEnd SubPrivate Sub Form_Load()Dim rs_reader As New ADODB.RecordsetDim rs_book As New ADODB.RecordsetDim sql As Stringsql = "select * from 读者信息"rs_reader.CursorLocation = adUseClientrs_reader.Open sql, conn, adOpenKeyset, adLockPessimisticIf Not rs_reader.EOF ThenDo While Not rs_reader.EOFCombo1.AddItem rs_reader.Fields(1)Combo2.AddItem rs_reader.Fields(0)rs_reader.MoveNextLoopEnd Ifrs_reader.Closesql = "select * from 借阅信息"rs_book.CursorLocation = adUseClientrs_book.Open sql, conn, adOpenKeyset, adLockPessimisticIf Not rs_book.EOF ThenDo While Not rs_book.EOFCombo3.AddItem rs_book.Fields(3)Combo4.AddItem rs_book.Fields(4)rs_book.MoveNextLoopEnd Ifrs_book.CloseEnd Sub9.frmborrowbookOption ExplicitDim leibie As StringDim qixian As IntegerDim shumu As IntegerDim maxnum As IntegerPrivate Sub Combo1_Change()Combo2.ListIndex = Combo1.ListIndexEnd SubPrivate Sub Combo2_Change()Combo1.ListIndex = Combo2.ListIndexEnd SubPrivate Sub Command1_Click()Dim rs_borrowbook As New ADODB.RecordsetDim sql As Stringsql = "select * from读者信息where读者编号='" & Combo1.Text & "" rs_borrowbook.Open sql, conn.adOpenKeyset, adLockPessimisticleibie = rs_borrowbook.Fields(3)shumu = rs_borrowbook.Fields(8)rs_borrowbook.Closesql = "select * from读者类别where种类名称='" & leibie & ""rs_borrowbook.Open sql, conn.adOpenKeyset, adLockPessimistic qixian = rs_borrowbook.Fields(2)maxnum = rs_borrowbook.Fields(1)rs_borrowbook.CloseIf shumu >= maxnum ThenMsgBox "该读者借书数额已满!", vbOKOnly + vbExclamation Exit SubEnd Ifsql = "select * from借阅信息"rs_borrowbook.Open sql, conn.adOpenKeyset, adLockPessimisticrs_borrowbook.AddNewrs_borrowbook.Fields(1) = Combo1.Textrs_borrowbook.Fields(2) = Combo2.Textrs_borrowbook.Fields(3) = Label8.Captionrs_borrowbook.Fields(4) = Label9.Captionrs_borrowbook.Fields(5) = Daters_borrowbook.Fields(6) = DateAdd("Ww", qixian, Date)rs_borrowbook.Updaters_borrowbook.Closesql = "select * from书籍信息where书籍编号='" & book_num & ""rs_borrowbook.Open sql, conn.adOpenKeyset, adLockPessimisticrs_borrowbook.Fields(7) = "是"rs_borrowbook.Updaters_borrowbook.Closesql = "select * from读者信息where读者编号='" & Combo1.Text & "" rs_borrowbook.Open sql, conn.adOpenKeyset, adLockPessimisticrs_borrowbook.Fields(8) = rs_borrowbook.Fields(8) + 1rs_borrowbook.Updaters_borrowbook.CloseMsgBox "本书借阅成功!", vbOKOnly + vbExclamationUnload MeEnd SubPrivate Sub Command2_Click()Unload MeEnd SubPrivate Sub Form_Load()Dim rs_borrow As New ADODB.RecordsetDim rs_reader As New ADODB.RecordsetDim sql As Stringsql = "select * from 书籍信息where 书籍编号= '" & book_num & "'" rs_borrow.Open sql, conn, adOpenKeyset, adLockPessimisticLabel8.Caption = rs_borrow.Fields(0)Label9.Caption = rs_borrow.Fields(1)Label10.Caption = rs_borrow.Fields(2)Label11.Caption = rs_borrow.Fields(3)Label12.Caption = rs_borrow.Fields(4)Label13.Caption = rs_borrow.Fields(5)Label14.Caption = rs_borrow.Fields(6)sql = "select * from 读者信息"rs_reader.Open sql, conn, adOpenKeyset, adLockPessimisticIf Not rs_reader.EOF ThenDo While Not rs_reader.EOFCombo1.AddItem rs_reader.Fields(1)Combo2.AddItem rs_reader.Fields(0)rs_reader.MoveNextLoopElseMsgBox "请先登记读者", vbOKOnly + vbExclamationExit SubEnd Ifrs_borrow.Closers_reader.CloseEnd Sub10.frmchangepwdPrivate Sub Command1_Click()Dim rs_chang As New ADODB.RecordsetDim sql As StringIf Trim(Text1.Text) <> Trim(Text2.Text) ThenMsgBox "密码不一致", vbOKOnly + vbExclamation, ""Text2.SetFocusText1.Text = ""Text2.Text = ""Elsesql = "select*from 系统管理where 用户名='" & userID & "'"rs_chang.Open sql, conn, adOpenKeyset, adLockPessimisticrs_chang.Fields(1) = Text1.Textrs_chang.Updaters_chang.CloseMsgBox "密码修改成功", vbOKOnly + vbExclamation, ""Unload MeEnd IfEnd SubPrivate Sub Command2_Click()Unload MeEnd Sub11.frmfindbookOption ExplicitDim panduan As StringPrivate Sub Command1_Click()Dim rs_findbook As New ADODB.RecordsetDim sql As StringIf Check1.V alue = vbChecked Thensql = "书名='" & Trim(Text1.Text & "") & "'"End IfIf Check2.V alue = vbChecked ThenIf Trim(sql) = "" Thensql = "类别='" & Trim(Combo1.Text & "") & "'"Elsesql = sql & "and 书名='" & Trim(Combo1.Text & "") & "'"End IfEnd IfIf Check3.V alue = vbChecked ThenIf Trim(sql) = "" Thensql = "作者='" & Trim(Text2.Text & "") & "'"Elsesql = sql & "and 作者='" & Trim(Text2.Text & "") & "'"End IfEnd IfIf Check4.V alue = vbChecked ThenIf Trim(sql) = "" Thensql = "出版社='" & Trim(Text3.Text & "") & "'"Elsesql = sql & "and 出版社='" & Trim(Text3.Text & "") & "'"End IfEnd IfIf Check5.V alue = vbChecked ThenIf Trim(sql) = "" Thensql = "书籍编号='" & Trim(Text4.Text & "") & "'"Elsesql = sql & "and 书籍编号='" & Trim(Text4.Text & "") & "'"End IfEnd IfIf Trim(sql) = "" ThenMsgBox "请选择查询方式!", vbOKOnly + vbExclamationExit SubEnd Ifsql = "select * from 书籍信息where " & sqlrs_findbook.CursorLocation = adUseClientrs_findbook.Open sql, conn, adOpenKeyset, adLockPessimisticDataGrid1.AllowAddNew = FalseDataGrid1.AllowDelete = FalseDataGrid1.AllowUpdate = FalseSet DataGrid1.DataSource = rs_findbookEnd SubPrivate Sub Command2_Click()Unload MeEnd SubPrivate Sub Command3_Click()If Trim(book_num) = "" ThenMsgBox "请选择要借阅的图书!", vbOKOnly + vbExclamationExit SubEnd IfIf panduan = "是" ThenMsgBox "此书已被借出!", vbOKOnly + vbExclamationExit SubEnd Iffrmborrowbook.ShowEnd SubPrivate Sub DataGrid1_RowColChange(LastRow As V ariant, ByV al LastCol As Integer) book_num = DataGrid1.Columns(0).CellV alue(DataGrid1.Bookmark)panduan = DataGrid1.Columns(7).CellV alue(DataGrid1.Bookmark)End SubPrivate Sub Form_Load()Dim rs_find As New ADODB.RecordsetDim sql As Stringsql = "select * from 图书类别"rs_find.Open sql, conn, adOpenKeyset, adLockPessimisticrs_find.MoveFirstIf Not rs_find.EOF ThenDo While Not rs_find.EOFCombo1.AddItem rs_find.Fields(0)rs_find.MoveNextLoopCombo1.ListIndex = 0End Ifrs_find.CloseEnd Sub12.frmfindborrowinfoPrivate Sub Command1_Click()Dim sql As StringDim rs_find As New ADODB.RecordsetIf Option1.V alue = True Thensql = "select * from 书籍信息where 是否被借出='是'"End IfIf Option2.V alue = True Thensql = "select * from 书籍信息where 是否被借出='否'"End IfIf Option3.V alue = True Thensql = "select * from 书籍信息where 读者姓名='" & Text1.Text & "'" End Ifrs_find.CursorLocation = adUseClientrs_find.Open sql, conn, adOpenKeyset, adLockPessimisticDataGrid1.AllowAddNew = FalseDataGrid1.AllowDelete = FalseDataGrid1.AllowUpdate = FalseSet DataGrid1.DataSource = rs_findEnd SubPrivate Sub Command2_Click()Unload MeEnd Sub13.frmfindreaderOption ExplicitPrivate Sub Command1_Click()Dim rs_findreader As New ADODB.RecordsetDim sql As StringIf Check1.V alue = vbChecked Thensql = "读者编号='" & Trim(Text1.Text & "") & "'"End IfIf Check2.V alue = vbChecked ThenIf Trim(sql) = "" Thensql = "读者姓名='" & Trim(Text2.Text & "") & "'"Elsesql = sql & "and读者姓名='" & Trim(Text2.Text & "") & "'" End IfEnd IfIf Check3.V alue = vbChecked ThenIf Trim(sql) = "" Thensql = "读者类别='" & Trim(Combo1.Text & "") & "'"Elsesql = sql & "and读者类别='" & Trim(Combo1.Text & "") & "'" End IfEnd Ifsql = "select * from 读者信息where " & sqlrs_findreader.CursorLocation = adUseClientrs_findreader.Open sql, conn, adOpenKeyset, adLockPessimistic DataGrid1.AllowAddNew = FalseDataGrid1.AllowDelete = FalseDataGrid1.AllowUpdate = FalseSet DataGrid1.DataSource = rs_findreader'rs_findreader.CloseEnd SubPrivate Sub Command2_Click()Unload MeEnd SubPrivate Sub Form_Load()Dim rs_find As New ADODB.RecordsetDim sql As Stringsql = "select * from 读者类别"rs_find.Open sql, conn, adOpenKeyset, adLockPessimisticIf Not rs_find.EOF ThenDo While Not rs_find.EOFCombo1.AddItem rs_find.Fields(0)rs_find.MoveNextLoopCombo1.ListIndex = 0End Ifrs_find.CloseEnd Sub14.frmmodifybookinfoOption ExplicitDim rs_book As New ADODB.RecordsetPrivate Sub cmdcancel_Click()rs_book.CancelUpdateDataGrid1.AllowAddNew = FalseDataGrid1.AllowUpdate = Falsecmdmodify.Enabled = Truecmddel.Enabled = Falsecmdcancel.Enabled = Falsecmdupdate.Enabled = FalseEnd SubPrivate Sub cmddel_Click()Dim answer As StringOn Error GoTo delerroranswer = MsgBox("确定要删除吗?", vbY esNo, "")If answer = vbY es ThenDataGrid1.AllowDelete = Truers_book.Deleters_book.UpdateDataGrid1.RefreshMsgBox "成功删除!", vbOKOnly + vbExclamation, "" DataGrid1.AllowDelete = FalseElseExit SubEnd Ifdelerror:If Err.Number <> 0 ThenMsgBox Err.DescriptionEnd IfEnd SubPrivate Sub cmdmodify_Click()Dim answer As StringOn Error GoTo cmdmodifycmddel.Enabled = Falsecmdmodify.Enabled = Falsecmdupdate.Enabled = Truecmdcancel.Enabled = TrueDataGrid1.AllowUpdate = Truecmdmodify:If Err.Number <> 0 ThenMsgBox Err.DescriptionEnd IfEnd SubPrivate Sub cmdupdate_Click()If Not IsNull(DataGrid1.Bookmark) Thenrs_book.UpdateEnd Ifcmdmodify.Enabled = Truecmddel.Enabled = Truecmdcancel.Enabled = Falsecmdupdate.Enabled = FalseDataGrid1.AllowUpdate = FalseMsgBox "修改成功!", vbOKOnly + vbExclamation, "" End SubPrivate Sub Form_Load()Dim sql As StringOn Error GoTo loaderrorsql = "select * from 书籍信息"rs_book.CursorLocation = adUseClientrs_book.Open sql, conn, adOpenKeyset, adLockPessimistic cmdupdate.Enabled = FalseDataGrid1.AllowAddNew = FalseDataGrid1.AllowDelete = FalseDataGrid1.AllowUpdate = FalseIf userpow = "guest" ThenFrame2.Enabled = FalseEnd IfSet DataGrid1.DataSource = rs_bookExit Subloaderror:MsgBox Err.DescriptionEnd SubPrivate Sub Form_Unload(Cancel As Integer)Set DataGrid1.DataSource = Nothingrs_book.CloseEnd Sub15.frmmodifybookstyleOption ExplicitDim rs_reader As New ADODB.RecordsetPrivate Sub cmdcancel_Click()rs_reader.CancelUpdateDataGrid1.AllowAddNew = FalseDataGrid1.AllowUpdate = Falsecmdmodify.Enabled = Truecmddel.Enabled = Truecmdcancel.Enabled = Falsecmdupdate.Enabled = FalseEnd SubPrivate Sub cmddel_Click()Dim answer As StringOn Error GoTo delerroranswer = MsgBox("确定要删除吗?", vbY esNo, "")If answer = vbY es ThenDataGrid1.AllowDelete = Truers_reader.Deleters_reader.UpdateDataGrid1.RefreshMsgBox "成功删除!", vbOKOnly + vbExclamation, ""DataGrid1.AllowDelete = FalseElseExit SubEnd Ifdelerror:If Err.Number <> 0 ThenMsgBox Err.DescriptionEnd IfEnd SubPrivate Sub cmdmodify_Click()Dim answer As StringOn Error GoTo cmdmodifycmddel.Enabled = Falsecmdmodify.Enabled = Falsecmdupdate.Enabled = Truecmdcancel.Enabled = TrueDataGrid1.AllowUpdate = Truecmdmodify:If Err.Number <> 0 ThenMsgBox Err.DescriptionEnd IfEnd SubPrivate Sub cmdupdate_Click()If Not IsNull(DataGrid1.Bookmark) Thenrs_reader.UpdateEnd Ifcmdmodify.Enabled = Truecmddel.Enabled = Truecmdcancel.Enabled = Falsecmdupdate.Enabled = FalseDataGrid1.AllowUpdate = FalseMsgBox "修改成功!", vbOKOnly + vbExclamation, ""End SubPrivate Sub Form_Load()Dim sql As StringOn Error GoTo loaderrorsql = "select * from 图书类别"rs_reader.CursorLocation = adUseClientrs_reader.Open sql, conn, adOpenKeyset, adLockPessimisticcmdupdate.Enabled = False '窗体刚刚加载时,"取消"按钮应设置为不可用,即将其Enabled属性设为False'设定DataGrid控件属性DataGrid1.AllowAddNew = FalseDataGrid1.AllowDelete = FalseDataGrid1.AllowUpdate = FalseIf userpow = "guest" ThenFrame2.Enabled = FalseEnd If'添加错误处理语句Set DataGrid1.DataSource = rs_reader '使用DataGrid控件来显示图书类型数据表中的数据信息Exit Subloaderror:MsgBox Err.DesctiptionEnd SubPrivate Sub Form_Unload(Cancel As Integer)Set DataGrid1.DataSource = Nothingrs_reader.CloseEnd Sub16.frmmodifyreaderstyleOption ExplicitDim rs_reader As New ADODB.RecordsetPrivate Sub cmdcancel_Click()rs_reader.CancelUpdateDataGrid1.RefreshDataGrid1.AllowAddNew = FalseDataGrid1.AllowUpdate = Falsecmdmodify.Enabled = Truecmddel.Enabled = Truecmdcancel.Enabled = Falsecmdupdate.Enabled = FalseEnd SubPrivate Sub cmddel_Click()Dim answer As StringOn Error GoTo delerroranswer = MsgBox("确定要删除吗?", vbY esNo, "")If answer = vbY es ThenDataGrid1.AllowDelete = Truers_reader.Deleters_reader.UpdateDataGrid1.RefreshMsgBox "成功删除!", vbOKOnly + vbExclamation, ""DataGrid1.AllowDelete = FalseElseExit Sub。

相关文档
最新文档