1、系统概述
图书借阅管理系统由管理员系统和用户系统两个子系统构成。用户运行程序后可按程序说明进入子系统,输入“1”进入管理员系统,输入“2”进入用户系统。图书信息和读者信息均用文件存储。
管理员系统:
- 新增图书:管理员可输入图书的类别、书号、书名、借出状态等信息。
- 更改图书信息:管理员输入要更改图书的书号后,即可对图书的各类信息进行修改。
- 删除图书:管理员输入要删除图书的书号,删除图书的各类信息。
- 查找图书: 管理员可以选择书名查找、类别查找、书号查找3种方式查找目标图书。
- 显示所有图书信息:此功能可查看文件中的所有图书,包括新增、更改的图书。
- 全删当前数据:对当前执行新增、更改操作产生的数据进行删除。
- 退出:退出系统。
用户系统:
- 借阅图书:用户输入想要借阅图书的书号借阅。
- 归还图书:归还已借图书。
- 查找所有图书:查看文件中包含的图书信息。
- 查找图书:用户可以选择书名查找、类别查找、书号查找3种方式查找目标图书。
- 显示我的信息:显示用户已借阅图书的书号和剩余图书借阅数量。
- 退出:退出系统。
2、系统功能实现效果(部分)
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<conio.h>//控制输入输出
struct book
{
char sort[20],num[20],bookname[20];
int lend;
int nolend;
struct book *next;
};
struct reader{
char xuehao[20],name[20];
int lended;
int maxlended;
char item[5][20];
struct reader *next;
};
void bookcharge();//图书管理系统函数
void readcharge();//用户管理系统函数
void readbook(struct book *head);//从图书信息文件中获取信息
void readreader(struct reader *head);//从用户信息文件中获取信息
//------------------------管理员系统 ----------------------- //int menu1();//图书管理系统菜单
int menu1();//管理员菜单
void add(struct book *head);//新增图书
void change(struct book *head);//更改图书信息
void shanchu(struct book *head); //删除图书
void find(struct book *head); //查找图书
void show(struct book *head); //显示所有图书信息
void deleteall(struct book *head);//全删当前数据
void free(struct book *head);//退出
//------------------------用户系统---------------------------//
struct reader *insert(struct reader *head);//返回登录读者信息指针
int menu2();//用户菜单
void lendbook(struct book *head,struct reader *q);//借阅图书
void returnbook(struct book *head,struct reader *q);//归还图书
void output(struct reader *head);//显示我的信息
void freeall(struct book *head,struct reader *q);//退出
//-------------------------主函数----------------------------//
main()
{
int x;
printf("欢迎进入图书馆系统,按1进入管理员系统,按2进入用户系统");
scanf("%d",&x);
if(x==1)
bookcharge();
if(x==2)
readcharge();
}
//---------------------管理员系统--------------------------//
void bookcharge()
{
int x;
struct book *headbook;
headbook=(struct book *)malloc(sizeof(struct book));
headbook->next=NULL;
readbook(headbook);
while(1)
{
getch;
system("cls");//清屏
switch(x=menu1())
{
case 1:add(headbook);
break;
case 2:change(headbook);
break;
case 3:shanchu(headbook);
break;
case 4:find(headbook);
break;
case 5:show(headbook);
break;
case 6:deleteall(headbook);
break;
case 0:free(headbook);
break;
}
}
}
//--------------------用户系统---------------------------//
void readcharge()
{
int x;
struct book *headbook;
headbook=(struct book *)malloc(sizeof(struct book));
headbook->next=NULL;
struct reader *headreader,*p;
headreader=(struct reader *)malloc(sizeof (struct reader));
headreader->next=NULL;
readbook(headbook);
readreader(headreader);
p=insert(headreader);
while(1)
{
getch();
system("cls");
switch(x=menu2())
{
case 1:lendbook(headbook,p);
break;
case 2:returnbook(headbook,p);
break;
case 3:show(headbook);
break;
case 4:find(headbook);
break;
case 5:output(p);
break;
case 0:free(headbook);
break;
}
}
}
void readbook(struct book *head)
{
FILE *fp;
if((fp=fopen("book.txt","r+"))==NULL)
{
printf("文件读取失败\n");
exit(0);
}
struct book *p,*tail=head;
while(!feof(fp))
{
p=(struct book *)malloc(sizeof(struct book));
fscanf(fp,"%s %s %s %d %d",p->sort,p->num,p->bookname,&p->lend,&p->nolend);
p->next=NULL;
tail->next=p;
tail=p;
}
fclose(fp);
}
void readreader(struct reader *head)
{
FILE *fp;
if((fp=fopen("reader.txt","r+"))==NULL)
{
printf("文件读取失败\n");
exit(0);
}
struct reader *p,*tail=head;
int i;
while(!feof(fp))
{
p=(struct reader*)malloc(sizeof(struct reader));
fscanf(fp,"%s %s %d",p->xuehao,p->name,&p->lended);
for(i=0;i<p->lended;i++)
fscanf(fp,"%s",p->item[i]);
fscanf(fp,"%d",&p->maxlended);
p->next=NULL;
tail->next=p;
tail=p;
}
fclose(fp);
}
int menu1()
{
int a;
printf("===============图书维护系统===========\n");
printf("1.新增图书\n");
printf("2.更改图书信息\n");
printf("3.删除图书\n");
printf("4.查找图书\n");
printf("5.显示所有图书信息\n");
printf("6.全删当前数据\n");
printf("0.退出\n");
printf("===============请选择=================\n");
scanf("%d",&a);
return a;
}
//----------------------新增函数---------------------------------------//
void add(struct book *head)
{
FILE *fp;
char ch;
fp=fopen("boos.txt","ra+");
struct book *p=head->next,*s;
s=(struct book *)malloc(sizeof(struct book));
while(p->next!=NULL)
p=p->next;
s->next=p->next;
p->next=s;
printf("新增图书信息,请输入:\n");
printf("%-10s%-10s%-10s%-10s%-10s\n","图书类别","书号","书名","已借出数量 ","未借出数量");
scanf("%s %s %s %d %d",s->sort,s->num,s->bookname,&s->lend,&s->nolend);
fprintf(fp,"%s %s %s %d %d",s->sort,s->num,s->bookname,s->lend,s->nolend);
fputc(ch,fp);
fclose(fp);
printf("===============添加成功===============\n");
getch();
}
//----------------------更改函数---------------------------------------//
void change(struct book *head)
{
char str[20];
struct book *p=head->next,*p1;
printf("输入你要修改的书号:\n");
scanf("%s",str);
printf("%10s%10s%10s\t%10s\t%10s\n","图书类别","书号","书名","已借出数量","未借出数量");
while(p)
{
if(strcmp(str,p->num)==0)
{
printf("%10s %10s %10s %10d %10d\n",p->sort,p->num,p->bookname,p->lend,p->nolend);
p1=p;
}
p=p->next;
}
printf("输入更改后的信息\n");
printf("%10s%10s%10s\t%10s\t%10s\n","图书类别","书号","书名","已借出数量","未借出数量");
scanf("%s %s %s %d %d",p1->sort,p1->num,p1->bookname,&p1->lend,&p1->nolend);
printf("===============修改完毕================\n");
getch();
}
// ----------------------删除函数-------------------------------------//
void shanchu(struct book *head)
{
char a[20];
struct book *p=head->next,*p1=head;
printf("输入你要删除的书号:\n");
scanf("%s",a);
printf("%-10s%-10s%-10s%-10s%-10s\n","图书类别","书号","书名","已借出数量 ","未借出数量");
while(p)
{
if(strcmp(p->num,a)==0)
{
printf("%-10s%-10s%-10s%-10d%-10d\n",p->sort,p->num,p->bookname,p->lend,p->nolend);
p1->next=p->next;
free(p);
}
p1=p;
p=p->next;
}
printf("============删除完毕===========\n");
getch();
}
//----------------------查找函数-----------------------------------------//
void find(struct book *head)
{
int a,flag=0;
char b[20];
struct book *p=head->next;
printf("选择查找方式:书名查找按1,类别查找按2,书号查找按3:\n");
scanf("%d",&a);
if(a==1)
{
printf("请输入你要查找的书名:\n");
scanf("%s",b);
while(p)
{
if(strcmp(p->bookname,b)==0)
{
printf("%-10s%-10s%-10s%-10s%-10s\n","图书类别","书号","书名","已借出数量 ","未借出数量");
printf("%-10s%-10s%-10s%-10d%-10d\n",p->sort,p->num,p->bookname,p->lend,p->nolend);
getch();
flag=1;
}
p=p->next;
}
if(flag==0)
printf("查无此书\n");
printf("请按任意键继续…");
getch();
}
else if(a==2)
{
printf("请输入你要查找的类别:\n");
scanf("%s",b);
while(p)
{
if(strcmp(p->sort,b)==0)
{
printf("%-10s%-10s%-10s%-10s%-10s\n","图书类别","书号","书名","已借出数量","未借出数量");
printf("%-10s%-10s%-10s%-10d%-10d\n",p->sort,p->num,p->bookname,p->lend,p->nolend);
printf("请按任意键继续…");
getch();
flag=1;
}
p=p->next;
}
if(flag==0)
printf("查无此类\n");
printf("请按任意键继续…");
getch();
}
else if(a==3)
{
printf("请输入你要查找的书号:\n");
scanf("%s",b);
while(p)
{
if(strcmp(p->num,b)==0)
{
printf("%-10s%-10s%-10s%-10s%-10s\n","图书类别","书号","书名","已借出数量 ","未借出数量");
printf("%-10s%-10s%-10s%-10d%-10d\n",p->sort,p->num,p->bookname,p->lend,p->nolend);
printf("请按任意键继续…");
getch();
flag=1;
}
p=p->next;
}
if(flag==0)
printf("查无此书\n");
}
else
printf("输入错误\n");
}
//-----------------------显示所有图书信息-------------------------------//
void show(struct book *head)
{
struct book *p=head->next;
printf("%-10s%-10s%-10s%-10s%-10s\n","图书类别","书号","书名","已借出数量 ","未借出数量");
while(p)
{
printf("%-10s%-10s%-10s%10d%10d\n",p->sort,p->num,p->bookname,p->lend,p->nolend);
p=p->next;
}
getch();
}
//-----------------------全删当前函数----------------------------------//
void deleteall(struct book *head)
{
struct book *p=head;
while(p)
{
head=head->next;
free(p);
p=head;
}
printf("=========已经全删==========\n");
getch();
}
//-----------------------退出-----------------------------------------//
void free(struct book *head)
{
struct book *p=head;
while(p)
{
head=head->next;
free(p);
p=head;
}
printf("正在退出,按任意键继续\n");
getch();
}
struct reader *insert(struct reader *head)
{
char str[20];
int flag=0;//判断学号是否存在的标记
struct reader *p=head->next;
printf("用户请输入学号登录(104173101):");
scanf("%s",str);
while(p)
{
if(strcmp(p->xuehao,str)==0)
{
flag=1;
break;
}
p=p->next;
}
if(flag==1)
return p;
else
printf("学号输入错误");
}
int menu2()
{
int b;
printf("============图书维护系统==============\n");
printf("1.借阅图书\n");
printf("2.归还图书\n");
printf("3.查看所有图书\n");
printf("4.查找图书\n");
printf("5.显示我的信息\n");
printf("0.退出\n");
printf("============请选择====================\n");
scanf("%d",&b);
return b;
}
//-----------------------借阅图书----------------------------------//
void lendbook(struct book *head,struct reader *q)
{
char s[20];
int flag=0;
struct book *p=head->next;
printf("============书籍借阅系统============\n");
printf("请输入你想要借阅的书号:");
scanf("%s",s);
while(p)
{
if(strcmp(p->num,s)==0)
{
flag=1;
break;
}
p=p->next;
}
if(q->lended>q->maxlended)
{
printf("已达最大借书数量!\n");
printf("====================================\n");
return ;
}
if(flag==1)
{
strcpy(q->item[q->lended],s);
q->lended++;
p->lend++;
p->nolend--;
printf("借阅成功!\n");
}
else
printf("查无此书!\n");
printf("====================================\n");
getch();
}
//--------------------------------归还图书----------------------------//
void returnbook(struct book *head,struct reader *q)
{
char s[20];
int flag=0,i,t;
struct book *p=head->next;
printf("============书籍归还系统============\n");
printf("请输入你想要归还的书号:");
scanf("%s",s);
for(i=0;i<q->lended;i++)
if(strcmp(q->item[i],s)==0)
{
flag=1;
t=i;
break;
}
if(flag==1)
{
memset(q->item[t],0,30);
q->lended--;
while(p)
{
if(strcmp(p->num,s)==0)
{
p->lend--;
p->nolend++;
}
p=p->next;
}
printf("归还成功!\n");
}
else
printf("书号输入错误!\n");
printf("====================================\n");
}
//-------------------------显示我的信息----------------------//
void output(struct reader *head)
{ int i;
printf("%-10s%-10s%-10s%-10s\n","学号","姓名","已借出数量 ","最大借出数量");
printf("%-10s%-10s%-10d%-10d\n",head->xuehao,head->name,head->lended,head->maxlended);
printf("借书项目\n");
for(i=0;i<head->lended;i++)
printf("%10s",head->item[i]);
}