图书信息管理系统.docx
- 文档编号:10389398
- 上传时间:2023-02-10
- 格式:DOCX
- 页数:30
- 大小:122.46KB
图书信息管理系统.docx
《图书信息管理系统.docx》由会员分享,可在线阅读,更多相关《图书信息管理系统.docx(30页珍藏版)》请在冰豆网上搜索。
图书信息管理系统
本系统结构简单,功能不多,供初学者参考使用!
需求分析
我所设计的系统主要包括学生登陆模块和管理员登陆模块,并设置了简单的权限处理(只有帐号和密码全都正确时方能进入系统)。
但并未尽善尽美,有些地方存在漏洞,主要内容及功能如下:
学生登录模块:
1.图书查询(包括对书名,作者,分类号(即是编号),出版社,出版时间,价格,总库存量及现库存量的查询)。
2.图书排序(可对各个图书信息的项目进行从小到大排序)。
3.浏览全部图书(输出全部图书信息)
4.借书系统(每人只可借一本书)
5.还书系统
6.修改密码(查看密码是否修改成功时,需要进入查看个人资料,用新密码进入)
7.查看个人资料(图书名与分类号初始为0,意味着尚未借阅任何图书)
管理员登陆系统:
1.图书查询
2.图书排序
3.浏览全部图书
4.添加图书信息(可逐个添加,也可批量添加)
5.删除图书信息(输入时,需要输入图书的分类号)
6.修改图书信息(可修改图书名,作者名等相关图书信息)
头函数名:
#include
#include
#include
voidwelcome();//欢迎用户使用
intdenglu1(structstudents[],inti);//学生登陆
intdenglu2();//管理员登陆
structbook*creatbook();//创建链表,将文件中的图书信息写入链表
intinputchoice();//选择菜单
intinputchoice1();//学生选择菜单
intinputchoice2();//管理员选择菜单
voidpmenu(structbook*head);//学生主功能选择菜单
voidmenu2(structbook*head);//管理员主功能选择菜单
structbook*addbook(structbook*head);//添加图书信息
intchashu(structbook*head,charm[20]);//查找分类号是否存在
structbook*insert1(structbook*head,structbook*p);//增加接点
voidprintbook(structbook*head);//图书查找
intputchoice();//选择查找内容
voidchaname1(structbook*head);//按书名查找
voidchaprice(structbook*head);//按价格查找
voidchacnum(structbook*head);//按分类号查找
voidchazuozhe(structbook*head);//按作者名查询图书信息
voidchatime(structbook*head);//按出版时间查找
voidchapress(structbook*head);//按出版社查找
voidsortbook(structbook*head);//排序选择
voidshuming(structbook*head);//按图书名排
voidptime(structbook*head);//按出版时间排序
voidprice1(structbook*head);//按图书价格排
voidfenleihao(structbook*head);//按图书编号排序
voidzuo1(structbook*head);//按作者名排序
voidpre1(structbook*head);//按出版社排序
structbook*shanchubook(structbook*head);//删除图书信息
voidfprint(structbook*head);//将新链表写入文件中
voidxiugai(structbook*head);//修改图书信息
voidprintbook1(structbook*head);//浏览全部图书信息
intchacun(structbook*head,charm[20]);//查找库存量是否为0
intjige();//求出文件中客户的个数
intxcz(structbook*head,charcnum[20]);//把库内图书的库存量减一
intxcz1(structbook*head,charcnum[20]);//把库内图书的库存量加一
voidbackbook(structstudents[],inti,structbook*head);//还书函数
voidborrowbook(structstudents[],inti,structbook*head);//借书函数
voidxmima(structstudents[],inti);//修改密码
voidxwj(structstudents[],inti);//将修改后的数组写入文件
voidoneself(structstudents[],inti);//查看个人信息
intjie(charcnum[20],inti,structstudents[],charmnum[20]);//查询是否借书
inthuan(inti,structstudents[],charmnum[20]);//借书查询是否借书
图书信息结构体:
structbook{
charbookname[20];//书名
charename[20];//作者
charcnum[20];//图书分类号即图书编号,区别其余图书唯一特征
charpubpress[20];//出版社
charpubtime[20];//出版时间
intprice;//价格
intzc;//现库存
intxc;//总库存
structbook*next;//用链表建立图书信息
};
intdenglu2()//管理员登陆系统
{
FILE*fp;
structxinxi{
charmnum[20];//管理员登陆账号
charmima[20];//管理员登录密码
}temp;
charmnum[20],mima[20];
intm,n,i;
for(i=0;i<3;i++)
{
printf("请输入帐号:
");
scanf("%s",mnum);
printf("请输入密码:
");
scanf("%s",mima);
if((fp=fopen("2.txt","r"))==NULL){
printf("Cannotopenthefile!
");
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)
return1;
}
fclose(fp);
}
returni;
}
intinputchoice2()//管理员功能选择模块,管理员的所有功能
{
intmychoice;
printf("1.图书查询\n2.图书排序\n3.浏览全部图书\n4.添加图书\n5.删除图书\n6.修改图书\n0.退出\n");
printf("\ninputyourchoice:
");
scanf("%d",&mychoice);
returnmychoice;
}
3、structbook*creatbook(){
FILE*fp;
structbook*head,*tail,*p;
intsize=sizeof(structbook);
charbookname[20],ename[20],cnum[20],pubpress[20],pubtime[20];
intprice,zc,xc;
head=tail=NULL;
if((fp=fopen("book.txt","r"))==NULL){
printf("Cannotopenthefile!
");
exit(0);
}
fscanf(fp,"%s%s%s%s%s%d%d%d",bookname,ename,cnum,pubpress,pubtime,&price,&zc,&xc);
while(!
feof(fp)){
p=(structbook*)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,pubpress,pubtime,&price,&zc,&xc);
}
fclose(fp);
tail->next=NULL;
returnhead;
}
structbook*addbook(structbook*head)//添加图书信息
{
FILE*fp;
structbook*p;
intsize=sizeof(structbook);
charbookname[20];//书名
charename[20];//作者
charcnum[20];//分类号
charpubpress[20];//出版社
charpubtime[20];//出版时间
intprice,zc,xc;//价格,总库存,现库存
intn,i;
printf("如果您已经添加完毕,请将分类号数输入为0,谢谢合作:
\n");
printf("1.少量添加,所添加内容没有存在文件中\n2.批量添加,内容在文件中存放\n");
printf("请输入编号:
");
scanf("%d",&i);
switch(i){
case1:
printf("请输入图书分类号:
");
scanf("%s",cnum);
n=chashu(head,cnum);
if(n==1)
{
printf("您输入的分类号已存在,请重新输入!
\n");
returnhead;
}
while(strcmp(cnum,"0")!
=0)
{
n=chashu(head,cnum);
if(n==1)
{
printf("图书的分类号已存在,请重新输入!
");
returnhead;
}
p=(structbook*)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;
case2:
if((fp=fopen("book1.txt","r"))==NULL)
{
printf("Filedonotopen!
");
exit(0);
}
while(!
feof(fp))
{
p=(structbook*)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("图书的分类号已存在,请重新输入!
");
returnhead;
}
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;
}
returnhead;
}
intchashu(structbook*head,charm[20])//查找图书是否存在
{
intflag=0;
structbook*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)
return1;//不可添加该图书
else
return-1;
}
structbook*insert1(structbook*head,structbook*ptr,charcnum[20])//增加接点
{
structbook*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;
}
}
returnhead;
}
intputchoice()//选择查找内容
{
intmychoice;
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);
returnmychoice;
}
voidchaname1(structbook*head)//按书名查找
{
structbook*p;
charshuname[20];
intflag=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->ename,p->cnum,p->pubpress,p->pubtime,p->price,p->zc,p->xc);
printf("\n");
flag=1;
}
p=p->next;
}
if(flag==0)
printf("未找到你要找的书,请核实后再输!
\n");
}
voidsortbook(structbook*head)//排序选择
{
inti;
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){
case0:
break;
case1:
shuming(head);//按图书名排序
break;
case2:
ptime(head);//按出版时间排序
break;
case3:
price1(head);//按出版价格排序
break;
case4:
fenleihao(head);//按图书分类号排序
break;
case5:
zuo1(head);//按图书作者排序
break;
case6:
pre1(head);//按出版社排序
default:
printf("您的输入有误!
\n");
break;
}
}
其中,只给出按价格排序,其余省去。
voidprice1(structbook*head)//按图书价格排序
{
structbook*a[100],*p,*p1,*temp;
inti,k,index,n=0;
charch;
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].xc); } break; default: printf("您的输入有误! \n"); break; } } 删除信息模块: structbook*shanchubook(structbook*head)//删除图书信息 { charnum[20]; structbook*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) { if(strcmp(head->cnum,num)==0) { ptr2=head; head=head->next; free(ptr2); } } if(head==NULL) { returnNULL; } ptr1=head; ptr2=head->next; while(ptr2! =NULL) { if(strcmp(ptr2->cnum,num)==0) { ptr1->next=ptr2->next; free(ptr2); } else ptr1=ptr2; ptr2=ptr1->next; } } returnhead; } 修改图书信息模块: void
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 图书 信息管理 系统