diff --git a/zzh.h b/zzh.h new file mode 100644 index 0000000..d8e1826 --- /dev/null +++ b/zzh.h @@ -0,0 +1,943 @@ +#include +#include +#include +#include +#include +#include +#include +#define BACKSPACE 8 +#define PASS_MAXLEN 128 +#define LEN sizeof(struct Book) +#define LEN1 sizeof(struct reader) +//建立书籍的结构体 +void toxy(int x, int y)//定位光标位置到指定坐标 +{ + HANDLE hOut; + hOut = GetStdHandle(STD_OUTPUT_HANDLE); + COORD pos = { x,y }; + SetConsoleCursorPosition(hOut, pos); +} +struct Book//图书信息 +{ + char num[20],nam[20],aut[20],pub[20],cat[20]; + int many; + float price; + struct Book *next; +}; +struct reader//读者信息 +{ + int xuehao; + char username[20],time[20],name[20]; + struct reader *next; +}; +void home();//注册总页面 +void Reg();//注册 +void Log();//登录 +void Adm();//管理员 +int UserMenu();//用户主页 +int AdminMenu();//管理员主页 +void BroBook();//借书 +void BacBook();//还书 +void LooBook(int n);//查询书籍 +void AddBook();//添加书籍 +void DelBook();//删除书籍 +void FixBook();//修改书籍 +int Total();//统计书的总数 +int Total1();//统计账户总数->用于修改用户名重复的问题 +int Total2();//统计读者总数 +void SBAll(int q);//查询所有书籍 +void SBAut(int q);//图书作者查询 +void SBNam(int q);//图书名字查询 +void SBCat(int q);//图书分类查询 +void ed();//结束 +void Reader();//读者借阅信息 +void Readername();//按名字查找借阅 +void Allreader();//所有查看 + +void ed(void) +{ + system("cls"); + printf("******************************************************************************************\n"); + printf("* 图书管理系统(Version 2.0) *\n"); + printf("******************************************************************************************\n"); + printf("* *\n"); + printf("* *\n"); + printf("* 酱,拜拜咯ヾ(·ω·`)o *\n"); + printf("* *\n"); + printf("* *\n"); + printf("******************************************************************************************\n"); + Sleep(1000); + system("cls"); + home(); +} +//管理员菜单 +int AdminMenu(){ + system("cls"); + char t[10]; + while(1){ + printf("******************************************************************************************\n"); + printf("* 图书管理系统(Version 2.0) *\n"); + printf("******************************************************************************************\n"); + printf("* *\n"); + printf("* kuo`ni`ji`wa,我的主人: *\n"); + printf("* *\n"); + printf("* 有什么能为您效劳的吗~ *\n"); + printf("* *\n"); + printf("* 1、增加图书。 *\n"); + printf("* *\n"); + printf("* 2、删除图书。 *\n"); + printf("* *\n"); + printf("* 3、查询图书。 *\n"); + printf("* *\n"); + printf("* 4、修改图书信息。 *\n"); + printf("* *\n"); + printf("* 5、查询读者借阅信息 *\n"); + printf("* *\n"); + printf("* 6、没事了,退出。 *\n"); + printf("* *\n"); + printf("******************************************************************************************\n"); + printf("\n\n\t\t\t\t\t\t\t\t\t您想执行的操作:"); + scanf("%s",&t); + if(strcmp(t,"1")==0){ + AddBook(); + break; + }else if(strcmp(t,"2")==0){ + DelBook(); + break; + }else if(strcmp(t,"3")==0){ + LooBook(1); + break; + }else if(strcmp(t,"4")==0){ + FixBook(); + break; + }else if(strcmp(t,"6")==0){ + ed(); + }else if(strcmp(t,"5")==0){ + Reader(); + } + } +} +void LooBook(int n){ + system("cls"); + while(1){ + char t; + printf("******************************************************************************************\n"); + printf("* 图书管理系统(Version 2.0) *\n"); + printf("******************************************************************************************\n"); + printf("* *\n"); + printf("* 搜索方式: *\n"); + printf("* *\n"); + printf("* 1、按书名查找 *\n"); + printf("* *\n"); + printf("* 2、按作者查找 *\n"); + printf("* *\n"); + printf("* 3、按分类查找 *\n"); + printf("* *\n"); + printf("* 4、全书总览 *\n"); + printf("* *\n"); + printf("* *\n"); + printf("* 按ESC返回 *\n"); + printf("******************************************************************************************\n"); + printf("\n\n\t\t\t\t\t\t\t\t\t您想执行的操作:"); + t=getch(); + while(t!='1'&&t!='2'&&t!='3'&&t!='4'&&t!=27){ + t=getch(); + continue; + } + if(t=='1'){ + SBNam(n); + break; + }else if(t=='2'){ + SBAut(n); + break; + }else if(t=='3'){ + SBCat(n); + break; + }else if(t=='4'){ + SBAll(n); + break; + } + else if(t==27){ + if(n==0){ + UserMenu(); + }else if(n==1){ + AdminMenu(); + } + break; + } + + } +} + +void SBAll(int q){ + system("cls"); + int n=0; + int m=0,Many=0; + float Price=0; + char t,ReName[100]; + int i=0,k=0,j=0; + char Num[20]={'\0'},Aut[20]={'\0'},Pub[20]={'\0'},Nam[20]={'\0'},Cat[20]={'\0'}; + FILE *fp; + fp=fopen("图书.txt","r"); + if(fp=NULL){ + system("cls"); + printf("出错了,请联系管理员,按Esc键返回\n"); + t=getch(); + for(;t!=27;) + t=getch(); + if(q==0){ + UserMenu(); + }else if(q==1){ + AdminMenu(); + } + }else{ + j=Total(); + fp=fopen("图书.txt","r"); + for(int m=0;mnext =p1; + p2=p1; + p1=(struct Book*)malloc(LEN); + } + strcpy(p1->num,Num);//复制书号 + strcpy(p1->nam,Nam);//复制书名 + strcpy(p1->aut,Aut);//复制作者名字 + strcpy(p1->pub,Pub);//复制出版社 + strcpy(p1->cat,Cat);//复制类别 + p1->many=Many;//复制个数 + p1->price=Price;//复制单价 + } + } + if(n==0){ + head=NULL; + }else{ + p2->next=p1; + p1->next=NULL; + fclose(fp); + } +} + fp=fopen("图书.txt","w"); + fclose(fp); + fp=fopen("图书.txt","a"); + p=head; + + for(;p!=NULL;){ + fprintf(fp,"%-8s%-9s%-14s%-16s%-18s%-7d%-8.2f\n",p->num,p->nam,p->aut,p->pub,p->cat,p->many,p->price); + p=p->next; + } + fclose(fp); + system("cls"); + printf("删除成功,按任意键返回上一层\n"); + t=getch(); + AdminMenu(); +} + +//修改书籍 +void FixBook(){ + system("cls"); + struct Book *head,*p1,*p2,*p; + int i,n; + char Rename[100]; + char Num[20],Nam[20],Aut[20],Pub[20],Cat[20]; + int Many; + float Price; + printf("请输入您要修改图书的书名:"); + scanf("%s",Rename); + FILE *fp; + fp = fopen("图书.txt","r"); + n = Total(); + int count=0; + int k=0; + for(i=0;inext=p1; + p2=p1; + p1=(struct Book*)malloc(LEN); + } + strcpy(p1->num,Num);//复制书号 + strcpy(p1->nam,Nam);//复制书名 + strcpy(p1->aut,Aut);//复制作者名字 + strcpy(p1->pub,Pub);//复制出版社 + strcpy(p1->cat,Cat);//复制类别 + p1->many=Many;//复制个数 + p1->price=Price;//复制单价 + } + } + if(n==0){ + head = NULL; + } + else{ + p2->next=p1; + p1->next=NULL; + fclose(fp); + } + fp=fopen("图书.txt","w"); + fclose(fp); + fp=fopen("图书.txt","a"); + p=head; + + for(;p!=NULL;){ + fprintf(fp,"%-8s%-9s%-14s%-16s%-18s%-7d%-8.2f\n",p->num,p->nam,p->aut,p->pub,p->cat,p->many,p->price); + p=p->next; + } + fclose(fp); + fp = fopen("图书.txt","a"); + system("cls"); + printf("请输入书号:");scanf("%s",Num); + printf("请输入书名:");scanf("%s",Nam); + printf("请输入作者:");scanf("%s",Aut); + printf("请输入出版社:");scanf("%s",Pub); + printf("请输入图书类别:");scanf("%s",Cat); + printf("请输入图书数量:");scanf("%d",&Many); + printf("请输入图书价格(最多两位小数):");scanf("%f",&Price); + fprintf(fp,"%-8s%-9s%-14s%-16s%-18s%-7d%-8.2f\n",Num,Nam,Aut,Pub,Cat,Many,Price); + system("cls"); + printf("\n\n\n"); + printf("\t\t\t┌──────────────────────────────────────────────┐\n"); + printf("\t\t\t│ │\n"); + printf("\t\t\t│ │\n"); + printf("\t\t\t│ 正在写入图书信息. │\n"); + printf("\t\t\t│ │\n"); + printf("\t\t\t│ │\n"); + printf("\t\t\t└──────────────────────────────────────────────┘\n"); + Sleep(500); + system("cls"); + printf("\n\n\n"); + printf("\t\t\t┌──────────────────────────────────────────────┐\n"); + printf("\t\t\t│ │\n"); + printf("\t\t\t│ │\n"); + printf("\t\t\t│ 正在写入图书信息.. │\n"); + printf("\t\t\t│ │\n"); + printf("\t\t\t│ │\n"); + printf("\t\t\t└──────────────────────────────────────────────┘\n"); + Sleep(500); + system("cls"); + printf("\n\n\n"); + printf("\t\t\t┌──────────────────────────────────────────────┐\n"); + printf("\t\t\t│ │\n"); + printf("\t\t\t│ │\n"); + printf("\t\t\t│ 正在写入图书信息... │\n"); + printf("\t\t\t│ │\n"); + printf("\t\t\t│ │\n"); + printf("\t\t\t└──────────────────────────────────────────────┘\n"); + Sleep(500); + system("cls"); + printf("\n\n\n"); + printf("\t\t\t┌──────────────────────────────────────────────┐\n"); + printf("\t\t\t│ │\n"); + printf("\t\t\t│ │\n"); + printf("\t\t\t│ 正在写入图书信息. │\n"); + printf("\t\t\t│ │\n"); + printf("\t\t\t│ │\n"); + printf("\t\t\t└──────────────────────────────────────────────┘\n"); + Sleep(500); + system("cls"); + printf("\n\n\n"); + printf("\t\t\t┌──────────────────────────────────────────────┐\n"); + printf("\t\t\t│ │\n"); + printf("\t\t\t│ │\n"); + printf("\t\t\t│ 正在写入图书信息.. │\n"); + printf("\t\t\t│ │\n"); + printf("\t\t\t│ │\n"); + printf("\t\t\t└──────────────────────────────────────────────┘\n"); + Sleep(500); + system("cls"); + printf("\n\n\n"); + printf("\t\t\t┌──────────────────────────────────────────────┐\n"); + printf("\t\t\t│ │\n"); + printf("\t\t\t│ 操作成功,是否要继续? │\n"); + printf("\t\t\t│ │\n"); + printf("\t\t\t├───────────────────────┬──────────────────────│\n"); + printf("\t\t\t│ 1.是 │ 2.否 │\n"); + printf("\t\t\t└───────────────────────┴ ─────────────────────┘\n"); + fclose(fp); + char t; + while(1) //利用死循环可有效防止其他按键干扰 + { + t=getch(); + if(t=='1') AddBook(); + else if(t=='2') AdminMenu(); + } +} + //统计图书数量 +int Total(){ + FILE *fp; + int txcl=0,n; + float tprice=0; + char tname[20]={'\0'},tauthor[20]={'\0'},tchuban[20]={'\0'},tkind[20]={'\0'},tshuhao[20]={'\0'}; + + fp=fopen("图书.txt","r");//打开文件 + + for (n=0;!feof(fp);n++)//逐个读文件 + fscanf(fp,"%s%s%s%s%s%d%f",tshuhao,tname,tauthor,tchuban,tkind,&txcl,&tprice); + n--;//减去最后一个 + fclose(fp);//关闭文件 + return (n);//返回个数 +} +//统计账号数量 +int Total1(){ + int n; + char name[100],password[100]; + FILE *fp=fopen("账号管理.txt","r"); + for(n=0;!feof(fp);n++){ + fscanf(fp,"%s%s",name,password); + } + n--; + fclose(fp); + return (n); +} +//统计读者数量 +int Total2(){ + int n; + int num; + char username[20],time[20],name[20]; + FILE *fp=fopen("读者.txt","r"); + for(n=0;!feof(fp);n++){ + fscanf(fp,"%d%s%s%s",&num,username,time,name); + } + n--; + fclose(fp); + return (n); +} +void Reader() +{ + system("cls"); + printf("******************************************************************************************\n"); + printf("* 图书管理系统(Version 2.0) *\n"); + printf("******************************************************************************************\n"); + printf("* *\n"); + printf("* 搜索方式: *\n"); + printf("* *\n"); + printf("* 1、按账号查找 *\n"); + printf("* *\n"); + printf("* 2、所有借书总览 *\n"); + printf("* *\n"); + printf("* 按ESC返回 *\n"); + printf("******************************************************************************************\n"); + printf("\n\n\t\t\t\t\t\t\t\t\t您想执行的操作:"); + char op; + while(1) + { + op = getch(); + if(op=='1') Readername(); + else if(op=='2') Allreader(); + else if(op==27) AdminMenu(); + } +} + +void Readername() +{ + system("cls"); + printf("您想查看的读者的名字:"); + char Name[100]; + char username[100],time[100],name[100]; + int num; + scanf("%s",Name); + FILE *fp; + fp = fopen("读者.txt","r"); + int n = Total2(); + int i;int count=0; + for(i=0;i