图书管理系统程序代码

合集下载

图书管理系统程序源代码

图书管理系统程序源代码

源程序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 结构体的数据。

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

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

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

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

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

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

C语言程序设计(图书管理系统)源代码 倾情奉献

C语言程序设计(图书管理系统)源代码 倾情奉献

# include< stdio.h ># include< string.h ># include< stdlib.h >/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/struct tushu_node{int num;char leibie[20];char name[30];char author[20];char press[20];char time[20];double price;struct tushu_node*next;};FILE *fpp; /*定义fpp为全局变量*/struct tushu_node*head,*tail,*p;int quanxian(); /* 核查权限的函数*/int inputchioce(); /* 显示主菜单的函数*/void save(); /* 保存链表为文件的函数覆盖以前的信息*/ void save1(); /* 保存链表为文件的函数不覆盖以前的信息只在创建时调用一次*/struct tushu_node* wjtolb(); /* 从文件中读取数据并建立图书信息的链表的函数*/int luruxinxi(); /* 录入学生信息的函数*/ struct tushu_node * luruxinxi_chuangjian(); /* 创建图书信息的函数*/struct tushu_node * luruxinxi_charu(); /*插入图书信息的函数*/struct tushu_node * luruxinxi_shanchu(); /*删除图书信息的函数*/struct tushu_node * luruxinxi_xiugai(); /*修改图书信息的函数*/int liulantushu(); /* 浏览图书信息的函数*/int chaxuntushu(); /* 查询图书信息的函数*/ void chaxuntushu_num(); /* 按编号查询图书*/void chaxuntushu_name(); /* 按书名查询图书*/void chaxuntushu_price(); /* 按价格查询图书*/void paixutushu(); /* 为图书排序的函数*/ struct tushu_node* paixutushu_price(); /* 为图书按价格排序的函数*/ struct tushu_node* paixutushu_time(); /* 为图书按出版时间排序的函数*/void sfjx() ; /* 写个小函数,判断是否继续,让程序更完美在排序中使用*/int tongjitushu_shumu(); /* 统计图书数目的函数*/void shiyongshuoming(); /* 使用说明的函数*//*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/int main(){int chioce;chioce=quanxian(); /*核查用户是否有使用该管理系统的权限的函数*/if(chioce==1) /*若取得权限则返回值为1 */{system("cls");inputchioce();}exit(0);}/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/int inputchioce() /* 主菜单*/{int mychioce,x=-1;printf("\n++++++++++++++++++++++++++++++++++++++欢迎你++++++++++++++++++++++++++++++++++\n\n");printf("**+++++++++++++++++++++++++++++++++++ 主菜单+++++++++++++++++++++++++++++++**\n");printf("** 1-- 录入(删除修改)图书信息** ** 2--(按规则)查询图书信息**\n");printf("** 3-- 浏览图书信息** ** 4-- 为图书(按规则)排序**\n");printf("** 5-- 统计图书(数目)** ** 6-- 帮助**\n");printf("** 0-- 退出系统** ** **\n");printf("**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++**\n");printf("\n 恭喜你获得使用权限,请你选择:");scanf("%d",&mychioce);switch(mychioce){case 1:{ luruxinxi();break;}case 2:{chaxuntushu();break;}case 3:{ liulantushu();break;}case 4:{ paixutushu();break;}case 5:{ tongjitushu_shumu();printf("\n\n是否继续操作? 请选择(继续-1/退出-0)");scanf("%d",&x);if(x==1){ system("cls");inputchioce();}if(x==0){printf("\n\n谢谢你的使用!再见\n");exit (0); }if(x!=1&&x!=0){system("cls");printf("选择有误,默认返回主菜单,请重新选择:\n");inputchioce();}break;}case 6:{ shiyongshuoming();break;}case 0:{ printf(" \n\n 谢谢你的使用!!再见\n\n");break;}default:{ system("cls");printf("\n 选择有误,请重新选择:\n");inputchioce();}break;}}/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/int quanxian(){int m=1,n=3,flag=0;char mima[20];do{printf("\n\n 你好,欢迎使本图书信息管理系统!\n");printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~\n");printf("【现在进行权限核查】\n--------------------友情提醒:你共有3次输入密码的机会!\n");printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~\n ");if(n==2||n==1){printf("注意:你已输入错误%d次剩余输入次数: %d 请输入密码:",3-n,n);}if(n==3) printf("剩余输入次数: %d 请输入密码:",n);scanf("%s",mima);if(strcmp(mima,"chenbo0916")==0){flag=1;return flag;}m++;n--;system("cls");}while(strcmp(mima,"chenbo0916")!=0&&m<=3) ;printf("\n\n对不起,你连续三次输入密码错误,没有使用该图书管理系统的权限!\n");exit(0);}/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/struct tushu_node* wjtolb(struct tushu_node*head,int *n) /* 从文件中读取数据并建立图书信息的链表的函数*/{FILE *fp;struct tushu_node*p,*p1,*p2;if((fp=fopen("1.txt","r"))==NULL){printf(" 打开文件失败!\n");exit(1);}while(!feof(fp)){(*n)++;p=(struct tushu_node*)malloc(sizeof(struct tushu_node));fscanf(fp,"%d%s%s%s%s%s%lf",&p->num,p->leibie,p->name,p->author,p->press,p->time,&p->price);if(head==NULL){head=p;p1=p;}else{p1->next=p;p2=p1;p1=p;}}p2->next=NULL;free(p);(*n)--;fclose(fp);return head;/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/int luruxinxi(){int k;printf(" |++++++++++++++++++++++++++++录入信息++++++++++++++++++++++++++++++++|\n");printf(" | 1-- 创建或添加图书信息** ** 2-- 删除图书信息|\n");printf(" | 3-- 修改图书信息** ** 0-- 还回主菜单|\n");printf("请你再次选择具体操作:");scanf ("%d",&k);system("cls"); /* 清屏*/switch(k){case 1:{ luruxinxi_chuangjian();break;}case 2:{luruxinxi_shanchu();break;}case 3:{luruxinxi_xiugai();break;}case 0:{ inputchioce();break;}default:{ system("cls");printf("选择有误,默认返回主菜单,请重新选择:\n");inputchioce();}break;}}/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/struct tushu_node * luruxinxi_chuangjian() /* 创建图书信息的函数*/{int num;char leibie[10];char name[30];char author[20];char press[20];char time[20];double price;int size=sizeof(struct tushu_node);head=tail=NULL;printf("\n请依次输入图书的\n编号类别书名作者出版社出版时间价格(以“0”结束输入):\n");scanf("%d",&num);if(num!=0)scanf("%s%s%s%s%s%lf",leibie,name,author,press,time,&price);while(num!=0){p=(struct tushu_node*)malloc(size);p->num=num;strcpy(p->leibie,leibie);strcpy(p->name,name);strcpy(p->author,author);strcpy(p->press,press);strcpy(p->time,time);p->price=price;p->next=NULL;if(head==NULL)head=p;elsetail->next=p;tail=p;printf("\n请继续输入图书的\n编号类别书名作者出版社出版时间价格(以“0”结束输入):\n");scanf("%d",&num);if(num!=0){scanf("%s%s%s%s%s%lf",leibie,name,author,press,time,&price);}}if(num==0) /* 若判断数字为0,则退出*/{system("cls");save1(head);inputchioce();}return head;}/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/void save1(struct tushu_node* p1){ /* 将链表保存为文件的函数不覆盖以前的信息*/if( (fpp=fopen("1.txt","a"))==NULL ){printf("打开文件失败!");exit(0);}while(p1!=NULL){fprintf(fpp," %d %s %s %s %s %s %lf \n",p1->num,p1->leibie,p1->name,p1->author,p1->press,p1->time,p1->price);p1=p1->next;}if(fclose(fpp)){printf("关闭文件失败!\n");exit(0);}}/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/void save(struct tushu_node* p1) /* 将链表保存为文件的函数覆盖以前的信息*/{if(( fpp=fopen("1.txt","w"))==NULL ){printf("打开文件失败!");exit(0);}while(p1!=NULL){fprintf(fpp," %d %s %s %s %s %s %lf \n",p1->num,p1->leibie,p1->name,p1->author,p1->press,p1->time,p1->price);p1=p1->next;}if(fclose(fpp)){printf("关闭文件失败!\n");exit(0);}}/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/struct tushu_node * luruxinxi_shanchu() /* 删除某本图书信息(按编号删除)*/{int x=-1,n=0;int numm;int num;char leibie[10];char name[30];char author[20];char press[20];char time[20];double price;struct tushu_node*ptr1,*ptr2;struct tushu_node*head=NULL;printf("\n所有的图书信息如下:\n"); /* 删除前先遍历所有图书,方便看清要删除哪一本*/if((fpp=fopen("1.txt","r"))==NULL) /* 输入要删除的图书编号之前先遍历所有图书信息*/{printf(" 打开文件失败!");exit(0);}else{printf("\n\n编号类别书名作者出版社出版时间价格\n");while(!feof(fpp)){fscanf(fpp,"%d%s%s%s%s%s%lf",&num,leibie,name,author,press,time,&price);printf("%d %s %s %s %s %s %lf\n",num,leibie,name,author,press,time, price);}}if(fclose(fpp)){printf("关闭文件失败!\n");exit(0);}head=wjtolb(head,&n); /* 从文件中读取数据将数据创建为链表*/printf("\n 输入需要删除的图书的编号:");scanf("%d",&numm);while(head!=NULL&&head->num==numm){ptr2=head;head=head->next;free(ptr2);}if(head==NULL)return NULL;ptr1=head;ptr2=head->next;while(ptr2!=NULL){if(ptr2->num==numm){ptr1->next=ptr2->next;free(ptr2);}elseptr1=ptr2;ptr2=ptr1->next;}save(head); /* 重新保存为文件*/printf(" 编号为%d的图书已删除并将删除后的信息保存至文件",numm);printf("\n\n是否继续操作? 请选择(继续-1/退出-0)");scanf("%d",&x);if(x==1){system("cls");inputchioce();}if(x==0){printf("\n\n谢谢你的使用!再见\n");exit (0);}if(x!=1&&x!=0){system("cls");printf("选择有误,默认返回主菜单,请重新选择:\n");inputchioce();}return head;}/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/struct tushu_node * luruxinxi_xiugai() /*修改图书信息的函数(按编号修改)*/ { int n=0,x=-1,t;int num;int numm;char leibie[10];char name[30];char author[20];char press[20];char time[20];double price;struct tushu_node*head=NULL;struct tushu_node*p;printf("\n所有的图书信息如下:\n");if( (fpp=fopen("1.txt","r"))==NULL ) /* 输入要修改的图书编号之前先遍历所有图书信息*/{printf(" 打开文件失败!");exit(0);}else{printf("\n\n编号类别书名作者出版社出版时间价格\n");while(!feof(fpp)){fscanf(fpp,"%d%s%s%s%s%s%lf",&num,leibie,name,author,press,time,&price);printf("%d %s %s %s %s %s %lf\n",num,leibie,name,author,press,time, price);}}if(fclose(fpp)){printf("关闭文件失败!\n");exit(0);}printf("\n输入需要修改的图书的编号:");scanf("%d",&numm);system("cls"); /* 先遍历后选择完要修改的图书编号后清屏*/head=wjtolb(head,&n);printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~\n");printf("1--修改图书编号2--修改图书类别\n");printf("3--修改图书书名4--修改图书作者\n");printf("5--修改图书出版社6--修改图书出版时间\n");printf("7--修改图书价格\n");printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~\n");printf("编号为%d本图书的信息为:\n",numm);if(head!=NULL&&head->num==numm) /*修改头结点*/{printf("编号类别书名作者出版社出版时间价格\n");printf("%d %s %s %s %s %s %lf\n",head->num,head->leibie,head ->name,head->author,head->press,head->time,head->price);printf("请选择需要修改的图书信息的成分:");scanf("%d",&t);switch(t){case 1:{ printf(" 请输入图书%d的新编号:\n",numm);scanf("%d",&num);head->num=num;break;}case 2:{printf(" 请输入图书%d的新类别:\n",numm);scanf("%s",leibie);strcpy(head->leibie,leibie);break;}case 3:{ printf(" 请输入图书%d的新书名:\n",numm);scanf("%s",name);strcpy(head->name,name);break;}case 4:{ printf(" 请输入图书%d的新作者:\n",numm);scanf("%s",author);strcpy(head->author,author);break;}case 5:{ printf(" 请输入图书%d的新出版社:\n",numm);scanf("%s",press);strcpy(head->press,press);break;}case 6:{ printf(" 请输入图书%d的新出版时间:\n",numm);scanf("%s",time);strcpy(head->time,time);break;}case 7:{ printf(" 请输入图书%d的新价格:\n",numm);scanf("%lf",&price);head->price=price;break;}default:{ system("cls");printf("选择有误,默认返回主菜单,请重新选择:\n");inputchioce();}break;}save(head);printf("\n\n是否继续操作? 请选择(继续-1/退出-0)");scanf("%d",&x);if(x==1){system("cls");inputchioce();}if(x==0){printf("\n\n谢谢你的使用!再见\n");exit (0);}if(x!=1&&x!=0){system("cls");printf("选择有误,默认返回主菜单,请重新选择:\n");inputchioce();}}else /* 要修改的不是头节点*/{p=head->next;}//do 用do-while语句事不能对第二本图书进行修改//{p=p->next;}while(p!=NULL&&p->num!=numm);while(p!=NULL&&p->num!=numm){p=p->next;}if(p!=NULL&&p->num==numm) /* 修改其他节点*/{printf("\n\n编号类别书名作者出版社出版时间价格\n");printf("%d %s %s %s %s %s %lf\n", p->num,p->leibie,p->name,p->author,p->press,p->time,p->price);printf("请选择需要修改的图书信息的成分:");scanf("%d",&t);switch(t){case 1:{ printf(" 请输入图书%d的新编号:\n",numm);scanf("%d",&num);p->num=num;break;}case 2:{printf(" 请输入图书%d的新类别:\n",numm);scanf("%s",leibie);strcpy(p->leibie,leibie);break;}case 3:{ printf(" 请输入图书%d的新书名:\n",numm);scanf("%s",name);strcpy(p->name,name);break;}case 4:{ printf(" 请输入图书%d的新作者:\n",numm);scanf("%s",author);strcpy(p->author,author);break;}case 5:{ printf(" 请输入图书%d的新出版社:\n",numm);scanf("%s",press);strcpy(p->press,press);break;}case 6:{ printf(" 请输入图书%d的新出版时间:\n",numm);scanf("%s",time);strcpy(p->time,time);break;}case 7:{ printf(" 请输入图书%d的新价格:\n",numm);scanf("%lf",&price);p->price=price;break;}default:{ system("cls");printf("选择有误,请重新选择:\n");inputchioce();}break;}save(head);printf("\n\n是否继续操作? 请选择(继续-1/退出-0)");scanf("%d",&x);if(x==1){system("cls");inputchioce();}if(x==0){printf("\n\n谢谢你的使用!再见\n");exit (0);}if(x!=1&&x!=0){system("cls");printf("选择有误,默认返回主菜单,请重新选择:\n");inputchioce();}}return head;}/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/int liulantushu() /* 浏览图书信息的函数*/{int num;char leibie[10];char name[30];char author[20];char press[20];char time[20];double price;int x=-1;if( (fpp=fopen("1.txt","r"))==NULL ){printf(" 打开文件失败!");exit(0);}else{printf("\n\n编号类别书名作者出版社出版时间价格\n");while(!feof(fpp)){fscanf(fpp,"%d%s%s%s%s%s%lf",&num,leibie,name,author,press,time,&price);printf("%d\t%s\t%s\t%s\t%s\t%s\t%lf\n",num,leibie,name,author,press,time,price);}}if(fclose(fpp)){printf("关闭文件失败!\n");exit(0);}printf("\n\n是否继续操作? 请选择(继续-1/退出-0)");scanf("%d",&x);if(x==1){system("cls");inputchioce();}if(x==0){printf("\n\n谢谢你的使用!再见\n");exit (0);}if(x!=1&&x!=0){system("cls");printf("选择有误,默认返回主菜单,请重新选择:\n");inputchioce();}}/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/int chaxuntushu() /* 查询图书信息*/{int k;int n=0;struct tushu_node*head=NULL;head=wjtolb(head,&n);printf(" |++++++++++++++++++++++++++++ 查询图书信息++++++++++++++++++++++++++++++++|\n");printf(" | 1-- 按编号查询图书信息** ** 2-- 按书名查询图书信息|\n");printf(" | 3-- 按价格查询图书信息** ** 0-- 还回主菜单|\n");printf("请你再次选择具体操作:");scanf ("%d",&k);system("cls"); /* 清屏*/switch(k){case 1:{ chaxuntushu_num(head);break;}case 2:{ chaxuntushu_name(head);break;}case 3:{ chaxuntushu_price(head);break;}case 0:{ inputchioce();break;}default:{ system("cls");printf("选择有误,默认返回主菜单,请重新选择:\n");inputchioce();}break;}}/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/void chaxuntushu_num(struct tushu_node*h) /* 按编号查询图书*/{int found,flag=1,num;int x;struct tushu_node*p;do{found=0;p=h;printf("请输入需要查找的图书的编号:");scanf( "%d",&num);printf("\n");while(p!=NULL){if(p->num==num){if(found==0)printf("\n编号类别书名作者出版社出版时间价格\n");printf("%d %s %s %s %s %s %lf\n",p->num,p->leibie,p->name,p->author,p->pr ess,p->time,p->price);found=1; /* 如果要查询的图书为头节点内的图书输出后将标记found变为1 */}p=p->next;}if(found==0) /* 若不为头节点found不变继续往后面查找*/printf("编号为%d 的图书未找到!\n",num);printf("\n\n是否继续查找?(继续--1/返回主菜单--0)");scanf("%d",&x);if(x==0)flag=0;if(x==1)flag=1;if(x!=1&&x!=0)flag=2;}while(flag==1); /* flag为判断是否需要继续的函数继续查找时flag为1 用do-while控制循环*/if(flag==0){system("cls");inputchioce();}if(flag==2){system("cls");printf("选择有误,默认返回主菜单,请重新选择:\n");inputchioce();}}/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/void chaxuntushu_name(struct tushu_node*h) /* 按书名查询图书*/{int found,flag=1;char name[30];int x;struct tushu_node*p;do{found=0;p=h;printf("请输入需要查找的图书的书名:");scanf( "%s",name);printf("\n");while(p!=NULL){if(strcmp(p->name,name)==0){if(found==0)printf("\n编号类别书名作者出版社出版时间价格\n");printf("%d %s %s %s %s %s %lf\n",p->num,p->leibie,p->name,p->author,p->pr ess,p->time,p->price);found=1;}p=p->next;}if(found==0)printf("书名为《%s》的图书未找到!\n",name);printf("\n\n是否继续查找?(继续--1/返回主菜单--0)");scanf("%d",&x);if(x==0)flag=0;if(x==1)flag=1;if(x!=1&&x!=0)flag=2;}while(flag==1);if(flag==0){system("cls");inputchioce();}if(flag==2){system("cls");printf("选择有误,默认返回主菜单,请重新选择:\n");inputchioce();}}/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/void chaxuntushu_price(struct tushu_node*h) /* 按价格查询图书*/{int found,flag=1;double price;int x;struct tushu_node*p;do{found=0;p=h;printf("请输入需要查找的图书的价格:");scanf( "%lf",&price);printf("\n");while(p!=NULL){if(p->price==price){if(found==0)printf("\n编号类别书名作者出版社出版时间价格\n");printf("%d %s %s %s %s %s %lf\n",p->num,p->leibie,p->name,p->author,p->pr ess,p->time,p->price);found=1;}p=p->next;}if(found==0)printf("价格为%lf的图书未找到!\n",price);printf("\n\n是否继续查找?(继续--1/返回主菜单--0)");scanf("%d",&x);if(x==0)flag=0;if(x==1)flag=1;if(x!=1&&x!=0)flag=2;}while(flag==1);if(flag==0){system("cls");inputchioce();}if(flag==2){system("cls");printf("选择有误,默认返回主菜单,请重新选择:\n");inputchioce();}}/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/void paixutushu() /* 为图书排序的函数*/{int k;int n=0;struct tushu_node*head=NULL;head=wjtolb(head,&n);printf(" |++++++++++++++++++++++++ 为图书按规则排序+++++++++++++++++++++++++++++|\n");printf(" | 1-- 按价格为图书排序** ** 2-- 按出版时间为图书排序|\n");printf(" | 0-- 还回主菜单** |\n");printf("请你再次选择具体操作:");scanf ("%d",&k);system("cls"); /* 清屏*/switch(k){case 1:{head=paixutushu_price(head);sfjx();break;}case 2:{head=paixutushu_time(head);sfjx();break;}case 0:{inputchioce();break;}default:{system("cls");printf("选择有误,默认返回主菜单,请重新选择:\n");inputchioce();}break;}}/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/struct tushu_node* paixutushu_price(struct tushu_node *head) /* 为图书按价格排序的函数*/{int n;struct tushu_node*p1,*p2,*p3,*p4;int i,j;int size=sizeof(struct tushu_node);n=tongjitushu_shumu();p1=head;p2=head->next;if(head==NULL||head->next==NULL)return head;if(p2->next==NULL){if(p1->price<p2->price)return head;else{p2->next=p1;p1->next=NULL;head=p2;save(head);printf("\n\n 按价格排序操作已完成并保存完毕\n是否继续操作? 请选择(继续-1/退出-0)");return head;}}for(i=1;i<n;i++)p4=(struct tushu_node*)malloc(size);p4->next=head;p3=p4;p1=head;p2=head->next;for(j=0;j<n-i;j++){if(p2->price>p1->price){p3=p1;p1=p2;p2=p2->next;}else{p1->next =NULL;p1->next=p2->next;p3->next=p2;p2->next =p1;p3=p2;p2=p1->next;}}head=p4->next;free(p4);}save(head);printf("\n\n按价格排序操作已完成并保存完毕\n是否继续操作? 请选择(继续-1/退出-0)");return head;}/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/void sfjx() /* 写个小函数,判断是否继续,让程序更完美*/ {int x=-1;scanf("%d",&x);if(x==1){system("cls");inputchioce();}if(x==0)printf("\n\n谢谢你的使用!再见\n");exit(0);}if(x!=1&&x!=0){system("cls");printf("选择有误,默认返回主菜单,请重新选择:\n");inputchioce();}}/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/struct tushu_node* paixutushu_time(struct tushu_node *head) /* 为图书按出版时间排序的函数*/{int n;struct tushu_node*p1,*p2,*p3,*p4;int i,j;int size=sizeof(struct tushu_node);n=tongjitushu_shumu();p1=head;p2=head->next;if(head==NULL||head->next==NULL)return head;if(p2->next==NULL){if(strcmp(p1->time,p2->time)>0)return head;else{p2->next=p1;p1->next=NULL;head=p2;save(head);printf("\n\n按出版时间排序操作已完成并保存完毕\n是否继续操作? 请选择(继续-1/退出-0)");return head;}}for(i=1;i<n;i++){p4=(struct tushu_node*)malloc(size);p4->next=head;p3=p4;p1=head;p2=head->next;for(j=0;j<n-i;j++){if(strcmp(p1->time,p2->time)<0){p3=p1;p1=p2;p2=p2->next;}else{p1->next =NULL;p1->next=p2->next;p3->next=p2;p2->next =p1;p3=p2;p2=p1->next;}}head=p4->next;free(p4);}save(head);printf("\n\n 按出版时间排序操作已完成并保存完毕\n是否继续操作? 请选择(继续-1/退出-0)");return head;}/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/int tongjitushu_shumu() /* 统计图书数目的函数*/{int num;char leibie[10];char name[30];char author[20];char press[20];char time[20];double price;int x=-1,n=0;if((fpp=fopen("1.txt","r"))==NULL){printf(" 打开文件失败!");exit(0);}else{while(!feof(fpp)){fscanf(fpp,"%d%s%s%s%s%s%lf",&num,leibie,name,author,press,time,&price);n++;}}if(fclose(fpp)){printf("关闭文件失败!\n");exit(0);}printf("共有%d本图书",n-1);return n-1 ;}/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*//*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*//*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/void shiyongshuoming() /* 使用说明的函数*/{int x=-1;system("cls");printf("\n\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~使用说明~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n ");printf(" 你好,欢迎使用本图书管理系统!\n 1.首先你需要获得本系统的使用权限,进入本系统后,你有三次输入密码");printf("的机会,在三次内输入正确密码即可获得使用权限,三次输入错误后,系统将自动退出。

图书管理系统源代码

图书管理系统源代码

#include<iostream>#include<string>#include<fstream>#include<strstream>#include<sstream>using namespace std;//定义类class Book{ public:char name[80];char auther[80];int num;//定义一个输出函数void out(){ cout<<"书名:"<<name<<" "<<"作者:"<<auther<<" "<<"数量:"<<num<<endl;}};//定义暂时存储数据的数组Book booklist[20];//寻找数组中空位的函数int locate1(){int z=0;while(z<20){if(booklist[z].name[0]=='n'&&booklist[z].name[1]=='u'&&booklist[z].name[2]=='l'&&booklist[z].name[3]=='l'){return z; //如果书名为null表示当前是空位则返回此位置}else{z++;}}}//依据书名和作者寻找书的位置int locate2(char m[80],char n[80]){int a=0;while(a<20){if(strcmp(n, booklist[a].auther)==0&&strcmp(m, booklist[a].name)==0){return a;break; //若书名和作者均符合则返回此位置并跳出}else{a++;}}if(a=20){return 20;}}//依据书名寻找书的位置int locate3(char m[80]){int a=0;while(a<20){if(strcmp(m, booklist[a].name)==0){return a; //书名相同即返回此位置break;}else{a++;}}if(a=20){return 20;}}//借书函数void borrow(){void menu();system("cls"); //刷新屏幕if(booklist[0].name[0]=='n'&&booklist[0].name[1]=='u'&&booklist[0 ].name[2]=='l'&&booklist[0].name[3]=='l'){cout<<"库中无图书,暂不能借书!\n";}else{system("cls");char m[80],n[80];cout<<"请输入要借阅的书名:(空格用下划线代替)"<<endl;cin>>m;cout<<"请输入要借阅的书作者:(空格用下划线代替)"<<endl;cin>>n;int l=locate2(m,n); //依据书名和作者定位if(l==20){cout<<"书库中无此书"<<endl;}else{if(booklist[l].num==0){system("cls");cout<<"抱歉,该书全部借出。

图书管理系统程序代码

图书管理系统程序代码

#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{("结束");}}}}。

图书管理系统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);

图书管理系统代码

图书管理系统代码

图书管理系统代码//***********************//图书馆管理系统//***********************#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<stdio.h>#include <stdlib.h>#include <string.h>#include <windows.h>#define N 2struct book{int num;char name[20];char author[10];int cla;char pub_org[21];int time;int price;}book[N];void BookType();void BookScan();void BookConsult();void BookDelete();void BookModify();void showMenu();void file_load();void showMenu(){int i;file_load();do{printf("\n*********MENU*********\n");printf("1----------录入功能---------\n");printf("2----------浏览功能---------\n");printf("3----------查询功能---------\n");printf("4----------删除功能---------\n");printf("5----------修改功能---------\n");printf("6----------退出系统---------\n");printf("Your choice:");scanf("%d",&i);switch(i){case 1:system("cls");BookType();system("cls");continue;/*录入图书*/case 2:system("cls");BookScan();system("pause");system("cls");continue;/*浏览图书*/case 3:system("cls");BookConsult();system("cls");continue;/*图书查询*/case 4:system("cls");BookDelete();system("cls");continue;/*删除一本图书资料*/case 5:system("cls");BookModify();system("cls");continue;/*修改*/case 6:exit(0);default :printf("\n命令错误,请重新输入\n");fflush(stdin);getchar();system("cls");showMenu();}}while(1);}void BookType(){int a;void file_save();for(a=0;a<N;a++){printf("\ninput num:");scanf("%d",&book[a].num);printf("\ninput name:");scanf("%s",book[a].name);getchar();printf("\ninput author:");scanf("%s",book[a].author);getchar();printf("\ninput cla:");scanf("%d",&book[a].cla);getchar();printf("\ninput org:");scanf("%s",book[a].pub_org);getchar();printf("\ninput time:");scanf("%d",&book[a].time);printf("\ninput price:");scanf("%d",&book[a].price);}file_save();}void file_save(){FILE *fp;struct book *p=book;fp=fopen("a.dat","wb");for(int i=0;i<N;i++){fwrite(p,sizeof(struct book),1,fp);p++;}fclose(fp);}void file_load(){FILE *fp;struct book *p=book;if((fp=fopen("a.dat","rb"))==NULL){printf("书籍信息尚未建立,请先建立");return;}for(int i=0;i<N;i++){fread(p,sizeof(struct book),1,fp);p++;}fclose(fp);}void BookScan() /*输入录入号,浏览图书信息*/{int i,number,flag=1;printf("Input book's number:\n");scanf("%d",&number);for(i=0;i<N;i++)if(book[i].num==number){printf("name=%s\nauthor=%s\ncla=%d\npub_org=%s\ntime=%d\nprice=%d\n",book[i].nam e,book[i].author,book[i].cla,book[i].pub_org,book[i].time,book[i].price);flag=0;break;}if(flag)printf("未找到所要浏览的图书,请重新输入\n");}void BookConsult() /*输入书名或作者名,查询图书信息*/{char c;char name[20];char author[20];int i,j=0;i=0;printf("a-----按书名查询\n");printf("b-----按作者查询\n");printf("选择查询的方式:");fflush(stdin);c=getchar();switch(c){case 'a':printf("Input the book's name :");scanf("%s",&name);getchar();for(i=0;i<N;i++)if(!strcmp(name,book[i].name)){printf("num=%d\nauthor=%s\ncla=%d\npub_org=%s\ntime=%d\nprice=%d\n",book[i].num, book[i].author,book[i].cla,book[i].pub_org,book[i].time,book[i].price);j++;}if(j==0){printf("没有找到,请重新输入\n");getchar();}getchar();break;case 'b':printf("Input the book's author :\n");scanf("%s",&author);getchar();for(i=0;i<N;i++)if(!strcmp(author,book[i].author)){printf("num=%d\nname=%s\ncla=%d\npub_org=%s\ntime=%d\nprice=%d\n",book[i].num,b ook[i].name,book[i].cla,book[i].pub_org,book[i].time,book[i].price);j++;}if(j==0){printf("没有找到,请重新输入\n");getchar();}getchar();break;default:printf("选择有误!");fflush(stdin);getchar();system("cls");BookConsult();}}void BookDelete() /*输入录入号,删除图书*/{int i,k,n;int num;char yes_no;for(i=0;i<N;i++)printf("book[%d].num=%d\n",i,book[i].num);do{printf("\n input the book's number:");scanf("%d",&num);for(k=0;k<n;k++)if(book[k].num==num) break;if(k<10){for(i=k;i<n;i++)book[i].num=book[i+1].num;n=n-1;printf("删除第%d本图书\n",k);}elseprintf("命令错误,请重新输入\n");printf("n=%d\n",n);for(i=0;i<n;i++)printf("book[%d].num=%d\n",i,book[i].num);printf("\ncontinue to delete books:(y/n)?\n");do{yes_no=getchar();}while(yes_no!='Y'&&yes_no!='y'&&yes_no!='N'&&yes_no!='n');}while(yes_no=='Y'||yes_no=='y');}void BookModify() /*输入书名,修改图书*/ {char name[20];int i,flag=1;gets(name);i=0;while(strcmp(name,book[i].name)==0){if(name[i]=='\0'&&book[i].name=='\0'){flag=0;break;}i++;}if(flag)printf("\ncan't find the book");elseprintf("\nmodify the book");}void main(){showMenu();}。

图书馆管理系统代码

图书馆管理系统代码

图书馆管理系统代码#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)。
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];
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---按作者查询信息并输出
#include <stdio、h>
#include <string、h>
#include <stdlib、h>
#define SIZE (struct booklist *)malloc(sizeof(struct booklist))
//建立已借阅图书信息结构体
struct borrow
{
char borbook_num[10];
struct booklist *scanf1_(void); //输入单个图书源数据
void exchange(struct booklist *,struct booklist *) ;//交换两个结构体内的内容
struct borrow *tianjia1_(struct borrow *borrow_head,struct booklist *p); //添加一个struct borrow结构体的数据
struct booklist *shanchu(struct booklist *,struct borrow *,struct prebor_stu *); //9---删除数据
struct borrow *shanchu2_(struct borrow *,struct borrow *); //删除一个struct borrow结构体的数据
void borstore(struct borrow *borrow_head); //保存已借阅图书信息到文件borrowlist、txt
//重新保存修改后的预借阅信息到文件prebor_stulist、txt (全部覆盖)
void prestore(struct prebor_stu *pre_head);
struct borr表
struct booklist *charu(struct booklist *head,struct borrow *borrow_head); //8---将图书的数据到顺序排放的链表中,且插入后也就是顺序排放的
struct booklist *load(void); //5---从文件读入图书信息
struct booklist *num_paixu(struct booklist *); //4---按编号排序
struct booklist *price_paixu(struct booklist *); //3---按价格顺序排序
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---输出链表中的图书信息*/
void chaxun3_(struct booklist *,struct prebor_stu *,struct borrow *); //7---查询某类别图书信息并自动输出
void chaxun4_(struct borrow *,prebor_stu *,struct booklist *); //7---按学号查询借阅信息
struct prebor_stu *shanchu3_(struct prebor_stu *,struct prebor_stu *); //删除一个struct prebor_stu结构体的数据
void xiugai(struct booklist *,struct borrow *,struct prebor_stu *); //10---修改数据
int pre_creat(struct booklist *head); //学生登录系统预借图书并将信息存入文件prebor_stulist、txt
struct prebor_stu *prebor_creat(void); //创建预借阅图书信息链表
void printf1_(struct booklist *); //输出单个基本图书的数据
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 condition[10];
struct booklist *next;
};
struct booklist *create(void); /*创建图书信息链表*/
struct borrow *borrow_creat(struct booklist *head); //创建已借阅图书信息链表
相关文档
最新文档