图书信息管理系统
本系统结构简单,功能不多,供初学者参考使用!
需求分析
我所设计的系统主要包括学生登陆模块和管理员登陆模块,并设置了简单的权限处理(只有帐号和密码全都正确时方能进入系统)。但并未尽善尽美,有些地方存在漏洞,主要内容及功能如下:
学生登录模块:
1.图书查询(包括对书名,作者,分类号(即是编号),出版社,出版时间,价格,总库存量及现库存量的查询)。
2.图书排序(可对各个图书信息的项目进行从小到大排序)。
3.浏览全部图书(输出全部图书信息)
4.借书系统(每人只可借一本书)
5.还书系统
6.修改密码(查看密码是否修改成功时,需要进入查看个人资料,用新密码进入)
7.查看个人资料(图书名与分类号初始为0,意味着尚未借阅任何图书)
管理员登陆系统:
1.图书查询
2.图书排序
3.浏览全部图书
4.添加图书信息(可逐个添加,也可批量添加)
5.删除图书信息(输入时,需要输入图书的分类号)
6.修改图书信息(可修改图书名,作者名等相关图书信息)
头函数名:
#include
#include
#include
void welcome();//欢迎用户使用
int denglu1(struct student s[],int i);//学生登陆
int denglu2();//管理员登陆
struct book * creatbook();//创建链表,将文件中的图书信息写入链表int inputchoice();//选择菜单
int inputchoice1();//学生选择菜单
int inputchoice2();//管理员选择菜单
void pmenu(struct book * head);//学生主功能选择菜单
void menu2(struct book * head);//管理员主功能选择菜单
struct book * addbook(struct book * head);//添加图书信息
int chashu(struct book *head,char m[20]);//查找分类号是否存在struct book *insert1(struct book * head,struct book *p);//增加接点void printbook(struct book * head);//图书查找
int putchoice();//选择查找内容
void chaname1(struct book * head);//按书名查找
void chaprice(struct book * head);//按价格查找
void chacnum(struct book * head);//按分类号查找
void chazuozhe(struct book * head);//按作者名查询图书信息
void chatime(struct book * head);//按出版时间查找
void chapress(struct book * head);//按出版社查找
void sortbook(struct book * head);//排序选择
void shuming(struct book * head);//按图书名排
void ptime(struct book * head);//按出版时间排序
void price1(struct book * head);//按图书价格排
void fenleihao(struct book * head);//按图书编号排序
void zuo1(struct book * head);//按作者名排序
void pre1(struct book * head);//按出版社排序
struct book * shanchubook(struct book * head);//删除图书信息
void fprint(struct book * head);//将新链表写入文件中
void xiugai(struct book * head);//修改图书信息
void printbook1(struct book * head);//浏览全部图书信息
int chacun(struct book * head,char m[20]);//查找库存量是否为0
int jige();//求出文件中客户的个数
int xcz(struct book * head,char cnum[20]);//把库内图书的库存量减一
int xcz1(struct book * head,char cnum[20]);//把库内图书的库存量加一void backbook(struct student s[],int i,struct book * head);//还书函数void borrowbook(struct student s[],int i,struct book * head);//借书函数void xmima(struct student s[],int i);//修改密码
void xwj(struct student s[],int i);//将修改后的数组写入文件
void oneself(struct student s[],int i);//查看个人信息
int jie(char cnum[20],int i,struct student s[],char mnum[20]);//查询是否借
书
int huan(int i,struct student s[],char mnum[20]);//借书查询是否借书图书信息结构体:
struct book{
char bookname[20];//书名
char ename[20];//作者
char cnum[20];//图书分类号即图书编号,区别其余图书唯一特征char pubpress[20];//出版社
char pubtime[20];//出版时间
int price;//价格
int zc;//现库存
int xc;//总库存
struct book *next;//用链表建立图书信息
};
int denglu2()//管理员登陆系统
{
FILE *fp;
struct xinxi{
char mnum[20];//管理员登陆账号
char mima[20];//管理员登录密码
}temp;
char mnum[20],mima[20];
int m,n,i;
for(i=0;i<3;i++)
{
printf("请输入帐号:");
scanf("%s",mnum);
printf("请输入密码:");
scanf("%s",mima);
if((fp=fopen("2.txt","r"))==NULL){
printf("Can not open the file!");
exit(0);
}
while(!feof(fp))
{
fscanf(fp,"%s%s",temp.mnum,temp.mima);
m=strcmp(temp.mnum,mnum);
n=strcmp(temp.mima,mima);
if(m==0&&n==0)
return 1;
}
fclose(fp);
}
return i;
}
int inputchoice2()//管理员功能选择模块,管理员的所有功能
{
int mychoice;
printf("1.图书查询\n2.图书排序\n3.浏览全部图书\n4.添加图书\n5.删除图书\n6.修改图书\n0.退出\n");
printf("\ninput your choice:");
scanf("%d",&mychoice);
return mychoice;
}
3、struct book * creatbook(){
FILE *fp;
struct book *head,*tail,*p;
int size=sizeof(struct book);
char bookname[20],ename[20],cnum[20],pubpress[20],pubtime[20];
int price,zc,xc;
head=tail=NULL;
if((fp=fopen("book.txt","r"))==NULL){
printf("Can not open the file!");
exit(0);
}
fscanf(fp,"%s%s%s%s%s%d%d%d",bookname,ename,cnum,pubpres
s,pubtime,&price,&zc,&xc);
while( !feof(fp)){
p=(struct book *)malloc(size);
strcpy(p->bookname,bookname);
strcpy(p->ename,ename);
strcpy(p->cnum,cnum);
strcpy(p->pubpress,pubpress);
strcpy(p->pubtime,pubtime);
p->price=price;
p->zc=zc;
p->xc=xc;
if(head==NULL)
head=p;
else
tail->next=p;
tail=p;
fscanf(fp,"%s%s%s%s%s%d%d%d",bookname,ename,cnum,pubpres s,pubtime,&price,&zc,&xc);
}
fclose(fp);
tail->next=NULL;
return head;
}
struct book * addbook(struct book *head)//添加图书信息
{
FILE *fp;
struct book *p;
int size=sizeof(struct book);
char bookname[20];//书名
char ename[20];//作者
char cnum[20];//分类号
char pubpress[20];//出版社
char pubtime[20];//出版时间
int price,zc,xc;//价格,总库存,现库存
int n,i;
printf("如果您已经添加完毕,请将分类号数输入为0,谢谢合作:\n");
printf("1.少量添加,所添加内容没有存在文件中\n2.批量添加,内容在文件中存放\n");
printf("请输入编号:");
scanf("%d",&i);
switch(i){
case 1:
printf("请输入图书分类号:");
scanf("%s",cnum);
n=chashu(head,cnum);
if(n==1)
{
printf("您输入的分类号已存在,请重新输入!\n");
return head;
}
while(strcmp(cnum,"0")!=0)
{
n=chashu(head,cnum);
if(n==1)
{
printf("图书的分类号已存在,请重新输入!");
return head;
}
p=(struct book *)malloc(size);
strcpy(p->cnum,cnum);
printf("请输入图书名:");
scanf("%s",bookname);
strcpy(p->bookname,bookname);
printf("请输入作者名:");
scanf("%s",ename);
strcpy(p->ename,ename);
printf("请输入出版社:");
scanf("%s",pubpress);
strcpy(p->pubpress,pubpress);
printf("请输入出版时间:");
scanf("%s",pubtime);
strcpy(p->pubtime,pubtime);
printf("请输入价格:");
scanf("%d",&price);
p->price=price;
printf("请输入总库存量:");
scanf("%d",&zc);
p->zc=zc;
printf("请输入现库存量:");
scanf("%d",&xc);
p->xc=xc;
head=insert1(head,p,cnum);
printf("请输入图书分类号:");
scanf("%s",cnum);
}
break;
case 2:
if((fp=fopen("book1.txt","r"))==NULL)
{
printf("File do not open!");
exit(0);
}
while(!feof(fp))
{
p=(struct book *)malloc(size);
fscanf(fp,"%s",bookname);
strcpy(p->bookname,bookname);
fscanf(fp,"%s",ename);
strcpy(p->ename,ename);
fscanf(fp,"%s",cnum);
strcpy(p->cnum,cnum);
n=chashu(head,cnum);
if(n==1)
{
printf("图书的分类号已存在,请重新输入!");
return head;
}
fscanf(fp,"%s%s%d%d%d",pubpress,pubtime,&price,&zc,&xc);
strcpy(p->pubpress,pubpress);
strcpy(p->pubtime,pubtime);
p->price=price;
p->zc=zc;
p->xc=xc;
head=insert1(head,p,cnum);
}
break;
default:
printf("输入错误!\n");
break;
}
return head;
}
int chashu(struct book * head,char m[20])//查找图书是否存在{
int flag=0;
struct book *p=NULL;
if(head==NULL)
return -1;//可添加该图书
else
p=head;
while(p!=NULL)
if(strcmp(p->cnum,m)==0)
flag=1;
p=p->next;
}
if(flag==1)
return 1;//不可添加该图书
else
return -1;
}
struct book *insert1(struct book *head,struct book *ptr,char cnum[20])//增加接点
{
struct book *p,*p1,*p2;
p2=head;
p=ptr;
if (head==NULL)
{
head=p1;
p1->next=NULL;
}
else
while((strcmp(p->cnum,p2->cnum)>0)&&(p2->next!= NULL))
{
p1=p2;
p2=p2->next;
}
if(strcmp(p->cnum,p2->cnum)<=0)
{
if (head==p2)
head=p;
else
p1->next=p;
p->next=p2;
}
else
{
p2->next=p;
p->next=NULL;
}
}
return head;
}
int putchoice()//选择查找内容
{
int mychoice;
printf("\n\t\t\t1.按书名查找\n\t\t\t2.按价格查找\n\t\t\t3.按分类号查找\n\t\t\t4.按作者查找\n\t\t\t5.按时间查找\n\t\t\t6.按出版社查找\n\t\t\t0.退出\n\n");
printf("请输入查询编号:");
scanf("%d",&mychoice);
return mychoice;
}
void chaname1(struct book * head)//按书名查找
{
struct book *p;
char shuname[20];
int flag=0;
p=head;
printf("请输入要查找的书名:");
scanf("%s",shuname);
printf("\n");
printf("查找结果如下\n");
printf("图书名\t作者\t分类号\t出版社\t出版时间\t价格\t总库存\t现库存\n");;
while(p!=NULL){
if(strcmp(shuname,p->bookname)==0)
{
printf("%s\t%s\t%s\t%s\t%s\t\t%d\t%d\t%d\t",p->bookname,p->en ame,p->cnum,p->pubpress,p->pubtime,p->price,p->zc,p->xc);
printf("\n");
flag=1;
}
p=p->next;
}
if(flag==0)
printf("未找到你要找的书,请核实后再输!\n");
}
void sortbook(struct book * head)//排序选择
{
int i;
printf("\n\t\t\t1-按图书名排序\n\t\t\t2-按出版时间排序\n\t\t\t3-按图书价格排序\n\t\t\t4-按图书分类号排序\n\t\t\t5-按作者名排序\n\t\t\t6-按出版社排序\n\t\t\t0-取消排序操作\n\n");
printf("请输入您选择的选择:");
scanf("%d",&i);
switch(i){
case 0:
break;
case 1:
shuming(head); //按图书名排序
break;
case 2:
ptime(head); //按出版时间排序
break;
case 3:
price1(head); //按出版价格排序
break;
case 4:
fenleihao(head); //按图书分类号排序break;
case 5:
zuo1(head); //按图书作者排序
break;
case 6:
pre1(head); //按出版社排序default:
printf("您的输入有误!\n");
break;
}
}
其中,只给出按价格排序,其余省去。
void price1(struct book * head)//按图书价格排序{
struct book *a[100],*p,*p1,*temp;
int i,k,index,n=0;
char ch;
p1=head;
for(p=head;p;p=p->next)
n++;
for(i=0;i a[i]=p1; p1=p1->next; } for(k=0;k index=k; for(i=k+1;i if(a[i]->priceprice) index=i; } temp=a[index]; a[index]=a[k]; a[k]=temp; } printf("排序成功!\n"); printf("是否显示排序结果?(y/n)\n"); scanf("%s",&ch); switch(ch){ case 'n': break; case 'y': printf("图书名\t作者\t分类号\t出版社\t出版时间\t价格\t总库存\t 现库存\n"); for(i=0;i printf("%s\t%s\t%s\t%s\t%s\t\t%d\t%d\t%d\n",a[i]->bookname,a[i]->ename,a[i]->cnum,a[i]->pubpress,a[i]->pubtime,a[i]->price,a[i].zc.a[i].x c); } break; default: printf("您的输入有误!\n"); break; } } 删除信息模块: struct book * shanchubook(struct book * head)//删除图书信息{ char num[20]; struct book *ptr1,*ptr2,*p; printf("请输入图书分类号:"); scanf("%s",num); p=head; while(p!=NULL){ if(strcmp(p->cnum,num)==0) break; p=p->next; } if(p==NULL){ printf("没有找到该号的图书!\n"); } else { while(head!=NULL&&head->next==NULL) {