数据结构小组实验利用链表实现图书管理系统.docx
- 文档编号:10275312
- 上传时间:2023-02-09
- 格式:DOCX
- 页数:18
- 大小:91.82KB
数据结构小组实验利用链表实现图书管理系统.docx
《数据结构小组实验利用链表实现图书管理系统.docx》由会员分享,可在线阅读,更多相关《数据结构小组实验利用链表实现图书管理系统.docx(18页珍藏版)》请在冰豆网上搜索。
数据结构小组实验利用链表实现图书管理系统
小组实验报告
组号:
得分:
______________
一、问题描述
(清楚阐述要解决的问题)
建立图书管理系统,实现:
1.新书入库
2.旧书删除
3.更新书目
4.图书借出
5.图书归还
6.借出书目统计
7.按一定要求输出书库图书
(1)全部输出
(2)输出某类型图书
(3)输出某作者图书
二、问题分析
(分析问题特点,讨论解决方法)
1.建立图书管理系统,我们首先要讨论图书本身所包含哪些信息,这里选取书号,书名,作者,类型,现存量和总存量五个比较重要的信息进行处理;
2.其次,我们要讨论如何存放书目,这里选取带头结点的单链表形式,方便图书的插入与删除操作;
3.最后运用链表的基本操作实现基本的图书管理操作。
三、算法描述
(采用自然语言描述选定的解决方案)
1.创建含有书号,书名,作者,类型,现存量,总存量和指针的一个结构类型;
2.创建一个带头结点的链表;
3.新书入库:
从键盘读取信息存入新书节点中,将新书节点插入链表尾部;
4.旧书删除:
我们提供两种删除方式,按书号和书名,具体操作为:
从头结点后开始,依次寻找指定书目,如果找到,删除该书目节点,并告知操作者删除成功,如果没能找到,则告知操作者无该图书;
5.更新书目:
从头结点开始,向下寻找指定书目,若找到,根据操作者需要更改图书信息,并提示更改信息成功,若没有,提示操作者无该书;
6.图书借出:
从头结点开始,向下寻找指定书目,若找到且现存量大于0,将该书现存量减一,并提示操作者图书借阅成功,若找到但现存量为0,则提示存量不足借阅失败,若没有找到,提示操作者无该书;
7.图书归还:
从头结点开始,向下寻找指定书目,若找到图书且现存量小于总库存,则现存量加一,提示归还成功,若找到图书且现存量小于总库存,则提示无图书借出归还失败,若没有找到,则提示无该图书归还失败;
8.借出书目统计:
输出所有现存量小于总存量的书目信息;
9.按一定要求输出书库图书
(1)全部输出:
遍历输出;
(2)输出某类型图书:
遍历链表,如果输入图书类型与该图书类型相同,则输出该图书信息;
(3)输出某作者图书:
遍历链表,如果输入作者与该图书作者相同,则输出该图书信息;
四、详细设计
(画出程序流程图)
五、程序代码
(对关键语句或程序中的亮点设计给出必要注释)
#include
#include
#include
typedefstructBookNode
{
intbooknum;//书号
charbookname[15];//书名
charwriter[20];//作者名字
charbooktype[20];//图书类型
intcurrent;//现存量
inttotal;//总库存
structBookNode*next;
}BookNode,*Link;
typedefstructLinkList
{
Linkhead;//头结点
intlenth;//链表中数据元素的个数
}LinkList;
intnewwarehouse(LinkList*library)
{
intbooknum;
charbookname[15];
charwriter[20];
charbooktype[20];
inttotal;
printf("请输入新书信息:
书号,书名,作者名字,图书类型,总库存\n");
scanf("%d%s%s%s%d",&booknum,bookname,writer,booktype,&total);
Linkpre=NULL;
Linkp=NULL;
pre=library->head;
while(pre->next!
=NULL)
{
pre=pre->next;
}
p=(Link)malloc(sizeof(BookNode));
p->booknum=booknum;
strcpy(p->bookname,bookname);
strcpy(p->writer,writer);
strcpy(p->booktype,booktype);
p->current=total;
p->total=total;
p->next=NULL;
pre->next=p;
printf("新书入库成功\n");
return1;
}
intdeletebook1(LinkList*library,intnum)
{
inte=1;
Linkp,pre;
pre=library->head;
p=pre->next;
while(p!
=NULL)
{
if(num==p->booknum)
{
pre->next=p->next;
free(p);
printf("图书删除成功\n");
e=0;
}
else
{
pre=p;
p=p->next;
}
}
if(e==1)printf("无此图书信息\n");
return1;
}
intdeletebook2(LinkList*library,charname[15])
{
inte=1;
Linkp,pre;
pre=library->head;
p=pre->next;
while(p!
=NULL)
{
if(strcmp(name,p->bookname)==0)
{
pre->next=p->next;
free(p);
printf("图书删除成功\n");
e=0;
}
else
{
pre=p;
p=p->next;
}
}
if(e==1)printf("无此图书信息\n");
return1;
}
voidmodify(LinkList*library)
{
charname[15];
inte=1;
intc;
Linkp,pre;
pre=library->head;
p=pre->next;
printf("请输入要修改的书名:
\n");
scanf("%s",name);
while(p!
=NULL&&e==1)
{
if(strcmp(p->bookname,name)==0)
{
printf("\n请选择要修改的项:
");
printf("\n1.修改图书编号\n");
printf("\n2.修改图书作者\n");
printf("\n3.修改图书类型\n");
printf("\n4.修改图书库存量\n");
scanf("%d",&c);
switch(c)
{
case1:
{
printf("\n请输入新的图书编号:
");
scanf("%d",&p->booknum);break;
}
case2:
{
printf("\n请输入新的图书作者:
");
scanf("%s",p->writer);break;
}
case3:
{
printf("\n请输入新的图书类型:
");
scanf("%s",p->booktype);break;
}
case4:
{
printf("\n请输入新的图书库存量:
");
scanf("%d",&p->total);
p->current=p->total;
break;
}
}
printf("\n\t该项已成功修改。
\n\t新的图书信息:
");
printf("书号:
%d书名:
%s作者名字:
%s图书类型:
%s总库存:
%d\n",p->booknum,p->bookname,p->writer,p->booktype,p->total);
e=0;
}
p=p->next;
}
if(e==1)printf("\n\t暂无此图书信息。
");
getch();
}
intborrow(LinkList*library,charname[15])
{
inte=1;
Linkp;
p=library->head->next;
while(p!
=NULL)
{
if(strcmp(name,p->bookname)==0&&p->current>0)
{
p->current=p->current-1;
printf("图书借阅成功,现存量减一\n");
e=0;
break;
}
elseif(strcmp(name,p->bookname)==0&&p->current==0)
{
printf("图书库存不足,借阅失败\n");
e=0;
break;
}
else
{
p=p->next;
}
}
if(e==1)printf("无该图书,借阅失败\n");
return1;
}
intgiveback(LinkList*library,charname[15])
{
Linkp;
inte=1;
p=library->head->next;
while(p!
=NULL)
{
if(strcmp(name,p->bookname)==0&&p->current
{
p->current=p->current+1;
printf("图书归还成功,现存量加一\n");
e=0;
break;
}
elseif(strcmp(name,p->bookname)==0&&p->current==p->total)
{
printf("该图书无借出,归还失败\n");
e=0;
break;
}
else
{
p=p->next;
}
}
if(e==1)printf("无该图书,归还失败\n");
return1;
}
voidstatistics(LinkList*library)
{
inti=0;
Linkp;
p=library->head->next;
while(p!
=NULL)
{
if(p->current
{
printf("书号:
%d书名:
%s作者名字:
%s图书类型:
%s现存量:
%d总库存:
%d\n",p->booknum,p->bookname,p->writer,p->booktype,p->current,p->total);
i++;
}
p=p->next;
}
if(i==0)printf("暂无图书出借\n");
}
voidshow1(LinkList*library)
{
Linkp;
p=library->head->next;
printf("书号书名作者名字图书类型现存量总库存\n");
while(p!
=NULL)
{
printf("%d%s%s%s%d%d\n",p->booknum,p->bookname,p->writer,p->booktype,p->current,p->total);
p=p->next;
}
}
voidshow2(LinkList*library)
{
inti=0;
charname[15];
printf("请输入作者名字:
");
scanf("%s",name);
Linkp;
p=library->head->next;
printf("书号书名作者名字图书类型现存量总库存\n");
while(p!
=NULL)
{
if(strcmp(name,p->bookname)==0)
{
printf("%d%s%s%s%d%d\n",p->booknum,p->bookname,p->writer,p->booktype,p->current,p->total);
i++;
}
p=p->next;
}
if(i>0)printf("按要求共找到%d本书\n",i);
if(i==0)printf("无该作者图书\n");
}
voidshow3(LinkList*library)
{
inti=0;
chartype[20];
printf("请输入图书类型:
");
scanf("%s",type);
Linkp;
p=library->head->next;
printf("书号书名作者名字图书类型现存量总库存\n");
while(p!
=NULL)
{
if(strcmp(type,p->booktype)==0)
{
printf("%d%s%s%s%d%d\n",p->booknum,p->bookname,p->writer,p->booktype,p->current,p->total);
i++;
}
p=p->next;
}
if(i>0)printf("按要求共找到%d本书\n",i);
if(i==0)printf("无此类图书\n");
}
voidShow(LinkList*library)
{
intc;
printf("请问你想按什么要求输出:
\n1.输出书库中所有书目3.输出某作者的全部书目4.输出某类型全部书目\n");
scanf("%d",&c);
switch(c)
{
case1:
show1(library);break;
case2:
show2(library);break;
case3:
show3(library);break;
default:
printf("\n输入有误!
\n");
}
}
LinkList*Initialize(LinkList*NewList)
{
Linktemp,p,q;
NewList=(LinkList*)malloc(sizeof(LinkList));
temp=(Link)malloc(sizeof(BookNode));
temp->booknum=0;
temp->next=NULL;
NewList->head=temp;
NewList->lenth=0;
returnNewList;
}
intmain()
{
LinkList*library=NULL;
library=Initialize(library);
intn,num=0;
charname[15];
intchoice=1;
printf("欢迎使用图书管理系统(*^▽^*)\n\n");
while(choice)
{
printf("请输入你想进行的操作之前的序号:
\n1.新书入库2.删除图书\n3.更新书目4.图书借出\n5.图书归还6.统计借出书目\n7.按一定要求输出书库图书\n0.退出\n\n");
printf("操作:
");
scanf("%d",&choice);
system("cls");
if(choice==1)newwarehouse(library);
if(choice==2)
{
printf("请问你想根据以下哪种方法删除书目:
\n1.书号2.书名\n");
scanf("%d",&n);
if(n==1)
{
printf("请问你想删除书目的书号是\n");
scanf("%d",&num);
deletebook1(library,num);
}
if(n==2)
{
printf("请问你想删除书目的书名是\n");
scanf("%s",&name);
deletebook2(library,name);
}
}
if(choice==3)modify(library);
if(choice==4)
{
printf("请问需要借阅书目的书名是\n");
scanf("%s",name);
borrow(library,name);
}
if(choice==5)
{
printf("请问需要归还书目的书名是\n");
scanf("%s",name);
giveback(library,name);
}
if(choice==6)statistics(library);
if(choice==7)Show(library);
if(choice==0)printf("感谢您的使用,祝您生活愉快(*^▽^*)\n");
if(choice<0||choice>7)printf("抱歉,您的输入错误,请重新输入\n");
printf("\n\n");
}
return0;
}
六、测试和结果
(给出测试用例,并给出测试结果)
1.初始界面
2.新书入库
3.旧书删除
4.更新书目
5.图书借出
6.图书归还
7.借出书目统计
8.按一定要求输出书库图书
(1)全部输出
(2)输出某类型图书
(3)输出某作者图书
9.退出
七、用户手册
(告诉用户如何使用程序,使用注意事项等)
1.该管理系统没有预先设置书目,如需使用后续功能请务必先进行新书入库操作;
2.新书入库时系统无法检测输入重复的情况(考虑到每次输入都遍历比较再录入的话程序效率会大大变低),切勿输入书号或书名相同的书目;
3.应需要录入信息较多,使用者输入时需注意不要输错数据类型,以免程序出现错误。
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数据结构 小组 实验 利用 实现 图书 管理 系统
![提示](https://static.bdocx.com/images/bang_tan.gif)