图书管理系统程序代码

合集下载

图书管理系统程序源代码

图书管理系统程序源代码

源程序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;}}}。

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

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

#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");

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

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

头函数名:#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;}}}。

图书管理系统C++代码

图书管理系统C++代码

#include <iostream>#include <iomanip>#include <string>#include <fstream>using namespace std; const int Reader=100; const int Maxb=100; const int Bor=5;class Student{private:int tag;int number;char name[10];int borbook[Bor]; public:Student() { }char *getname(){return name;}int gettag(){return tag;}int getnumber(){return number;}void setname(char *na) {strcpy(name,na);}void delbook(){tag=1;}void addStudent(int n,char *na){tag=0;number=n;strcpy(name,na);for(int i=0;i<Bor;i++)borbook[i]=0;}void borrowbook(int bookid)//借书操作{for(int i=0;i<Bor;i++){if (borbook[i]==0){borbook[i]=bookid;return;}}}int retbook(int bookid)//还书操作{for(int i=0;i<Bor;i++){if(borbook[i]==bookid){borbook[i]=0;return 1;}}return 0;}void output()//读出读者信息{cout << setw(5) << number <<setw(10) << name<<"借书编号:[";for(int i=0;i<Bor;i++)if(borbook[i]!=0)cout << borbook[i] << "|";cout << "]"<<endl;}};class RData{private:int top; //读者记录指针Student read[Reader];public:RData() //构造函数,将Student.txt读到read[]中{Student s;top=-1;fstream file("Student.txt",ios::in);//打开一个输入文件while (1){file.read((char *)&s,sizeof(s));if (!file)break;top++;read[top]=s;}file.close();}void clear(){top=-1;}int addStudent(int n,char *na)//查找是否存在{Student *p=equal(n);if (p==NULL){top++;read[top].addStudent(n,na);return 1;}return 0;}Student *equal(int Studentid)//按编号查找{for (int i=0;i<=top;i++)if (read[i].getnumber()==Studentid &&read[i].gettag()==0){return &read[i];}return NULL;}void output(){for (int i=0;i<=top;i++)read[i].output();}void Studentdata();//读者库维护~RData() //析构函数,将read[]写到Student.txt文件中{fstream file("Student.txt",ios::out);for (int i=0;i<=top;i++)if (read[i].gettag()==0)file.write((char *)&read[i],sizeof(read[i]));file.close();}};void RData::Studentdata(){char choice;char rname[20];int Studentid;Student *r;while (choice!='0'){cout<<" ┏━━━━━━━━━━━━━┓\n"; cout<<" ┃读者维护┃\n"; cout<<" ┃━━━━━━━━━━━━━┃\n"; cout<<" ┃1.新增┃\n"; cout<<" ┃━━━━━━━━━━━━━┃\n"; cout<<" ┃2.更改┃\n"; cout<<" ┃━━━━━━━━━━━━━┃\n"; cout<<" ┃3.删除┃\n"; cout<<" ┃━━━━━━━━━━━━━┃\n"; cout<<" ┃4.查找┃\n"; cout<<" ┃━━━━━━━━━━━━━┃\n"; cout<<" ┃5.显示┃\n"; cout<<" ┃━━━━━━━━━━━━━┃\n"; cout<<" ┃6.全删┃\n";cout<<" ┃━━━━━━━━━━━━━┃\n"; cout<<" ┃0.退出┃\n"; cout<<" ┗━━━━━━━━━━━━━┛\n"; //cout<<cin >> choice;switch (choice){case '1':cout << "输入读者编号:";cin >> Studentid;cout << "输入读者姓名:";cin >> rname;addStudent (Studentid,rname);break;case '2':cout << "输入读者编号:";cin >> Studentid;r=equal(Studentid);if (r==NULL){cout << " 该读者不存在"<<endl;break;}cout << "输入新的姓名:";cin >> rname;r->setname(rname);break;case '3':cout << " 输入读者编号:";cin >> Studentid;r=equal(Studentid);if (r==NULL){cout <<" 该读者不存在" << endl;break;}r->delbook();break;case '4':cout << "读入读者编号:";cin >> Studentid;r=equal(Studentid);if (r==NULL){cout <<"该读者不存在"<< endl;break;}r->output();break;case '5':output();break;case '6':clear();break;default:cout<<"退出:\n";system("cls");break; }}}class Book{private:int tag;int number;char name[20];int onshelf;public:Book(){}char *getname(){return name;}int getnumber(){return number;}int gettag(){return tag;}void setname(char na[]){strcpy(name,na);}void delbook(){tag=1;}void addbook(int n,char *na){tag=0;number=n;strcpy(name,na);onshelf=1;}int borrowbook()//借书操作{if (onshelf==1){onshelf=0;return 1;}return 0;void retbook()//还书操作{onshelf=1;}void output()//输出图书{cout << setw(6) << number << setw(18) << name << setw(10) <<(onshelf==1? "在架":"已借") <<endl;}};class BDatabase{private:int top;Book book[Maxb]; //图书记录public:BDatabase()//构造函数,将book.txt读到book[]中{Book b;top=-1;fstream file("book.txt",ios::in);while (1){file.read((char *)&b,sizeof(b));if (!file) break;top++;book[top]=b;file.close();}void clear(){top=-1;}int addbook(int n,char *na){Book *p=equal(n);if (NULL==p){top++;book[top].addbook(n,na);return 1;}return 0;}Book *equal(int bookid){for (int i=0;i<=top;i++)if (book[i].getnumber()==bookid &&book[i].gettag()==0) {return &book[i];}return NULL;}void bookdata();void output(){for (int i=0;i<=top;i++)if (book[i].gettag()==0)book[i].output();}~BDatabase()//析构函数,将book[]写到book.txt文件中{fstream file("book.txt",ios::out);for (int i=0;i<=top;i++)if (book[i].gettag()==0)file.write((char *)&book[i],sizeof(book[i]));file.close();}};void BDatabase::bookdata(){char choice;char bname[40];int bookid;Book *b;while (choice!='0'){cout<<" ┏━━━━━━━━━━━━━┓\n"; cout<<" ┃图书维护┃\n"; cout<<" ┃━━━━━━━━━━━━━┃\n"; cout<<" ┃1.新增┃\n"; cout<<" ┃━━━━━━━━━━━━━┃\n"; cout<<" ┃2.更改┃\n"; cout<<" ┃━━━━━━━━━━━━━┃\n"; cout<<" ┃3.删除┃\n"; cout<<" ┃━━━━━━━━━━━━━┃\n"; cout<<" ┃4.查找┃\n"; cout<<" ┃━━━━━━━━━━━━━┃\n"; cout<<" ┃5.显示┃\n"; cout<<" ┃━━━━━━━━━━━━━┃\n"; cout<<" ┃6.全删┃\n";cout<<" ┃━━━━━━━━━━━━━┃\n"; cout<<" ┃0.退出┃\n"; cout<<" ┗━━━━━━━━━━━━━┛\n"; cin >> choice;switch (choice){case '1':cout << "输入图书编号:"<<endl;cin >> bookid;cout << "输入图书书名:"<<endl;cin >> bname;addbook(bookid,bname);break;case '2':cout << "输入图书编号:"<<endl;cin >> bookid;b=equal(bookid);if (b==NULL){cout << " 该图书不存在"<<endl;break;}cout << "输入新的书名:"<<endl;cin >> bname;b->setname(bname);break;case '3':cout <<" 读入图书编号:"<<endl;cin >> bookid;b=equal(bookid);if (b==NULL){cout <<" 该图书不存在" << endl;break;}b->delbook();break;case '4':cout << " 读入图书编号:"<<endl;cin >> bookid;b=equal(bookid);if (b==NULL){cout <<" 该图书不存在"<< endl;break;}b->output();break;case '5':output();break;case '6':clear();break;default:cout<<"退出\n"; system("cls"); break; }}}void main(){char choice;int bookid,Studentid;RData StudentDB;Student *r;BDatabase BookDB;Book *b;while(choice!='0'){cout<<" ┏━━━━━━━━━━━━━┓\n"; cout<<" ┃图书管理系统┃\n"; cout<<" ┃━━━━━━━━━━━━━┃\n"; cout<<" ┃1.借书┃\n"; cout<<" ┃━━━━━━━━━━━━━┃\n"; cout<<" ┃2.还书┃\n"; cout<<" ┃━━━━━━━━━━━━━┃\n"; cout<<" ┃3.图书维护┃\n"; cout<<" ┃━━━━━━━━━━━━━┃\n"; cout<<" ┃4.读者维护┃\n"; cout<<" ┃━━━━━━━━━━━━━┃\n"; cout<<" ┃0.退出┃\n"; cout<<" ┗━━━━━━━━━━━━━┛\n";cin >> choice;switch (choice){case '1': system("cls");cout <<" 借书读者编号:";cin >>Studentid;cout <<" 图书编号:";cin >>bookid;r=StudentDB.equal(Studentid);//按编号查找if (NULL==r){cout <<" 不存在该读者,不能借书"<< endl;break;}b=BookDB.equal(bookid);if (b==NULL){cout <<" 不存在该图书,不能借书"<< endl;break;}if (b->borrowbook()==0){cout << " 该图书已借出,不能借书"<< endl;break;}r->borrowbook(b->getnumber());system("cls"); break;case '2':system("cls");cout<<"还书\n 读者编号:";cin >>Studentid;cout << " 图书编号:";cin >>bookid;r=StudentDB.equal(Studentid);if (r==NULL){cout <<" 不存在该读者,不能还书" << endl;break;}b=BookDB.equal(bookid);if (b==NULL){cout <<" 不存在该图书,不能还书" <<endl;break;}b->retbook();r->retbook(b->getnumber());break;case '3':system("cls");BookDB.bookdata(); break;case '4':system("cls");StudentDB.Studentdata();break;default:cout<<"退出\n";}}}。

图书馆管理系统代码

图书馆管理系统代码

图书馆管理系统代码。

txt男人偷腥时的智商仅次于爱因斯坦。

美丽让男人停下,智慧让男人留下.任何东西都不能以健康做交换.#include<stdio.h〉#include<math。

h〉#include<string。

h>#include<stdlib.h>struct books_list{char author[20]; /*作者名*/char bookname[20]; /*书名*/char publisher[20]; /*出版单位*/char pbtime[15]; /*出版时间*/char loginnum[10]; /*登陆号*/float price; /*价格*/char classfy[10]; /*分类号*/struct books_list * next; /*链表的指针域*/};struct books_list * Create_Books_Doc(); /*新建链表*/void InsertDoc(struct books_list * head); /*插入*/void DeleteDoc(struct books_list * head , int num);/*删除*/void Print_Book_Doc(struct books_list * head);/*浏览*/void search_book(struct books_list * head); /*查询*/void info_change(struct books_list * head);/*修改*/void save(struct books_list * head);/*保存数据至文件*//*新建链表头节点*/struct books_list * Create_Books_Doc(){struct books_list * head;head=(struct books_list *)malloc(sizeof(struct books_list)); /*分配头节点空间*/head—>next=NULL; /*头节点指针域初始化,定为空*/return head;}/*保存数据至文件*/void save(struct books_list * head){struct books_list *p;FILE *fp;p=head;fp=fopen("data.txt","w+"); /*以写方式新建并打开 data。

图书管理系统代码

图书管理系统代码

c++程序如下:#include<stdio.h>#include<string.h>struct book{int num;char name[21];char zuozhe[13];float danjia;char zhuangtai[5];char people[9];char sex[3];char banji[8];int xuehao;} tushu[300];struct student{char pe[9];char se[3];char banji[8];int xu;int jie;int jieshu[5];} stu[100];int i,j,k,s=0,sum=0;void output(struct book tushu){printf("%6d",tushu.num);printf("%12s",);printf("%8s",tushu.zuozhe);printf("%10.2f",tushu.danjia);printf("%6s",tushu.zhuangtai);if(strcmp(tushu.zhuangtai,"已借")==0){ printf("%8s",tushu.people);printf("%5s",tushu.sex);printf("%10s",tushu.banji);printf("%4d",tushu.xuehao);}}void main(){int xz1,xz2,xz3,xz4,xz5,xz6,xz7,xz8,xz9,xz10;do{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(" 8.退出\n");printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");printf(" 请输入选择:");scanf("%d",&xz1);if(xz1==1){do{i=sum+1;printf("请输入图书编号:");scanf("%d",&tushu[i].num); printf("请输入图书名称:");scanf("%s",tushu[i].name); printf("请输入图书作者:");scanf("%s",tushu[i].zuozhe); printf("请输入图书单价:");scanf("%f",&tushu[i].danjia); strcpy(tushu[i].zhuangtai,"未借");sum++;printf("————————1.继续输入 2.返回————————请输入选择:");scanf("%d",&xz2);}while(xz2==1);}if(xz1==2){do{printf(" 1.按图书编号查询\n");&nbsp; printf(" 2.按图书名称查询\n");printf(" 3.按图书作者查询\n");printf(" 4.返回\n");printf(" 请输入选择:");scanf("%d",&xz3);if(xz3==4) break;if(xz3==1){printf("请输入要查找的图书编号:");int num1;k=0;scanf("%d",&num1);for(i=1;i<=sum;i++) if(num1==tushu[i].num){k=1;break;}if(k==0) printf(" ————————无此图书!————————\n");else{printf(" 编号 名称 作者 单价 状态 姓名 性别 &nbsp; 班级 学号\n");output(tushu[i]);printf("\n");}}if(xz3==2){printf("请输入要查找的图书名称:");char name1[21];k=0;scanf("%s",name1);for(i=1;i<=sum;i++) if(name1[1]==tushu[i].name[1]){k=1;break;}if(k==0) printf(" ————————无此图书!————————\n");else{printf(" 编号 名称 作者 单价 状态 姓名 性别 班级 学号\n"); output(tushu[i]);printf("\n");}}if(xz3==3){printf("请输入要查找的图书作者:");char zuozhe1[13];k=0; > scanf("%s",zuozhe1); for(i=1;i<=sum;i++) if(zuozhe1[1]==tushu[i].zuozhe[1]){k=1;break;}if(k==0) printf(" ————————无此图书!————————\n");else{printf(" 编号 名称 作者 单价 状态 姓名 性别 班级 学号\n"); output(tushu[i]);printf("\n");}}printf("————————1.继续查找 2.返回————————请输入选择:"); scanf("%d",&xz4);}while(xz4==1);}if(xz1==3){do{printf(" 1.指定图书编号删除\n");printf(" 2.指定图书名称删除\n");printf(" 3.指定图书作者删除\n");printf("&nbsp; 4.返回\n"); printf(" 请输入选择:");scanf("%d",&xz5);if(xz5==4) break;if(xz5==1){printf("请输入要删除的图书编号:");int num1;scanf("%d",&num1);for(i=1;i<=sum;i++)if(num1==tushu[i].num){for(j=i;j<=sum;j++)tushu[j]=tushu[j+1];printf(" ————————已成功删除————————\n");sum=sum-1;}}if(xz5==2){printf("请输入要删除的图书名称"); ; char name1[21];scanf("%s",name1);for(i=1;i<=sum;i++)if(strcmp(name1,tushu[i].name)==0){for(j=i;j<=sum;j++)tushu[j]=tushu[j+1];printf(" ————————已成功删除————————\n");sum=sum-1;}}if(xz5==3){printf("请输入要删除的图书作者:");char zuozhe1[13];scanf("%s",zuozhe1);for(i=1;i<=sum;i++)if(strcmp(zuozhe1,tushu[i].zuozhe)==0){for(j=i;j<=sum;j++)tushu[j]=tushu[j+1]; printf(" ————————已成功删除————————\n");sum=sum-1;}}printf("————————1.继续删除2.返回————————请输入选择:");scanf("%d",&xz6);}while(xz6==1);}if(xz1==4){do{i=s+1;printf("请输入姓名:");scanf("%s",stu[i].pe);printf("请输入性别:");scanf("%s",stu[i].se);printf("请输入班级:");scanf("%s",stu[i].banji);printf("请输入学号:");scanf("%d",&stu[i].xu);stu[i].jie=0;s=s+1;printf("————————1.继续输入 2.返回————————请输入选择:");scanf("%d",&xz7);}while(xz7==1);}if(xz1==5){do{char people1[9];k=0;printf("请输入会员姓名:");scanf("%s",people1);for(i=1;i<=s;i++) if(strcmp(people1,stu[i].pe)==0){k=1;break;}if(k==0) printf(" ————————无此会员!————————\n");else{printf("%s ",stu[i].pe);printf("%s ",stu[i].se);printf("%s ",stu[i].banji);printf("%d ",stu[i].xu);int kk=stu[i].jie;for(j=1;j<=kk;j++) printf("%d",stu[i].jieshu[j]);printf("\n");}printf("————————1.继续查找2.返回————————请输入选择:");scanf("%d",&xz8);}while(xz8==1);}if(xz1==6){char people1[9];k=0;printf("请输入借书人姓名:");scanf("%s",people1);for(i=1;i<=s;i++) if(strcmp(people1,stu[i].pe)==0){k=1;break;} if(k==0) printf("&nbs员不能借书!————————else{printf(" 1.输入要借的图书编号\n");printf(" 2.输入要借的图书名称\n");printf(" 3.返回\n");printf(" 请输入选择:");scanf("%d",&xz9);if(xz9==1){int num1;k=0;printf("请输入图书编号:");scanf("%d",&num1);for(j=1;j<=sum;j++) if(num1==tushu[j].num){k=1;break;}if(k==0) printf(" ————————未找到该图书!————————\n");else{k=stu[i].jie+1;stu[i].jieshu[k]=tushu[j].num;&nb。

图书管理系统程序代码

图书管理系统程序代码

#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。

图书管理系统的C#代码完整版

图书管理系统的C#代码完整版

C#代码清单共1个项目,包含5个类。

项目: librarysystem类:主类代码:namespace librarysystem{ PublicationISBN = PublicationISBN;= PublicationName;= PublicationAuthor;= PublicationType;= PublicationStatus;}}}读者类代码:namespace librarysystem{ 询图书");("2.借书服务");("3.还书服务");("4.新出版物入库");("5.录入新读者");("6.查询读者的借阅信息");("7.退出管理系统");("-------------------------------------------------------------------");bool flag;do{flag = false;("请选择:");string key = ();switch (key){case"1":("请输入需要查询图书的书名:");ShowPubInfo();break;case"2":("请输入您的姓名:");();ShowBorrowInfo();("请输入您的姓名:");();ShowReturnInfo();break;case"4":("请按照提示逐步输入需要入库出版物的信息……");ShowAddPublications();break;case"5":("请按照提示逐步输入新注册读者的信息……");ShowAddReaders();break;case"6":("请输入您的姓名: ");();ShowRedPubInfo;break;case"7":flag = false;break;default:("无此业务,是否重新选择(y/n)");string answer = ();if (answer != "y"){flag = false;}else{flag = true;}break;}} while (flag);}/*显示查询到的出版物信息*/public void ShowPubInfo(){if ()){("您要查询的出版物信息:");("-------------------------------------------------------------------"); ("编号: " + ("出版物名字: " + ("出版物作者: " + ("出版物类型: " + if {("出版物状态:在架,可借");else{("出版物状态:未在架,不可借");}("-------------------------------------------------------------------"); ("");("");("是否办理其他业务(y/n)");string answer = ();if (answer == "y"){ShowMainMenu();();}else{("结束");}}else{("抱歉,未找到该图书!");("是否办理其他业务(y/n)");string answer = ();if (answer == "y"){ShowMainMenu();();();}else{("结束");}}}/*显示借阅操作结果*/public void ShowBorrowInfo(){if{("恭喜,借阅成功!");ShowRedPubInfo;}{("抱歉,借阅失败!");("是否办理其他业务(y/n)");string answer = ();if (answer == "y"){ShowMainMenu();}else{("结束");}}}/*显示归还操作结果*/public void ShowReturnInfo(){if{("恭喜,归还成功!");ShowRedPubInfo;}else{("抱歉,归还失败!");("是否办理其他业务(y/n)");string answer = ();if (answer == "y"){ShowMainMenu();}else{("结束");}}}public void ShowRedPubInfo(Readers red){("当前你的借阅信息如下:");("--------------------------------------------------------------------"); ("编号: " + ;("姓名: " + ;("性别: " + ;("主修专业: " + ;("已借图书: ");for (int{if [i] != ""){(" "+[i]);}}("");("--------------------------------------------------------------------"); ("");("是否办理其他业务(y/n)");string answer = ();if (answer == "y"){ShowMainMenu();}else{("结束");}}/*显示新出版物入库的信息*/public void ShowAddPublications(){pub = new Publications();("请输入出版物的编号: ");=();("请输入出版物的名称: ");= ();("请输入出版物的编者: ");= ();("请输入出版物的类型: ");= ();= true;(pub);("新出版物入库成功!");("是否办理其他业务(y/n)");string answer = ();if (answer == "y"){ShowMainMenu();();}else{("结束");}}/*显示新读者注册的信息*/public void ShowAddReaders(){red = new Readers();("请输入新注册读者的编号: "); = ();("请输入新注册读者的姓名: "); = ();("请输入新注册读者的性别: "); = ();("请输入新注册读者的院系: "); = ();("请输入新注册读者的专业: "); = ();for(int i=0;i<10;i++){[i]="";}(red);("新读者注册成功!");("是否办理其他业务(y/n) ");string answer = ();if (answer == "y"){ShowMainMenu();();();}else{("结束");}}}}。

图书管理系统(源代码)

图书管理系统(源代码)

#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语言实现代码
int number;
char telephone[20];
int NO;
char bookname[20];
int borrowdate;
int returndate;
if((fp=fopen("jieshujilu.txt","r"))==NULL){
scanf("%s",);
fprintf(fp,"%s",);
printf("请输入借书人班级:");
scanf("%s",p.classes);
fprintf(fp," %s",p.classes);
printf("请输入借书人学号:");
scanf("%d",&p.number);
/*随代码必须新建一下文件:jieshujilu.txt shuku.txt tempbook.txt tempshuku.txt */
#include<stdio.h>
#include<stdlib.h>
struct book{
char bookname[20]; //书名
exit(0);
}
printf("请输入此次收到的书本总数:");
scanf("%d",&i);
for(j=0;j<i;j++){
printf("请输入书名:");
scanf("%s",b.bookname);
fprintf(fp,"%s",b.bookname);

图书管理系统的设计(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<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");}。

图书馆管理系统代码

图书馆管理系统代码

图书馆管理系统代码#include#define DEBUG 0//宏定义决定测试代码是否编译0为不编译⾮0则编译const char book_path[20] = "books.txt";const char reader_path[20] = "readers.txt";//⽂件读写声明void read_from_files_to_vector();void write_all_to_files();#if DEBUGvoid scan_readers() {for(reader &s:readers) {wcout << s;}}#endifint main(){//完成操作后需要在控制台按5中退出才会保存到⽂件wcin.imbue(china);wcout.imbue(china);read_from_files_to_vector();#if DEBUGcout <<"size of readers = "<< readers.size() << endl;cout <<"size of books = "<< books.size() << endl;scan_book();scan_readers();#endifstring password = "123456"; //密码已改cout <<"------------欢迎使⽤中南⼤学⽹络在线图书系统------------"< //这⾥可以添加你们⼩组的名单或⼀些装饰的字符cout <<"--------------------请选择登录⽅式--------------------"<< endl; cout <<" 1 管理员登陆2读者登陆"<< endl;int a;cin >> a;cleanScreen();if (a == 1){string str;for (int j = 0; j <= 4; j++){cout <<"请输⼊管理密码,你有"<< (4-j) <<"次机会"<< endl; cin >> str;if (password == str){break;}else cout <<"密码错误!请重新输⼊"<< endl;if (j == 4)return 0;}cleanScreen();cout <<"-------------欢迎来到图书管理系统-------------"<< endl; cout <<"成功登陆!你有以下操作可供选择"<< endl;cout << endl;//操作循环cout <<" 1 浏览图书信息"<< endl;cout <<" 2 图书信息修改"<< endl;cout <<" 3 图书信息添加"<< endl;cout <<" 4 图书信息删除"<< endl;cout <<" 5 保存信息并退出系统"<< endl;cout <<"--------------请选择操作选项编号--------------"<< endl; int b;cin >> b;cleanScreen();while (b != 5) {switch (b){case 1:scan_book(); break;case 2:modify_book(); break;case 3:add_book(); break;case 4:delete_book(); break;default:cout <<"输⼊错误,请重新输⼊"; break;}cout << endl;cout <<"---------------请进⾏下⼀次操作---------------"<< endl; cout <<" 1 浏览图书信息"<< endl;cout <<" 2 图书信息修改"<< endl;cout <<" 3 图书信息添加"<< endl;cout <<" 4 图书信息删除"<< endl;cout <<" 5 退出系统"<< endl;cout <<"--------------请选择操作选项编号--------------"<< endl; cin >> b;cleanScreen();}write_all_to_files();return 0;}else if (a == 2){int readerIndex = 0; //记录读者下标//输⼊学号登陆cout <<"--------------请输⼊学号--------------"<< endl;wchar_t studentnumber[20];for (int m = 0; m <= 9; m++){cout <<"请输⼊学号,你有"<< (9-m) <<"次机会"<< endl; wcin >> studentnumber;int t;for (t = 0; t < readers.size(); t++){if (wcscmp(studentnumber, readers[t].cardnum) == 0){readerIndex = t;break;}}//判断跳出循环原因if (t < readers.size())break;else{cout <<"登录账号不存在,请重新输⼊学号"<< endl;continue;}if (m == 9)return 0;}cleanScreen();cout <<"------------欢迎来到读者⾃助系统------------"<< endl;wcout << L"欢迎你,"<< readers[readerIndex].name << L"!你有以下操作可供选择"<< endl; cout << endl;//操作循环cout <<" 1 图书浏览"<< endl;cout <<" 2 图书查询"<< endl;cout <<" 3 图书借阅"<< endl;cout <<" 4 图书返还"<< endl;cout <<" 5 退出系统"<< endl;cout <<"---------------请选择操作选项--------------"<< endl;int c;cin >> c;cleanScreen();while (c != 5){switch (c){case 1:scan_book(); break;case 2:search_book(); break;case 3:borrow_book(readerIndex); break;case 4:return_book(readerIndex); break;default:cout <<"输⼊错误!请重新输⼊"<< endl; break;}cout << endl;cout <<"--------------请进⾏下⼀次操作--------------"<< endl;cout <<" 1 图书浏览"<< endl;cout <<" 2 图书查询"<< endl;cout <<" 3 图书借阅"<< endl;cout <<" 4 图书返还"<< endl;cout <<" 5 退出系统"<< endl;cout <<"---------------请选择操作选项---------------"<< endl;cin >> c;cleanScreen();}write_all_to_files();return 0;}return 0;}//main 函数结束//写⼊/读取⽂件void write_all_to_files(){wofstream outfile;outfile.imbue(locale("chs"));//写⼊书本⽂件outfile.open(book_path);outfile << books.size() << '\n';for (int i = 0; i < books.size(); i++){outfile << books[i];}outfile.close();outfile.clear();//写⼊读者⽂件,由于程序中没有针对读者的删改(备⽤,将0改为1后即可编译这段代码) #if 0 outfile.open(path::reader_path);outfile << readers.size() << '\n';for (int i = 0; i < readers.size(); i++){outfile << readers[i];}outfile.close();#endifreturn;}void read_from_files_to_vector(){wifstream infile;infile.imbue(locale("chs"));//⽤于设置读写中⽂book bb;reader rr;//在程序⽬录下没有相应⽂件时创建空⽂件(备⽤,将0改为1后即可编译这段代码) #if 0 wofstream creat_if_no;creat_if_no.imbue(locale("chs"));creat_if_no.open(book_path,ios::_Noreplace);creat_if_no.close();creat_if_no.clear();creat_if_no.open(reader_path, ios::_Noreplace);creat_if_no.close();creat_if_no.clear();#endif//读取书本数据infile.open(book_path);int size = 0;infile >> size;while (!infile.eof() && size != 0){infile >> bb;books.push_back(bb);size--;}infile.close();infile.clear();//读取读者数据infile.open(reader_path);infile >> size;while (!infile.eof() && size != 0){infile >> rr;readers.push_back(rr);size--;}infile.close();return;}#include "classes.h"locale china("chs");//use china character/*void printout_book(book &b){cout << b.id << '\n'<< b.title << '\n'<< b.firstauthor << '\n'<< b.publisher <<'\n'<< b.birthday << '\n'<< b.location << '\n'<< b.price << '\n'<< b.number << endl;}*///这个函数我⽤重载运算符<< 的函数代替了//对应全局变量的定义vector books;vector readers;//book重载操作符函数定义wistream& operator >> (wistream& in, book &b) { cout <<"请输⼊书号"<< endl;cout <<"请输⼊书名"<< endl;in >> b.title;cout <<"请输⼊作者名"<< endl;in >> b.firstauthor;cout <<"请输⼊出版社"<< endl;in >> b.publisher;cout <<"请输⼊印刷⽇期(年⽉)"<< endl;in >> b.birthday;cout <<"请输⼊所属类别"<< endl;in >> b.location;cout <<"请输⼊价格"<< endl;in >> b.price;cout <<"请输⼊数量"<< endl;in >> b.number;return in;}wostream& operator<<(wostream& out, book &b){out << b.id << ' '<< b.title << ' '<< b.firstauthor << ' '<< b.publisher << ' '<< b.birthday.year << ' '<< b.birthday.month << ' '<< b.location << ' '<< b.price << ' '<< b.number << endl;return out;}wifstream& operator >> (wifstream& in, book &b){in >> b.id >> b.title >> b.firstauthor>> b.publisher >> b.birthday.year >> b.birthday.month >> b.location >> b.price >> b.number;{out << b.id << ' '<< b.title << ' '<< b.firstauthor << ' '<< b.publisher << ' '<< b.birthday << ' '<< b.location << ' '<< b.price << ' '<< b.number << '\n';return out;}//reader重载操作符函数定义wistream& operator >> (wistream& in, reader &r){//由于没有对reader的操作,这个函数尚未被使⽤cout <<"请输⼊读者姓名"<< endl;in >> /doc/3dc30ba0fbb069dc5022aaea998fcc22bdd14356.html ; cout <<"请输⼊性别(男为0,⼥为1)"<< endl;cout <<"请输⼊卡号"<< endl;in >> r.cardnum;cout <<"请输⼊学位(学⼠为0,硕⼠为1,博⼠为2)"<< endl;in >> r.e;r.already = 0; //已借书本数默认为0return in;}wostream& operator<<(wostream& out, reader &r){out << r.cardnum << ' ';out << /doc/3dc30ba0fbb069dc5022aaea998fcc22bdd14356.html << ' '; out << r.s << ' ';out << r.e << ' ';out << r.already << endl;{in >> r.cardnum >> /doc/3dc30ba0fbb069dc5022aaea998fcc22bdd14356.html >> r.s >> r.e >> r.already;return in;}wofstream& operator<<(wofstream& out, reader &r){out << r.cardnum << ' '<< /doc/3dc30ba0fbb069dc5022aaea998fcc22bdd14356.html << ' '<< r.s << ' '<< r.e << ' '<< r.already << '\n';return out;}//main函数中调⽤定义void scan_book() //建⽴浏览函数{for (int i = 0; i < books.size(); i++){wcout << books[i];}}void search_book() //建⽴搜索函数{cout <<"************你有以下查询⽅式可供选择************"<< endl; cout <<" 1 按书名查询"<< endl;cout <<" 2 按编号查询"<< endl;cout <<" 3 按作者查询"<< endl;cout <<"************请选择查询⽅式************"<< endl;cin >> g;switch (g){case 1:{wchar_t name[20];cout <<"************请输⼊书名************"<< endl; wcin >> name;for (int r = 0; r < books.size(); r++){if (wcscmp(books[r].title, name) == 0){wcout << books[r];return;}}cout <<"查⽆此书"<< endl;return;break;}case 2:{int str;cout <<"************请输⼊图书编号************"<< endl; cin >> str;for (int l = 0; l < books.size(); l++){if (books[l].id == str){wcout << books[l];return;}}cout <<"查⽆此书"<< endl;return;break;}case 3:wchar_t auth[10];cout <<"************请输⼊图书作者************"<< endl;wcin >> auth;for (int p = 0; p < books.size(); p++){if (wcscmp(books[p].firstauthor, auth) == 0){wcout << books[p];return;}}cout <<"查⽆此书"<< endl;return;break;}default:{cout <<"查⽆此书"<< endl;return;}}}//实现逻辑有问题,⽆法建⽴书-借书⼈的对应关系void borrow_book(int t) //建⽴借书函数{if (readers[t].already >= 5){cout <<"抱歉,你的借书数已满,不可再借"<< endl;return;}int log;cout <<"************请输⼊要借出图书的登陆号************"<< endl; wcin >> log;for (int i = 0; i < books.size(); ++i){if (log == books[i].id){if (books[i].number > 0){int y;cout <<"确认借出书籍吗?确认请输⼊1 取消请输⼊0"<< endl;cin >> y;if (y == 1){cout <<"借阅成功!";--(books[i].number);++(readers[t].already);return;}else return;}else{cout <<"图书已借完"<< endl;return;}}}cout <<"图书不存在!"<< endl;return;}void return_book(int t) //建⽴还书函数{int log;cout <<"************请输⼊要归还的图书的登陆号************"<< endl; wcin >> log;for (int i = 0; i < books.size(); i++){if (log == books[i].id){cout <<"图书归还成功"<< endl;++books[i].number;--readers[t].already;return;}}cout <<"图书不存在于本图书馆⽆需归还!"<< endl;return;}void modify_book() //建⽴修改函数{int log;cout <<"************请输⼊要修改的图书编号************"<< endl; wcin >> log;for (int i = 0; i < books.size(); i++){if (log == books[i].id){cout <<"需修改图书信息如下"<< endl;wcout << books[i];cout <<"************请输⼊修改后的信息************"<< endl; wcin >> books[i];return;}}cout <<"图书不存在⽆法修改"<< endl;return;}void delete_book(){int log;cout <<"************请输⼊要删除的图书编号************"<< endl; cin >> log;//迭代器实现删除指定图书vector::iterator itor2;for (vector::iterator iter = books.begin(); iter != books.end(); ){if (log == iter->id){cout <<"将删除的图书信息如下"<< endl;wcout << *iter;int sure = 0;cout <<"确定删除?(1确定,0取消)"<< endl;cin >> sure;if (sure == 0)return;//开始在内存中删除itor2 = iter;books.erase(itor2);cout <<"编号为"<< log <<"的图书已删除"<< endl; return;}elseiter++;}cout <<"图书不存在⽆法删除"<< endl;return;}void add_book(){book new_book;cout <<"************请输⼊新图书信息************"<< endl; wcin >> new_book;books.push_back(new_book);return;}。

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)。

模块设计
基础模块
SqlSession:
利用mybatis获取jdbc,其中有inter.select,update,select等方法
String resource = "mybatis-config.xml";
InputStream inputStream = Resources.getResourceAsStream(resource);
SqlSessionFactory sqlSessionFactory = new
SqlSessionFactoryBuilder().build(inputStream);
SqlSession sesson = sqlSessionFactory.openSession();
Dao基础模块
所有的dao都继承于BaseDao; 代码
/**
*保存利用mybatis的xml
* model 保存的对象
*id mybatis的id名
*/
Public void Save(BaseModel model,String id){
sesson.inster(id model);
}
……
Model基础模块
所有的模型都继承于BaseModel;
代码片段
/**
*字段编号
*/
Private int id;
Public void setId(String id){
This.id = id;
}
Public String getId(){
Return id;
}
添加书籍
代码片段
Book book = new Book();
book.setId(…..);
……..
Book.setTitle(….);
BooksManageDao bookDao = new BooksManageDao();
bookDao .save(“addBook”,book);
删除书籍
代码片段
BookDao bookDao = new BookDao();
Book book = (Book) bookDao .getModel(id);
BooksManageDao bookDao = new BooksManageDao();
bookDao .delete(“delete Book”,book);
更新书籍
代码片段
BookDao bookDao = new BookDao();
Book book = (Book) bookDao .getModel(id);
book.setId(…..);
……..
Book.setTitle(….);
BooksManageDao bookDao = new BooksManageDao(); bookDao .update(“update Book”,book); 查询书籍
代码片段
//数据库的自定义一页显示10条
Int pageNo = “当前页数”
BooksManageDao bookDao = new BooksManageDao();
bookDao .select(“selectte Book”, pageNo);
添加用户
代码片段
Student student = new Student ();
student.setId(…..);
……..
student.setTitle(….);
StudentDao studentDao = new StudentDao();
studentDao .save(“add Student”,book);
删除用户
代码片段
Int id = “字段编号”
StudentDao studentDao = new StudentDao()
Student student = (Student) studentDao.getModel(id);
student.setId(…..);
StudentDao studentDao = new StudentDao(); studentDao .delete(“deleteStudent”,book); 更新用户
代码片段
Int id = “字段编号”
StudentDao studentDao = new StudentDao()
Student student = (Student) studentDao.getModel(id);
student.setId(…..);
……..
student.setTitle(….);
StudentDao studentDao = new StudentDao(); studentDao .update(“updeteStudent”,book); 查询用户
代码片段
//数据库的自定义一页显示10条
Int pageNo = “当前页数”
StudentDao studentDao = new StudentDao();
studentDao .select(“selectStudent”, pageNo);
借阅书籍
代码片段
Borrow borrow = new Borrow();
Student student = new Student ();
student.setId(…..);
……..
student.setTitle(….);
Book book = newBook();
book.setId(…..);
……..
book.setTitle(….);
borrow .save(“b orrow”,book,student);
归还书籍
代码片段
ReturnNook returnBook = new ReturnNook();
Student student = new Student ();
student.setId(…..);
……..
student.setTitle(….);
Book book = newBook();
book.setId(…..);
……..
book.setTitle(….);
returnBook .save(“returnBook”,book,student);。

相关文档
最新文档