需求分析

图书馆作为文学的聚集地和展示平台,书籍是从古至今文化传递记载的介质。图书馆是高校不可缺少的基础设施,图书馆管理系统是图书馆正常运转的关键。此次数据库课程设计采用C++语言编写程序,实现图书登记、删除、查询、浏览、读者借阅、还书、会员登录、密码修改等功能。程序包括数据链表和文件指针的操作,包括结构数据的定义和使用,文件的读写、定位和修改。
橘猫书馆管理系统主要是完成对书籍,书的种类,学生借阅信息的管理,能够有效的查看借阅记录以及书籍信息。从而减轻书馆管理者的人工负担。书馆管理员首先完成对图书类别管理,图书信息的查询、增加、删除、修改等操作,以及学生借阅图书信息的查询、增加、删除等。


管理员默认密码为123456

代码实现

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string>
#include<math.h>
#include<cstdio>
#include <math.h>
#include <dos.h>
#include <windows.h>
#include<iostream>
#define  LEN   sizeof(struct library)
#define  LEN1  sizeof(struct reader)
#define LEN2 sizeof(struct land)
using namespace std;
int role;
struct library
{int xcl;//库存float price;//单价char name[20],author[20],chuban[20],kind[20],shuhao[20];struct library *next;
};
struct reader//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%读者结构体
{int zhenghao;char mingzi[20],riqi[20],zname[20];struct reader *next;
};
struct land//登录信息
{int zhanghao;char password[20];struct land*next;
};
int match(int m,char a[20])//匹配数据库中的账号密码
{void lmain();FILE*fp;int n=0,i=0;int zhanghao;char password[20];if ((fp=fopen("land.txt","r"))==NULL)//不存在读者文件{system ("cls");printf("\n 小主还没有创建该账号呢..喵!");getch();system("cls");lmain();}for(;!feof(fp);){fscanf(fp,"%d%s",&zhanghao,password);if(m==zhanghao){if(strcmp(a,password)==0)return 1;else{return -1;}}}return 0;}
// void lmain()//登录功能函数
//{//  void xgmm();
//  void lmenu();
//  void land();
//  void xinjian();
//  char choose;
//  lmenu();
//  scanf(" %c",&choose);
//  switch(choose)//功能函数
//  {//    case'1':
//      land();
//      break;
//    case'2':
//      xinjian();
//      break;
//      case'3':
//      xgmm();
//      break;
//    case'4':
//      system("cls");
//    getch();
//      exit(0);
//      system ("cls");
//  break;
//  }
//}
void xinjian()//新建账户密码
{void lmain();FILE *fp;int zhanghao;char password[20],password1[20];char hit=0;cout<"hhhh"; if ((fp=fopen("land.txt","r"))==NULL)//if语句:打开图书馆文件,不存在此文件则新建{fp=fopen("land.txt","w");fclose(fp);}system("cls");fp=fopen("land.txt","a");for(;;)//输入两次密码确认,两次相同才能确认{printf("\n请按以下格式输入账户:\n橘猫编号 橘猫密码\n");printf("请输入:");scanf("%d %s",&zhanghao,password);printf("再次输入密码:\n");scanf("%s",password1);printf("hhhh");printf("你输入的账号是%d",zhanghao);if(strcmp(password,password1)==0){fprintf(fp,"%d %s\n",zhanghao,password);break;}else{printf("两次输入密码不一致,继续创建按回车,退出按ESC");hit=getch();if(hit=27)system("cls");lmain();}}fclose(fp);printf("创建成功,按任意键返回");getch();system("cls");lmain();
}
void land()//输入账户密码的登录函数
{void main1();void lmain();void jieshuxitong(); int zhanghao;char password[20];int i=2,j,k,n;char hit=0;system("cls");do{printf("\输入橘猫账号吧:");scanf("%d",&zhanghao);printf("小主确认输入请按回车,要重新输入啦请按ECS键");hit=getch();//暂停程序当i接收后继续下一条指令for (;hit!=13&&hit!=27;)//保证只能是CR和ESC才能退出循环,输入其他字符无用,暂停程序,按'CR'继续。{hit=getch();}}while(hit==27);printf("\n小主请输入橘猫密码:");scanf("%s",password);i=match(zhanghao,password);if(i==1){printf("登陆成功啦...喵喵喵");getch();jieshuxitong();}else{if(i==-1){printf("小主的密码不正确呢!");getch(); land();}if(i==0)printf("没有这个橘猫账户喵");getch();system("cls"); lmain();}
}
int tjzs3()//统计账号密码文本个数
{FILE *fp;
int zhao=0,n;
char mm[20]={'\0'};
fp=fopen("land.txt","r");//打开文件
for (n=0;!feof(fp);n++)//逐个读文件
fscanf(fp,"%d %s",&zhao,mm);
n--;
fclose(fp);//关闭文件
return (n);//返回个数
}
void xg(int z,char m[20])//修改函数
{FILE *fp;int zhanghao1,n,j,k;char mima1[20];struct land *head,*p,*p1,*p2;fp=fopen("land.txt","r");j =tjzs3();for (k=0;k<=j;k++){fscanf(fp,"%d %s",&zhanghao1,mima1);if (z!=zhanghao1)//比较名字,将不同名字的信息复制到链表{n++;//相同返回值为0不执行if语句继续循环,不同则执行直到将所有不同的书名建立成链表if (n==1)//建立链表{p1=p2=(struct land*)malloc(LEN2);head=p1;}else{p2->next=p1;p2=p1;p1=(struct land*)malloc(LEN2);//新建链表}p1->zhanghao=zhanghao1;strcpy(p1->password,mima1);//复制账号密码}}if (n==0){head=NULL;}else//建立链表的最后剩余一个储存空间,所以封底{p2->next=p1;p1->next=NULL;fclose(fp);}fp=fopen("land.txt","w");//清空文件,只写打开,然后关闭fclose(fp);fp=fopen("land.txt","a");//追加文件p=head;for (;p!=NULL;)//把链表内容覆盖到文件{fprintf(fp,"%d %s%\n",p->zhanghao,p->password);p=p->next;}fprintf(fp,"%d %s\n",z,m);fclose(fp);system ("cls");}
void xgmm()//修改账户密码的函数
{void main1();  void lmain();FILE *fp;int zh=0,k=0,many=0,m=0,n=0;int chazhao,hit;char mima[20]={'\0'},password1[20]={'\0'};char  mm[20]={'\0'}; char i;if ((fp=fopen("land.txt","r"))==NULL)//打开文件{system ("cls");printf("\n记录文件不存在!按任意键返回");getch();system("cls");lmain();}system("cls");printf("请小主输入橘猫账号和橘猫密码:\n");scanf("%d %s",&chazhao,mima);m =tjzs3();for (n=0;n<=m;n++){fscanf(fp,"%d %s",&zh,mm);if(zh==chazhao){if(!strcmp(mm,mima)){printf("请输入新的橘猫密码");scanf("%s",mima);printf("再次输入橘猫密码喵:\n");scanf("%s",password1);if(strcmp(mima,password1)==0){xg(chazhao,mima);getch();lmain();system("cls");}else{printf("小主密码两次不一致喵");hit=getch();system("cls");lmain();}}else{printf("原来橘猫账户的旧密码错误,好可惜呀!");getch();system("cls");lmain();}}}printf("不存在此账号,按任意键返回");fclose(fp);//修改结束getch();system("cls");lmain();
}
void lmain()//登录功能函数
{void land();void xinjian();void lmenu();char choose;lmenu();scanf(" %c",&choose);switch(choose)//功能函数{case'1':land();break;case'2':xinjian();break;case'3':xgmm();break;case'4':system("cls");getch();exit(0);system ("cls");break;}
}
void lmenu()//显示登录菜单
{void pic3();pic3();
printf("\n    *******\t\t\t\t\t\t  橘猫登录系统                                                 *******\n");
printf("    **************************************************************************************************************************\n");
printf("    **************************************************************************************************************************\n");
printf("\n    *******\t\t\t\t\t\t  1.登录橘猫系统\n\n");
printf("\n    *******\t\t\t\t\t\t  2.创建橘猫账号\n\n");
printf("\n    *******\t\t\t\t\t\t  3.修改橘猫密码\n\n");
printf("\n    *******\t\t\t\t\t\t  4.退出橘猫系统\n\n");
printf("\n    *******\t\t\t\t\t\t 请按键选择,回车确定\n");
printf("    **************************************************************************************************************************\n");
printf("    **************************************************************************************************************************\n");
return ;
}
void pic1(){cout<<"\t\t\t\t\t\t\t ∧, ,,∧  oo    "<<endl;cout<<"\t\t\t\t\t\t\t/●   ● \       "<<endl;cout<<"\t\t\t\t\t\t\t╰/] - [\╯ "<<endl;printf("\n");printf("\n");
}
void pic2(){cout<<"\t\t\t\t      ∧_∧      ∧_∧      ∧_∧     ∧_∧ "<<endl;cout<<"\t\t\t\t     (^ .^)     (^ 、^)    (^ 0^)     (^ Д^)"<<endl;cout<<"\t\t\t\t--------∪-∪----------∪-∪--------∪-∪----------∪-∪-- "<<endl;printf("\n");printf("\n");
}
void pic3(){cout<<"\t\t\t\t\t\t╭-╮    ╭-╮"<<endl;cout<<"\t\t\t\t\t\t┃ ┃    ┃ ┃"<<endl;cout<<"\t\t\t\t\t\t┃ ゛”゛   ┃"<<endl;cout<<"\t\t\t\t\t\t┃   ┃ ┃   ┃"<<endl;cout<<"\t\t\t\t\t\tミ~~ · ~~ミ"<<endl;cout<<"\t\t\t\t\t\t╰━┳━┳ ╯"<<endl;cout<<"\t\t\t\t\t\t   ╭┫   ┣╮"<<endl;cout<<"\t\t\t\t\t\t   ┺┻┻┻┹ "<<endl;
}
void pic4(){cout<<"\t\t\t\t\t\t │\__╭╭╭╭╭__/│ "<<endl;cout<<"\t\t\t\t\t\t │           │  "<<endl;cout<<"\t\t\t\t\t\t │           │ "<<endl;cout<<"\t\t\t\t\t\t │ ●       ● │ "<<endl;cout<<"\t\t\t\t\t\t │≡  ╰┬┬┬╯  ≡│ "<<endl;cout<<"\t\t\t\t\t\t │    ╰—╯    │"<<endl;cout<<"\t\t\t\t\t\t ╰——┬O———O┬——╯ "<<endl;cout<<"\t\t\t\t\t\t     ╭—^__^—╮"<<endl;cout<<"\t\t\t\t\t\t     │〈=-﹏-=〉│ "<<endl;cout<<"\t\t\t\t\t\t   ╭═O════O═╮ "<<endl;cout<<"\t\t\t\t\t\t     │*   *  *│ "<<endl;cout<<"\t\t\t\t\t\t     │   *    │ "<<endl;cout<<"\t\t\t\t\t\t     │ *    * │  "<<endl;cout<<"\t\t\t\t\t\t    ╰════════╯ "<<endl;
}
void mainmenu()//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~主菜单
{ //system ("cls");//清除屏幕先前显示的内容 ,往下运行(在stdlib.h头文件中) printf("\n\n             ^.^ ^.^ ^.^ ^.^ ^.^.^ (= ̄ω ̄=)^.^ ^. ^ ^.^ ^.^ ^.^ ");printf("\n\n\n                       1.橘猫图书馆书籍系统\n\n");printf("\n\n                        2.橘猫读者借阅系统\n\n");printf("\n\n                         3.离开橘猫图书馆,喵喵喵\n\n");//printf("\n\n                     ^~^请您按键选择and回车确定哦~.~\n\n\n");printf("                ^.^ ^.^ ^.^ ^.^ ^.^ ^.(= ̄ω ̄=) ^.^ ^.^ ^.^ ^.^ ^.^ \n");
}void menu1() //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~显示 图书信息 菜单
{ system ("cls");pic3(); printf("\n\n\n               ^~^ ^~^ ^~^ ^~^ ^~^ ^~^ (= ̄ω ̄=) ^~^ ^~^ ^~^ ^~^ ^~^ ^~^ ^~^ ");printf("\n\n                          1.橘猫书籍入库\n\n");printf("\n                         2.橘猫书籍清除\n\n");printf("\n                         3.橘猫书籍查询\n\n");printf("\n                         4.预览橘猫书籍信息\n\n");printf("\n                       5.返回上一层,喵喵喵\n\n");//printf("\n                    ^~^请您按键选择and回车确定哦*.*\n\n");printf("                ^~^ ^~^ ^~^ ^~^ ^~^ ^~^ (= ̄ω ̄=) ^~^ ^~^ ^~^ ^~^ ^~^ ^~^ ^~^ \n");
}
void guanliyuanyanzheng(){void begin();string yaochi1="123456";string yaochi;printf("               (= ̄ω ̄=) 请小主输入开启橘猫管理员模式的密码吧");cin>>yaochi;printf("\n");if(yaochi==yaochi1){cout<<"           \t\t\t\t\t管理员模式开启成功"<<endl; printf("\n");}else{cout<<"             \t\t\t\t\t好像输入的密码不对呢,小主再试试吧"<<endl;printf("\n");begin();}
}
void menu2() //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~显示 借阅系统 菜单
{ system ("cls");printf("               (= ̄ω ̄=) \n");printf("小主可以任意输入书号,书名,作者或类别一项来进行查询:\n");//printf("类别(科学技术 语言文学 政治经济 历史地理 意识形态 艺术)\n\n");
}
void index1(){printf("    **************************************************************************************************************************\n");printf("    **************************************************************************************************************************\n");printf("    *******--------------------------------------------欢迎来到橘猫图书馆----------------------------------------------*******\n");printf("    **************************************************************************************************************************\n");printf("    **************************************************************************************************************************\n");
}
float f(float x, float y, float z) {float a = x * x + 9.0f / 4.0f * y * y + z * z - 1;return a * a * a - x * x * z * z * z - 9.0f / 80.0f * y * y * z * z * z;
}float h(float x, float z) {for (float y = 1.0f; y >= 0.0f; y -= 0.001f)if (f(x, y, z) <= 0.0f)return y;return 0.0f;
}
void index(){system("color 5E");for (float z = 1.5f; z > -1.5f; z -= 0.05f) {for (float x = -1.5f; x < 1.5f; x += 0.025f) {float v = f(x, 0.0f, z);if (v <= 0.0f) {float y0 = h(x, z);float ny = 0.01f;float nx = h(x + ny, z) - y0;float nz = h(x, z + ny) - y0;float nd = 1.0f / sqrtf(nx * nx + ny * ny + nz * nz);float d = (nx + ny - nz) * nd * 0.5f + 0.5f;putchar(".:-=+*#%@"[(int)(d * 5.0f)]);}elseputchar(' ');}putchar('\n');}Sleep(500);//system("color E4");
}
void main1()//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~main1函数
{void tsgxx();//声明 图书馆信息 函数 void jieshuxitong();//声明 借书系统 函数int choose;//cout<<"role为"<<role<<endl;//cout<<"hhhhhh"<<endl;if(role==2){cout<<"\t\t\t\t\t\t欢迎你,橘猫读者,借阅系统对你开放\n\n"; lmain();} else {pic1();guanliyuanyanzheng();cout<<"\t\t\t\t\t\t欢迎你,橘猫管理员,所有权限对你开放\n\n"<<endl;mainmenu();//显示主菜单 scanf("%d",&choose);switch(choose)//功能函数选择{ case 1:   tsgxx();break;case 2:   jieshuxitong(); break;  case 3:   system ("cls");printf("\n\n\n  小主再见,橘猫会想你的 ^、^\n\n\n  任意键安全退出哦 ^、^\n\n");exit(0);//exit关闭所有文件,终止正在执行的程序。exit(0):正常退出break;}
}
}void tsgxx()//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~图书馆信息函数
{ void tsjinku();//声明 图书进库 函数 void shanchu();//声明 删除图书信息 函数 void chaxunts();//声明 查询图书 函数 void kucunxinxi();//声明 显示库存 函数 char choose;menu1();//显示 图书信息 菜单 getchar();//吞掉一个显示出menu1函数后的进行下一步的回车      scanf("%c",&choose);for (;;)//在返回上一级前循环输入                                                                                                                                                    //??? switch(choose){ case '1':    tsjinku();break;case '2': shanchu();break;case '3': chaxunts();break;case '4':    kucunxinxi();break;case '5':  main1();//返回上一级 break;}
}int kucungs()//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~统计库存图书文本个数函数
{ 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("library.txt","r");//打开文件  fopen("文件名.文件类型","权限"); for (n=0;!feof(fp);n++)//逐个读文件(feof(fp):检测是否以及读取到文件尾部,到达尾部返回1,否则返回0)fscanf(fp,"%s%s%s%s%s%d%f",tshuhao,tname,tauthor,tchuban,tkind,&txcl,&tprice);n--;fclose(fp);//关闭文件return (n);//返回个数
}int duzhegs()//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~统计读者文本个数函数
{ FILE *fp;int zhenghao=0,n;char mingzi[20]={'\0'},riqi[20]={'\0'},zname[20]={'\0'};fp=fopen("reader.txt","r");//打开文件for (n=0;!feof(fp);n++)//逐个读文件fscanf(fp,"%d%s%s%s ",&zhenghao,&mingzi,&riqi,&zname);fclose(fp);//关闭文件return (n);//返回个数
}void tsjinku()//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~图书进库函数
{ FILE *fp;int xcl=0,n=0;float price=0;char name[20]={'\0'},author[20]={'\0'},kind[20]={'\0'},chuban[20]={'\0'},shuhao[20]={'\0'};char hitkey; system ("cls");if ((fp=fopen("library.txt","a"))==NULL)//打开图书馆文件,不存在此文件则新建{ fp=fopen("library.txt","w");fclose(fp);}fp=fopen("library.txt","a");//追加写打开进行录入数据 //printf("\n  请您输入需要添加的图书信息:\n\n  书号  书名  作者  出版社 类别  进库量 单价");//printf("\n\n   (类别:哲学,文学,教育,艺术,科学,教材,小说,其它)\n   (书号:(XXX) )\n"); for (;hitkey!=27;)//如果输入一组数据后敲了回车键则循环输入 { if (n!=0)printf("请输入:\n");//从第二次输入开始提示请输入 printf("请小主输入书籍的书号:");scanf("%s",shuhao);printf("\n");printf("请小主输入书籍的书名:");scanf("%s",name);printf("\n");printf("请小主输入书籍的作者:");scanf("%s",author);printf("\n");printf("请小主输入书籍的出版社:");scanf("%s",chuban);printf("\n");printf("请小主输入书籍的类别:");scanf("%s",kind);printf("\n");printf("请小主输入书籍的库存:");scanf("%d",&xcl);printf("\n");printf("请小主输入书籍的单价:");scanf("%f",&price);printf("\n");  //scanf("%s%s%s%s%s%d%f",shuhao,name,author,chuban,kind,&xcl,&price);     fprintf(fp,"%-10s%-25s%-20s%-20s%-20s%-5d%-8.2f\n",shuhao,name,author,chuban,kind,xcl,price);printf("\n");printf("继续输入请按回车\n结束输入请按Esc\n");n++;hitkey=getch();//记录敲击进来的键                                                                                                                                                for (;hitkey!=13&&hitkey!=27;)//13:\r回车  27:ESC退出                                                                                                                          hitkey=getch();//敲击错误可重复敲击 }fclose(fp);printf("\n橘猫收到,返回上一层!");getch();tsgxx();//返回上一层
}void shanchu()//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~删除图书信息
{ struct library *head=NULL;struct library *p,*p1,*p2;int txcl=0,n=0,j,i;float tprice=0;char tname[20]={'\0'},tauthor[20]={'\0'},tchuban[20]={'\0'},tkind[20]={'\0'},ttname[20]={'\0'},tshuhao[20]={'\0'};char hitkey;FILE *fp;if ((fp=fopen("library.txt","r"))==NULL)//打开文件{ system ("cls");printf("\n橘猫图书馆貌似没有库存呢...喵喵喵\n请按任意键返回\n");getch();tsgxx();}else{ system ("cls");printf("\n请小主输入要移除的书籍名称吧:");//输入删除图书书名scanf("%s",&ttname);printf("\n确认删除请回车,取消请按Esc\n");hitkey=getch();for(;hitkey!=13&&hitkey!=27;)hitkey=getch();if (hitkey==27)tsgxx();fp=fopen("library.txt","r");for (j=0;!feof(fp);)//读文件夹信息,统计在库图书个数{ j++;fscanf(fp,"%s%s%s%s%s%d%f",tshuhao,tname,tauthor,tchuban,tkind,&txcl,&tprice);}fclose(fp);fp=fopen("library.txt","r");for (i=1;i<j;i++){ fscanf(fp,"%s%s%s%s%s%d%f",tshuhao,tname,tauthor,tchuban,tkind,&txcl,&tprice);if (strcmp(ttname,tname))//比较名字,将不同名字的信息复制到链表                                                                                     //??? { n++;//相同返回值为0不执行if语句继续循环,不同则执行直到将所有不同的书名建立成链表if (n==1)//建立链表{ p1=p2=(struct library*)malloc(LEN);head=p1;}else{ p2->next=p1;p2=p1;p1=(struct library*)malloc(LEN);//新建链表}strcpy(p1->shuhao,tshuhao);//复制书号strcpy(p1->name,tname);//复制书名strcpy(p1->author,tauthor);//复制作者名字strcpy(p1->chuban,tchuban);//复制出版社strcpy(p1->kind,tkind);//复制类别p1->xcl=txcl;//复制个数p1->price=tprice;//复制单价}}if (n==0)//如果图书只有一项且这一项刚好和要删除的相同{ head=NULL;}else//建立链表的最后剩余一个储存空间,所以封底{p2->next=p1;p1->next=NULL;fclose(fp);}}fp=fopen("library.txt","w");//清空文件,只写打开,然后关闭fclose(fp);fp=fopen("library.txt","a");//追加文件p=head;for (;p!=NULL;)//把链表内容覆盖到文件{fprintf(fp,"%-8s%-9s%-14s%-16s%-18s%-7d%-8.2f\n",p->shuhao,p->name,p->author,p->chuban,p->kind,p->xcl,p->price);p=p->next;}fclose(fp);//关闭文件system ("cls");printf("\n移除成功啦,喵喵喵 \n按任意键返回上一层\n");getch();//返回上一层tsgxx();
}void chaxunts()//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~查询函数
{FILE *fp;char choose;int txcl=0,n=0,k=0,i,l;float tprice=0;char tname[20]={'\0'},tauthor[20]={'\0'},chazhao[20]={'\0'},tchuban[20]={'\0'},tshuhao[20]={'\0'},tkind[20]={'\0'};if ((fp=fopen("library.txt","r"))==NULL)//打开文件{ system ("cls");printf("\n貌似记录文件不存在呢,喵喵喵!按任意键返回");getch();tsgxx();}l=kucungs();//获得库存图书个数menu2();//提示输入菜单 scanf("%s",chazhao);system ("cls");for (i=0;i<l;i++){ fscanf(fp,"%s%s%s%s%s%d%f",tshuhao,tname,tauthor,tchuban,tkind,&txcl,&tprice);//读文件信息if(!strcmp(chazhao,tshuhao)||!strcmp(chazhao,tname)||!strcmp(chazhao,tauthor)||!strcmp(chazhao,tkind))//在库存图书里面模糊检索 {if (k==0){printf("查询结果:\n\n");//printf("书号\t 书名\t\t      作者\t\t  出版社\t      类别\t\t库存量\t单价\n");}printf("%-8s%-18s%-14s%-16s%-18s%-7d%-8.2f\n",tshuhao,tname,tauthor,tchuban,tkind,txcl,tprice);k++;}}if (k==0)//没有这本书 { system ("cls");printf("\n无符合记录!\n");getch();tsgxx();}fclose(fp);getch();//返回tsgxx();
}
void chaxunts1()//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~查询函数
{void jieshuxitong(); FILE *fp;char choose;int txcl=0,n=0,k=0,i,l;float tprice=0;char tname[20]={'\0'},tauthor[20]={'\0'},chazhao[20]={'\0'},tchuban[20]={'\0'},tshuhao[20]={'\0'},tkind[20]={'\0'};if ((fp=fopen("library.txt","r"))==NULL)//打开文件{ system ("cls");printf("\n记录文件不存在!按任意键返回");getch();tsgxx();}l=kucungs();//获得库存图书个数menu2();//提示输入菜单 scanf("%s",chazhao);system ("cls");for (i=0;i<l;i++){ fscanf(fp,"%s%s%s%s%s%d%f",tshuhao,tname,tauthor,tchuban,tkind,&txcl,&tprice);//读文件信息if(!strcmp(chazhao,tshuhao)||!strcmp(chazhao,tname)||!strcmp(chazhao,tauthor)||!strcmp(chazhao,tkind))//在库存图书里面模糊检索 {if (k==0){printf("查询结果:\n\n");//printf("书号\t 书名\t\t      作者\t\t  出版社\t      类别\t\t库存量\t单价\n");}printf("%-8s%-18s%-14s%-16s%-18s%-7d%-8.2f\n",tshuhao,tname,tauthor,tchuban,tkind,txcl,tprice);k++;}}if (k==0)//没有这本书 { system ("cls");printf("\n貌似没有无符合记录呢!\n");getch();tsgxx();}fclose(fp);getch();//返回jieshuxitong();
}void kucunxinxi()//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~显示库存图书信息
{FILE *fp;int xcl=0,n=0,i=0,j=0;float price=0;char name[20]={'\0'},author[20]={'\0'},kind[20]={'\0'},chuban[20]={'\0'},shuhao[20]={'\0'};if ((fp=fopen("library.txt","r"))==NULL)//打开文件夹{system ("cls");printf("\n貌似没有无符合记录呢!");}n= kucungs();if (n==0){ system ("cls");printf("\n貌似没有无符合记录呢!");}fp=fopen("library.txt","r");//打开只读文件system ("cls");pic3();printf("橘猫为小主展示的书籍信息如下");printf("\n"); printf("书号\t 书名\t\t      作者\t\t  出版社\t      类别\t\t库存量\t单价\n");for (i=0;i<n;i++)//输出所有在库图书信息{fscanf(fp,"%s%s%s%s%s%d%f",shuhao,name,author,chuban,kind,&xcl,&price);printf("%-10s%-20s%-20s%-20s%-20s%-5d%-8.2f\n",shuhao,name,author,chuban,kind,xcl,price);}fclose(fp);printf("\n按任意键返回\n");getch();//返回tsgxx();
}
void kucunxinxi1()//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~显示库存图书信息
{void jieshuxitong();FILE *fp;int xcl=0,n=0,i=0,j=0;float price=0;char name[20]={'\0'},author[20]={'\0'},kind[20]={'\0'},chuban[20]={'\0'},shuhao[20]={'\0'};if ((fp=fopen("library.txt","r"))==NULL)//打开文件夹{system ("cls");printf("\n貌似记录文件不存在呢!");}n= kucungs();if (n==0){ system ("cls");printf("\n貌似记录文件不存在呢!");}fp=fopen("library.txt","r");//打开只读文件system ("cls");printf("橘猫为小主展示的书籍信息如下"); printf("\n");printf("书号\t 书名\t\t      作者\t\t  出版社\t      类别\t\t库存量\t单价\n");for (i=0;i<n;i++)//输出所有在库图书信息{fscanf(fp,"%s%s%s%s%s%d%f",shuhao,name,author,chuban,kind,&xcl,&price);printf("%-10s%-20s%-20s%-20s%-20s%-5d%-8.2f\n",shuhao,name,author,chuban,kind,xcl,price);}fclose(fp);printf("\n按任意键返回\n");getch();//返回jieshuxitong();
}void menu3() //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~显示借书系统主菜单
{system ("cls");pic4();printf("\n                `~` `~` `~` `~` `~` `~` `~` `~` `~` `~` `~` `~` `~` `~` ");printf("\n\n                       1.橘猫图书库存查看\n"); printf("\n\n                      2.橘猫书籍快速查询\n"); printf("\n\n                      3.橘猫书籍借书登记\n");printf("\n\n                       4.橘猫书籍还书登记\n");printf("\n\n                       5.橘猫借阅情况查看\n");printf("\n\n                       6.结束程序\n\n");//printf("\n\n                   ^~^请按键选择and回车确定哦 *·*\n");printf("\n               `~` `~` `~` `~` `~` `~` `~` `~` `~` `~` `~` `~` `~` `~`\n ");  return ;
}void jieshuxitong()//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~借书系统函数
{ void jieshu();void huanshu();void duzhexinxi();//函数声明char choose;menu3();getchar();//吞掉一个显示出menu3函数后的进行下一步的回车 scanf("%c",&choose);//选择功能for (;;)switch(choose){ case '1': kucunxinxi1();//库存查询 break; case '2': chaxunts1();//条件查询图书 break; case '3': jieshu();//借书 break;    case '4': huanshu();//还书 break;case '5':    duzhexinxi();//查询借阅还书信息 break;case '6':   exit(0);break;}
}void jieshu()//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~借书函数
{FILE *fp,*fp3;struct library *head=NULL;struct library *p,*p1,*p2;int txcl=0,i,loop,zhenghao=0,n=0,k=0,t=0,flag=0;float tprice=0;char tname[20]={'\0'},tauthor[20]={'\0'},tchuban[20]={'\0'},tkind[20]={'\0'},tshuhao[20]={'\0'},ttname[20]={'\0'},mingzi[20]={'\0'},riqi[20]={'\0'},zname[20]={'\0'};char hitkey=0;system ("cls");{if ((fp=fopen("library.txt","r"))==NULL)//打开图书馆文件{system ("cls");printf("\n 橘猫图书馆没有库存啦!按任意键退出!");getch();exit (0);}else{{printf("\n小主输入借阅的书名就好啦:\n请输入:\n");//输入书名scanf("%s",zname);k= kucungs();//统计图书馆文件个数for (i=0;i<k;i++)//读入图书馆信息,存储到链表{fscanf(fp,"%s%s%s%s%s%d%f",tshuhao,tname,tauthor,tchuban,tkind,&txcl,&tprice);n++;if (n==1){ p1=p2=(struct library*)malloc(LEN);head=p1;}else{ p2->next=p1;p2=p1;p1=(struct library*)malloc(LEN);//新建链表}strcpy(p1->shuhao,tshuhao);//复制书号 strcpy(p1->name,tname);//复制书名strcpy(p1->author,tauthor);//复制作者strcpy(p1->chuban,tchuban);//复制出版社strcpy(p1->kind,tkind);//复制类别p1->xcl=txcl;//复制现存量p1->price=tprice;//复制单价}if (n==0)head=NULL;else{p2->next=p1;p1->next=NULL;fclose(fp);}}}p=head;for (;p!=NULL;)//读链表{if(!(strcmp(p->name,zname)))//判断要借书的是否存在{flag=1;//标记取1loop=p->xcl;//现存量减1(p->xcl)--;}p=p->next;}if(flag&&(loop>0))//存在借书书名且现存量大于0,把库存量变化后的链表存入文件{ fp=fopen("library.txt","w");fclose(fp);fp=fopen("library.txt","a");p=head;for (;p!=NULL;){fprintf(fp,"%-10s%-20s%-20s%-20s%-20s%-5d%-8.2f\n",p->shuhao,p->name,p->author,p->chuban,p->kind,p->xcl,p->price);p=p->next;}free(p);//把链表内容覆盖文件fclose(fp);}if(flag&&(loop>0))//存在借书书名且现存量大于0{{if ((fp3=fopen("reader.txt","r"))==NULL)//建读者文件夹{ fp3=fopen("reader.txt","w");//打开只读文件fclose(fp3);          }           fp3=fopen("reader.txt","a");//以附加的方式打开文件       }{{if (n!=0)printf("\n橘猫小读者输入相关的信息吧!:\n 按照这个顺序来输入哦!\n 小橘猫编号 小橘猫姓名 归还日期 借书书名\n请输入:");//录入读者信息scanf("%d %s %s %s",&zhenghao,&mingzi[20],&riqi[20],&zname[20]);fprintf(fp3,"\n%-8d%-23s%-18s%-10s\n",zhenghao,&mingzi[20],&riqi[20],&zname[20]);fp=fopen("library.txt","w");//删除图书馆文件信息fclose(fp);fp=fopen("library.txt","a");//重新追加信息p=head;for (;p!=NULL;)//把链表内容覆盖图书馆文件{fprintf(fp,"%-10s%-20s%-20s%-20s%-20s%-5d%-8.2f\n",p->shuhao,p->name,p->author,p->chuban,p->kind,p->xcl,p->price); p=p->next;}fclose(fp);fclose(fp3);printf("哈哈哈哈哈,居然成功啦!\n");getch();//返回jieshuxitong();//调用借阅系统}}jieshuxitong();//调用借阅系统}elseprintf("抱歉小主,这本书被借阅完啦,呜呜呜!按任意键返回!");//否则输出此书已被借完getch();//返回      jieshuxitong();//调用借阅系统}
}void huanshu()//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~还书函数
{FILE *fp,*fp3; struct reader *head=NULL;struct reader *p,*p1,*p2;struct library *lhead1=NULL;struct library *zp1,*lp1,*lp2;int txcl=0,i;float tprice=0;char tname[20]={'\0'},tauthor[20]={'\0'},tkind[20]={'\0'},tchuban[20]={'\0'},ttname[20]={'\0'},tshuhao[20]={'\0'};int ttzhenghao=0,tzhenghao=0,n=0,k=0,t=0,flag=0;char tmingzi[20]={'\0'},triqi[20]={'\0'},tzname[20]={'\0'},ttzname[20]={'\0'};char hitkey=0;system ("cls");{   if ((fp=fopen("reader.txt","r"))==NULL)//不存在读者文件,则输出不能还书{system ("cls");printf("\n 好像没有此小橘猫读者呢!按任意键退出!");getch();exit (0);}else{{         printf("\n请小主输入橘猫编号和图书书名:\n请输入:");    scanf("%d %s",&ttzhenghao,ttzname);//输入还书证号和书名k=duzhegs();//获取读者文件夹信息个数for (i=0;i<k;i++)//读取读者文件夹信息{fscanf(fp,"%d%s%s%s\n ",&tzhenghao,tmingzi,triqi,tzname);if((ttzhenghao==tzhenghao)&&!strcmp(ttzname,tzname))//如果证号书名存在,则标记为1flag=1;//strcmp:将两个字符串进行比较返回比较结果,相同返回0 }fclose(fp);fp=fopen("reader.txt","r");//打开读者文件if(flag){   for (i=0;i<k;i++)//将读者文件复制到链表{fscanf(fp,"%d%s%s%s\n ",&tzhenghao,tmingzi,triqi,tzname);//读取文件信息 if(!((ttzhenghao==tzhenghao)&&!strcmp(ttzname,tzname))){ n++;if (n==1){ p1=p2=(struct reader*)malloc(LEN1);//新建链表开辟内存 head=p1;//head指向第一个节点 }else{ p2->next=p1;p2=p1;p1=(struct reader*)malloc(LEN1);//新建链表}p1->zhenghao=tzhenghao;//复制证号strcpy(p1->mingzi,tmingzi);//复制读者名字                      strcpy(p1->riqi,triqi);//复制日期                        strcpy(p1->zname,tzname);//复制书名                  }}if (n==0)head=NULL;else{p2->next=p1;               p1->next=NULL;                  fclose(fp);             }fp=fopen("reader.txt","w");//清空读者文件fclose(fp);fp=fopen("reader.txt","a");//追加信息p=head;for (;p!=NULL;)//把链表内容覆盖读者文件         {               fprintf(fp,"\n%-8d%-23s%-18s%-10s\n",p->zhenghao,p->mingzi,p->riqi,p->zname);                     p=p->next;                  }free(p);               fclose(fp);             }}}}if(flag)//标记为1,即还书时{{{printf("确认还书请按回车!");for (;hitkey!=13&&hitkey!=27;)hitkey=getch();if (hitkey==13)printf("成功还书啦,喵喵喵!按任意键返回!");n=0;flag=0;fp3=fopen("library.txt","r");//打开图书馆文件k=kucungs();//获取图书馆文件个数for (i=0;i<k;i++)//将图书馆文件复制到链表{                  fscanf(fp3,"%s%s%s%s%s%d%f",tshuhao,tname,tauthor,tchuban,tkind,&txcl,&tprice);//读取信息                 n++;              if (n==1)             { lp1=lp2=(struct library*)malloc(LEN);//新建链表lhead1=lp1;}else{ lp2->next=lp1;lp2=lp1;lp1=(struct library*)malloc(LEN);//新建链表}strcpy(lp1->shuhao,tshuhao);//复制书号             strcpy(lp1->name,tname);//复制书名           strcpy(lp1->author,tauthor);//复制作者                   strcpy(lp1->chuban,tchuban);//复制出版社                  strcpy(lp1->kind,tkind);//复制类别                   lp1->xcl=txcl; //复制现存量                  lp1->price=tprice;//复制单价                    }if (n==0){lhead1=NULL;}else             {               lp2->next=lp1;              lp1->next=NULL; fclose(fp3);        }}}zp1=lhead1;     for (;zp1!=NULL;){     if(!(strcmp(zp1->name,ttzname)))//寻找书名相同         ++(zp1->xcl);//现存量加1           zp1=zp1->next;}fp3=fopen("library.txt","w");//清空图书馆文件fclose(fp);fp3=fopen("library.txt","a");//追加信息zp1=lhead1;for (;zp1!=NULL;)//把链表内容覆盖图书馆文件{fprintf(fp3,"%-10s%-20s%-20s%-20s%-20s%-5d%-8.2f\n\n",      zp1->shuhao,zp1->name,zp1->author,zp1->chuban,zp1->kind,zp1->xcl,zp1->price);      zp1=zp1->next;}fclose(fp3);getch();//返回jieshuxitong();//调用借阅系统}elseprintf("好像不存在此信息呢,好遗憾!按任意键返回!");getch();//返回jieshuxitong();//调用借阅系统
}void duzhexinxi()//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~显示读者借书情况函数
{FILE *fp;int zhenghao=0,xcl=0,n=0,i=0,j=0;char mingzi[20]={'\0'},riqi[20]={'\0'},zname[20]={'\0'};if ((fp=fopen("reader.txt","r"))==NULL)//打开读者文件夹{system ("cls");printf("\n记录文件不存在!");}n=duzhegs();if (n==0){ system ("cls");printf("\n无任何记录!");}fp=fopen("reader.txt","r");system ("cls");printf("\n证号\t读者姓名\t\t还书日期\t书名\n");for (i=0;i<n;i++)//输出文件信息{   fscanf(fp,"%d%s%s%s\n ",&zhenghao,mingzi,riqi,zname); printf("\n%-8d%-23s%-18s%-10s\n", zhenghao,mingzi,riqi,zname);}fclose(fp);printf("\n按任意键返回\n");getch();//返回jieshuxitong();//调用借阅系统
}void begin()
{printf("\n\n\n\t\t                    橘猫管理员登录请输入1\n\n\t\t                 橘猫读者登录请输入2 \n\n");cin>>role;main1();//cout<<"hhhh"<<role;
}int main()//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~主函数调用
{index();//爱心 index1();pic2();system("color E4");begin();//main1();return 0;
}

橘猫图书管理系统--数据库原理期末项目相关推荐

  1. 图书管理系统数据库综合应用

    图书管理系统数据库综合练习用到下面三个关系表: CARD      借书卡.    CNO 卡号,NAME   姓名,CLASS 班级 BOOKS     图书.      BNO 书号,BNAME ...

  2. 图书管理系统 数据库课程实验设计

    本课设系软件工程大二学生作,拙笔狂言,恭请斧正. 开发工具:Eclipse 2020-12,Microsoft SQL server 2012 程序语言:Java 引 言 选题题目:图书管理系统 选题 ...

  3. ASP.NET MVC CODE FIRST 图书管理系统 数据库

    ASP .NET MVC CODE FIRST 图书管理系统 本项目最后更新于2018-7-4,可能会因为没有更新而失效.如已失效或需要修正,请提issue! 我使用VS2017进行开发,框架是.NE ...

  4. 图书管理系统-数据库设计

    选题背景 依照图书管理系统的要求,完成如下任务 设计适合此应用需求的规范化的数据库: 建立ODBC数据源: 创建数据库连接: 制作一个具有安全性控制(权限管理和视图管理等)的数据库访问程序. 数据项 ...

  5. 图书管理系统——UML软件课程项目

    1面向对象分析 1.1需求分析 1.1.1问题定义 现各大高校内基本都设有图书馆供读者借阅图书,是学习的最佳选择场所之一.图书馆涉及图书借阅,新书购入和旧书淘汰,图书分类和图书查找功能. 图书管理系统 ...

  6. 图书管理系统的需求分析和项目介绍

    图书管理系统的项目介绍 一,介绍 图书管理系统为学校图书馆的自主借书还书等功能提供支持,用户有自己的账号,在线完成线下借书还书等操作. 管理系统包括图书的名称,作者,图书分类,图书编号,剩余数量,借出 ...

  7. 中南大学 oracle试卷,数据库原理期末复习(中南大学)数据库原理、技术及应用2.ppt...

    2014 春季 信息11,12 DB P,T&A-张祖平 数据库原理.技术及应用 张祖平/Zhang Zuping 电子信息工程系 School of Information Science ...

  8. Java web图书管理系统——数据库课程设计

    写了一个最基础的java web数据库课设,遵循三层架构. 后端:Java 前端:jsp + layui + echarts 数据库:mysql web容器:tomcat 操作系统:win10 IDE ...

  9. 图书管理系统 数据库实现(oracle)

    create tablespace library2 datafile 'E:\oracle\datafiles\library2.dbf' size 10M autoextend on; creat ...

最新文章

  1. 惊艳亮相!马斯克发布自研超算 Dojo 芯片、特斯拉人形机器人
  2. python代码根据当前时间获取下一周的日期
  3. 11.17-20 | KubeCon 北美 2020 阿里巴巴完整议题
  4. 【计网】计网----子网掩码,网关,ARP协议的作用
  5. 分享一个简单程序(webApi+castle+Automapper+Ef+angular)
  6. NET Core微服务之路:SkyWalking+SkyApm-dotnet分布式链路追踪系统的分享
  7. linux mysql 5.6.23_MySQL 5.6.23升级到MySQL 5.7.9
  8. java junit 怎么写_使用JUnit测试java代码
  9. 苹果:iPhone 12定价很合适,首批预订秒光说明用户认可
  10. 中国团队首次夺冠FPS游戏AI竞赛VizDoom,清华腾讯AI联手
  11. 最小生成树算法之Prim算法
  12. Android拍照,相册选择图片以及Android6.0权限管理
  13. unity怎么制作云飘动_Unity Shader教程之 旗帜飘扬效果的简单实现
  14. java,jsp页面添加提示图以及提示音乐
  15. 网络游戏协议测试(接口测试)的一些总结
  16. 我用kafka两年踩过的一些非比寻常的坑(宝贵经验)
  17. 开发者还能这样开发小游戏变现
  18. 【贪玩巴斯】关于修改系统hosts文件提升网络访问速度以便于提高抢课几率(好文分享)//2021-2-10
  19. Pandas库常用知识记录
  20. Autoware实车测试记录(一)--前期准备以及使用Autoware Maptool插件进行矢量地图的绘制

热门文章

  1. 新浪校园招聘2013.10.30浙大玉泉4教301笔试的前端妹纸,像雾像雨又像风
  2. 微信和mqqt服务器,微信小程序连接MQTT服务器实现控制Esp8266LED灯
  3. Nacos配置文件误删恢复
  4. UE4 骨骼穿模问题,血的教训
  5. 微信轻量级小说小程序系统源码+UI挺好看
  6. 新零售新连锁未来的发展趋势
  7. Outlook中添加中国农历节日
  8. Linux学习-01-Linux介绍
  9. 四大关键词 解读08年韩国游戏企业
  10. java顺丰运费接口_对接顺丰丰桥踩坑汇总(写给自己)