发布网友 发布时间:2022-04-21 23:28
共1个回答
热心网友 时间:2024-02-15 22:14
#include#include#include#include#includestructbook{charnumber[100];chartittle[100];charwriter[100];charpublisher[100];chardate[100];charprice[100];charstatus[100];charreader[100];};voidsearch_book();voidborrow_book();voidreturn_book();voidadd_book();voiddelete_book();voidmodify_book();voidscan_book();intmain(){intc1=0,c2,c3;intl,x,z;while(1){system("color2C");printf("\t\t\t^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^\n");printf("\t\t\t|*-*-*-图书管理系统*-*-*|\n");printf("\t\t\t*[1]用户登录*\n");printf("\t\t\t*[2]管理员登录*\n");printf("\t\t\t^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^\n");printf("\n");printf("请选择你的操作:");scanf("%d",&c1);system("cls");break;}if(c1==1){while(1){system("color2C");printf("\t\t\t^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^\n");printf("\t\t\t|*-*-*-图书管理系统*-*-*|\n");printf("\t\t\t*[1]查询图书*\n");printf("\t\t\t|[2]借阅图书|\n");printf("\t\t\t*[3]借还图书*\n");printf("\t\t\t*[4]浏览图书信息*\n");printf("\t\t\t|[5]退出图书管理系统|\n");printf("\t\t\t^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^\n");printf("\n");printf("请选择你的操作:");scanf("%d",&c2);getchar();switch(c2){case1:search_book();break;case2:borrow_book();break;case3:return_book();break;case4:scan_book();break;case5:system("cls");return0;}}}if(c1==2){while(1){system("color2C");printf("\t\t\t^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^\n");printf("\t\t\t|*-*-*-图书管理系统*-*-*|\n");printf("\t\t\t|[1]添加图书|\n");printf("\t\t\t*[2]删减图书*\n");printf("\t\t\t|[3]修改图书信息|\n");printf("\t\t\t*[4]浏览图书信息*\n");printf("\t\t\t|[5]退出图书管理系统|\n");printf("\t\t\t^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^\n");printf("\n");printf("请选择你的操作:");scanf("%d",&c3);getchar();switch(c3){case1:add_book();break;case2:delete_book();break;case3:modify_book();break;case4:scan_book();break;case5:system("cls");return0;}}}}/*查询图书*/voidsearch_book(){FILE*fp;structbookn;structbooknn;intl,r;charx,z;fp=fopen("F:\\课程设计\\图书管理系统.txt","rb");while(1){l=0;system("cls");printf("请输入图书名称:");scanf("%s",n.tittle);fflush(stdin);rewind(fp);while(1){fread(&nn,sizeof(nn),1,fp);if(feof(fp))break;r=strcmp(n.tittle,nn.tittle);if(r==0){l=1;break;}}if(l==0){printf("没有要查询的图书!!!\n\n");}else{printf("查询的图书为:");printf("\n");printf("****************************************\n");printf("编号书名作者出版社出版时间价格状态借阅者\n");printf("\n");printf("%s%s%s%s%s%s%s",nn.number,nn.tittle,nn.writer,nn.publisher,nn.date,nn.price,nn.status,nn.reader);printf("\n\n\n");}printf("是否继续查询图书?[是(y)/否(n)]?\n\n");do{x=getche();}while(x!='n'&&x!='y');if(x=='n')break;}fclose(fp);system("cls");}//添加voidadd_book(){FILE*fp;structbookn;structbooknn;charx,z;intl,r;fp=fopen("F:\\课程设计\\图书管理系统.txt","ab+");do{system("cls");do{l=0;printf("\n");printf("编号书名作者出版社出版时间价格状态借阅者\n");fflush(stdin);scanf("%s%s%s%s%s%s%s%s",n.number,n.tittle,n.writer,n.publisher,n.date,n.price,n.status,n.reader);system("cls");rewind(fp);while(!feof(fp)){fread(&nn,sizeof(nn),1,fp);r=strcmp(n.tittle,nn.tittle);if(r==0){l=1;printf("该图书已存在,请输入新的图书信息:\n\n");break;}}}while(l);fwrite(&n,sizeof(n),1,fp);printf("\n");printf("是否继续输入新的图书信息[y/n]\n\n");do{x=getche();}while(x!='n'&&x!='y');}while(x=='y');fclose(fp);system("cls");}//删除图书voiddelete_book(){FILE*fp,*fp1;charx,z;structbookn;structbooknn;intl,r;fp=fopen("F:\\课程设计\\图书管理系统.txt","ab+");while(1){l=0;system("cls");printf("\n");printf("请输入需要删除的图书名:\n\n");fflush(stdin);scanf("%s",&n.tittle);rewind(fp);while(1){fread(&nn,sizeof(nn),1,fp);if(feof(fp))break;r=strcmp(n.tittle,nn.tittle);if(r==0){l=1;break;}}if(l==0){printf("\n");printf("对不起,未找到该图书\n");}else{printf("\n");printf("****************************************\n");printf("编号书名作者出版社出版时间价格状态借阅者\n");printf("\n");printf("%s%s%s%s%s%s%s%s",nn.number,nn.tittle,nn.writer,nn.publisher,nn.date,nn.price,nn.status,nn.reader);printf("\n");printf("确认删除图书信息?[是(y)/否(n)]\n\n");do{z=getche();}while(z!='n'&&z!='y');if(z=='n')break;else{fp1=fopen("F:\\课程设计\\图书管理系统new.txt","wb");rewind(fp);while(1){fread(&nn,sizeof(nn),1,fp);if(feof(fp))break;r=strcmp(n.tittle,nn.tittle);if(r!=0)fwrite(&nn,sizeof(nn),1,fp1);}fclose(fp);fclose(fp1);fp=fopen("F:\\课程设计\\图书管理系统.txt","wb");fp1=fopen("F:\\课程设计\\图书管理系统new.txt","rb");while(1){fread(&nn,sizeof(nn),1,fp1);if(feof(fp1))break;fwrite(&nn,sizeof(nn),1,fp);}fclose(fp);fclose(fp1);}}printf("\n");printf("是否继续删除图书信息?[是(y)/否(n)]\n");do{x=getche();}while(x!='n'&&x!='y');if(x=='n')break;}fclose(fp);system("cls");}//修改图书信息voidmodify_book(){FILE*fp;structbookn;structbooknn;intl,r;charx,z;fp=fopen("F:\\课程设计\\图书管理系统.txt","rb+");while(1){l=0;printf("\n");system("cls");printf("请输入需要修改的图书名:\n\n");fflush(stdin);scanf("%s",&n.tittle);system("cls");rewind(fp);while(1){fread(&nn,sizeof(nn),1,fp);if(feof(fp))break;r=strcmp(n.tittle,nn.tittle);if(r==0){l=1;break;}}if(l==0){printf("\n");printf("对不起,未找到该图书信息\n\n");}else{printf("\n");printf("****************************************\n");printf("编号书名作者出版社出版时间价格状态借阅者\n");printf("\n");printf("%s%s%s%s%s%s%s%s",nn.number,nn.tittle,nn.writer,nn.publisher,nn.date,nn.price,nn.status,nn.reader);printf("请依次修改图书信息\n\n\n");fflush(stdin);scanf("%s%s%s%s%s%s%s%s",n.number,n.tittle,n.writer,n.publisher,n.date,n.price,n.status,n.reader);fseek(fp,sizeof(nn),1);fwrite(&n,sizeof(nn),1,fp);}printf("\n");printf("是否继续修改用户信息[y/n]?\n\n");do{x=getch();}while(x!='n'&&x!='y');if(x=='n')break;}fclose(fp);system("cls");}//借书voidborrow_book(){FILE*fp;structbookn;structbooknn;charx,z;intl,r;fp=fopen("F:\\课程设计\\图书管理系统.txt","rb+");while(1){l=0;system("cls");printf("\n");printf("请输入需要借阅的图书名:\n");fflush(stdin);scanf("%s",&n.tittle);rewind(fp);while(1){fread(&nn,sizeof(nn),1,fp);if(feof(fp))break;r=strcmp(n.tittle,nn.tittle);if(r==0){l=1;break;}}if(l==0){printf("\n");printf("对不起,未找到该图书。\n");}else{printf("\n");printf("****************************************\n");printf("编号书名作者出版社出版时间价格状态借阅者\n");printf("\n");printf("%s%s%s%s%s%s%s%s",nn.number,nn.tittle,nn.writer,nn.publisher,nn.date,nn.price,nn.status,nn.reader);printf("\n");fflush(stdin);printf("请输入图书信息并修改在库状态及借阅者信息");printf("****************************************\n");printf("编号书名作者出版社出版时间价格状态借阅者\n");printf("\n");scanf("%s%s%s%s%s%s%s%s",n.number,n.tittle,n.writer,n.publisher,n.date,n.price,n.status,n.reader);fseek(fp,sizeof(nn),1);fwrite(&n,sizeof(nn),1,fp);}printf("\n");printf("是否继续借书?[是(y)/否(n)]\n\n");do{x=getch();}while(x!='n'&&x!='y');if(x=='n')break;}fclose(fp);system("cls");}//还书voidreturn_book(){FILE*fp;structbookn;structbooknn;charx,z;intl,r;fp=fopen("F:\\课程设计\\图书管理系统.txt","rb+");while(1){l=0;system("cls");printf("\n");printf("请输入需要借还的图书名:\n");fflush(stdin);scanf("%s",&n.tittle);rewind(fp);while(1){fread(&nn,sizeof(nn),1,fp);if(feof(fp))break;r=strcmp(n.tittle,nn.tittle);if(r==0){l=1;break;}}if(l==0){printf("\n");printf("对不起,未找到该图书。\n");}else{printf("\n");printf("****************************************\n");printf("编号书名作者出版社出版时间价格状态借阅者\n");printf("\n");printf("%s%s%s%s%s%s%s%s",nn.number,nn.tittle,nn.writer,nn.publisher,nn.date,nn.price,nn.status,nn.reader);printf("\n");fflush(stdin);printf("请输入图书信息并修改在库状态\n\n");printf("****************************************\n");printf("编号书名作者出版社出版时间价格状态借阅者\n");printf("\n");scanf("%s%s%s%s%s%s%s%s",n.number,n.tittle,n.writer,n.publisher,n.date,n.price,n.status,n.reader);fseek(fp,-(int)sizeof(nn),1);fwrite(&n,sizeof(nn),1,fp);}printf("\n");printf("是否继续还书?[是(y)/否(n)]\n");do{x=getche();}while(x!='n'&&x!='y');if(x=='n')break;}fclose(fp);system("cls");}//浏览voidscan_book(){FILE*fp;charx,z;structbookn;fp=fopen("F:\\课程设计\\图书管理系统.txt","rb");rewind(fp);system("cls");while(1){fread(&n,sizeof(n),1,fp);if(feof(fp))break;else{printf("********************************************\n");printf("编号书名作者出版社出版时间价格状态借阅者\n");printf("\n");printf("%s%s%s%s%s%s%s%s",n.number,n.tittle,n.writer,n.publisher,n.date,n.price,n.status,n.reader);printf("\n");}}printf("\n");printf("回到主菜单请按回车");do{x=getche();}while(x!='\r');if(x=='\r'){fclose(fp);system("cls");}}