北京理工大学-数据结构实验报告-实验四--图书管理系统_第1页
北京理工大学-数据结构实验报告-实验四--图书管理系统_第2页
北京理工大学-数据结构实验报告-实验四--图书管理系统_第3页
北京理工大学-数据结构实验报告-实验四--图书管理系统_第4页
北京理工大学-数据结构实验报告-实验四--图书管理系统_第5页
已阅读5页,还剩24页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

实验四 图书管理系统姓名:任子龙 学号: 班级:一.需求分析(1)问题描述有一个小型书库保管了大量图书,关于图书有大量信息需要处理,这些信息包括图书的分类、书名、作者名、购买日期、价格等。现要求编写一个程序以便于对图书的管理。(2)基本要求:a建立图书信息。b提供查找功能,按照多种关键字查找需要的书籍。例如按书名查找,输入书名后,将显示出该图书的所有信息,或显示指定信息。c提供排序功能,按照多种关键字对所有的书籍进行排序,例如按出版日期进行排序。d提供维护功能,可以对图书信息进行添加、修改、删除等功能。(3)数据结构与算法分析将每一本书看作是一个基本单元。由于涉及添加、修改操作,这里使用了链表作为数据存储结构;同时,考虑到排序功能,尝试使用双向链表。其中,每本书作为一个结点,数据域包含char型变量,指针域含有左右指针left和right。二.概要设计1.抽象数据类型的定义为实现上述功能,程序中使用了双向链表,只需要定义一种数据类型:typedef struct book char number10;char title20;char author10; char date15;char price10;struct book *right; struct book *left;BK; 注意结点的指针域有left和right两个。2. 本程序包含两个模块(1) 主程序模块主函数只包含了 Menu_select()函数。目的是进入主菜单界面,进行功能选择;直到输入操作码0,退出系统;(2) 双向链表单元模块实现书籍信息的链式存储的抽象数据类型。各函数之间的调用关系:三.详细设计1.结点类型typedef struct book char number10;char title20;char author10; char date15;char price10;struct book *right; struct book *left;BK;2. 子函数(1) 功能菜单调用函数 Menu_select() 使用户进入主菜单界面,进行功能选择;先进入无限循环,输入操作码进行系统管理工作,直到输入操作码0,退出系统;(2) 各种功能函数Initialize()/初始化图书系统信息;Insert()/添加新的图书信息;Sort()/对图书进行排序,本程序可以实现按“图书编号”、“出版日期”、 “图书价格”多种关键字进行排序; Search()/实现对图书的查找功能,本程序可以实现按“图书编号”、“出版日期”、“图书价格”多种关键字进行查找;deletebook()/删除无效的图书信息;Print_book()/打印全部图书信息。3. 主函数Main函数十分的简单,目的只有一个,就是进入功能选择菜单。 int main() /*主函数*/ Menu_select(); /*调用主菜单*/ 4. 调试分析1. 为了提高程序的健壮性,在menu函数中,考虑如果操作码超出0-7的范围,进行错误提示。2. 刚开始使用的其实是单链表,然后很快就发现了问题,当编写排序部分的时候,很难再进行下去;考虑过使用顺序表,但是由于有删除、添加的操作,所以也放弃了顺序表,最终决定用双向链表,这还是第一次。过程中发现双向链表用起来很方便!3. 排序函数sort()中为了保证程序的正确性,使用了自己较为熟练的冒泡排序法,没有考虑时间复杂度。4. 在编写的过程中也更加熟悉了switch函数,free函数,goto函数(当然尽量少用),还有学会了清屏,system(“cls”);五.测试结果1.建立图书信息及添加功能2. 查找功能A.按编号查找:B.按日期查找3. 修改功能4. 删除功能5. 排序功能为了说明问题,这里又添加了两本书简爱、余罪测试只提供按编号和日期排序A.按编号排序:B.按出版日期排序6、 附录#include#include #include #includetypedef struct book char number10;char title20;char author10; char date15;char price10;struct book *right; struct book *left;BK; BK *h_book; /*函数申明*/ void Start() system(cls); printf(nnntt*n); printf(nnnttt欢迎使用图书管理系统n); printf(nnntt*n); printf(nnntt 按任意键进入系统.);getch(); system(cls); void Insert()/*新书入库*/ BK *p,*p0,*p1; p=p1=h_book; printf(n新书入库模块.n); printf(n请输入新书信息.n包括书号、书名、数量.n); p0=(BK *)malloc(sizeof(BK); printf(图书编号:); scanf(%s,p0-number); while(strcmp(p0-number,p1-number)!=0&p1-right!=NULL) p1=p1-right; if(strcmp(p0-number,p1-number)=0) /*此处分两种情况,若图书编号存在,则直接进库,只须输入书的数量*/ printf(n此编号图书已存在!直接入库!n); else/*若不存在,则需要输入其他的信息,然后在进行插入操作*/ printf(图书名称:); scanf(%s,p0-title); printf(图书作者:); scanf(%s,p0-author); printf(图书出版日期:); scanf(%s,p0-date); printf(图书价格:); scanf(%s,p0-price); while(p-right) p=p-right; if(h_book=NULL) h_book=p0; /*此处分两种情况,链表中没有 数据,head直接指向p0处*/ else p-right=p0; p0-left=p; /*此处分两种情况,链表中有数据, 链表中最后元素的right指向p0处*/ p0-right=NULL; printf(n新书入库完毕!按任意键继续下一步操作.n); getch(); system(cls); void Print_book() /*打印所有图书信息*/ BK *p; p=h_book; printf(n图书信息如下:nn); printf(图书编号t图书名称t图书作者t出版日期t价格n); while(p!=NULL) printf(%stt%stt%stt%st%sn,p-number,p-title,p-author,p-date,p-price); p=p-right; printf(n图书信息打印完毕!按任意键继续下一步操作.); getch(); system(cls); void Initialize() /*初始化*/ BK *p0; printf(n图书初始化开始,请输入图书信息.n包括编号.书名.数量.n); p0=(BK*)malloc(sizeof(BK); h_book=p0; printf(n请输入图书信息:n); printf(图书编号:); /*输入图书编号(唯一)*/ scanf(%s,p0-number); printf(图书名称:); /*输入图书名称*/ scanf(%s,p0-title); printf(图书作者:); /*输入图书作者*/ scanf(%s,p0-author); printf(图书出版日期:); /*输入图书出版日期*/ scanf(%s,p0-date); printf(图书价格:); /*输入图书价格*/ scanf(%s,p0-price); p0-right=NULL; p0-left=NULL; printf(n图书信息初始化完毕!按任意键继续下一步操作.n); getch(); system(cls); void Sort() /*按多种关键词排序*/ BK *p,*front,*rear,*temp; int x; printf(n图书排序开始.n); printf(n请选择关键字进行排序:n); printf(1.书籍编号n2.出版日期n3.书籍价格n); scanf(%d,&x); temp=(BK*)malloc(sizeof(BK); front=h_book; p=front; while(p-right) p=p-right; rear=p; while(1) if(front=rear) break; else p=front; while(1) if(p=rear) break; switch(x) case 1: if(strcmp(p-number,p-right-number)0) /按编号冒泡排序 strcpy(temp-number,p-number);strcpy(p-number,p-right-number);strcpy(p-right-number,temp-number); strcpy(temp-author,p-author);strcpy(p-author,p-right-author);strcpy(p-right-author,temp-author); strcpy(temp-title, p-title); strcpy(p-title, p-right-title); strcpy(p-right-title, temp-title); strcpy(temp-date, p-date); strcpy(p-date, p-right-date); strcpy(p-right-date, temp-date); strcpy(temp-price, p-price); strcpy(p-price, p-right-price); strcpy(p-right-price, temp-price); break;case 2: if(strcmp(p-date,p-right-date)0) /按出版日期冒泡排序 strcpy(temp-number,p-number);strcpy(p-number,p-right-number);strcpy(p-right-number,temp-number); strcpy(temp-author,p-author);strcpy(p-author,p-right-author);strcpy(p-right-author,temp-author); strcpy(temp-title, p-title); strcpy(p-title, p-right-title); strcpy(p-right-title, temp-title); strcpy(temp-date, p-date); strcpy(p-date, p-right-date); strcpy(p-right-date, temp-date); strcpy(temp-price, p-price); strcpy(p-price, p-right-price); strcpy(p-right-price, temp-price); break;case 3:if(strcmp(p-price,p-right-price)0) /按价格冒泡排序 strcpy(temp-number,p-number);strcpy(p-number,p-right-number);strcpy(p-right-number,temp-number); strcpy(temp-author,p-author);strcpy(p-author,p-right-author);strcpy(p-right-author,temp-author); strcpy(temp-title, p-title); strcpy(p-title, p-right-title); strcpy(p-right-title, temp-title); strcpy(temp-date, p-date); strcpy(p-date, p-right-date); strcpy(p-right-date, temp-date); strcpy(temp-price, p-price); strcpy(p-price, p-right-price); strcpy(p-right-price, temp-price); break;default:break; p=p-right; rear=rear-left; printf(n排序完毕!按任意键继续下一步操作.n); getch(); system(cls); void Search() /*多种关键词查找*/ BK *p; int x; char t20=0; printf(n图书查找开始.n); k:printf(n请选择关键字进行查找:n); printf(1.书籍编号n2.出版日期n3.书籍价格n); scanf(%d,&x); printf(n请输入关键字:n); scanf(%s,t); p=h_book; while(p) switch(x) case 1:if(strcmp(p-number,t)=0) printf(%st%st%st%st%sn,p-number,p-title,p-author,p-date,p-price); break; case 2:if(strcmp(p-date,t)=0) printf(%st%st%st%st%sn,p-number,p-title,p-author,p-date,p-price); break; case 3:if(strcmp(p-price,t)=0) printf(%st%st%st%st%sn,p-number,p-title,p-author,p-date,p-price); break; default:printf(请输入正确的操作码!n);goto k; p=p-right; printf(n查找完毕!按任意键继续下一步操作.n); getch(); system(cls); void deletebook()/*删除图书信息*/ BK *p; char t20=0; printf(n请输入需要删除书籍编号:); scanf(%s,t); p=h_book-right; while(p) if(strcmp(p-number,t)=0) p-left-right=p-right; p-right-left=p-left; free(p);break;p=p-right; printf(n删除完毕!按任意键继续下一步操作.n); getch(); system(cls); void Modify()/*修改图书信息 */ BK *p; char t20=0; printf(n请输入需要修改书籍编号:); scanf(%s,t); p=h_book; while(p) if(strcmp(p-number,t)=0) break; p=p-right; /*指针p指向需要修改的结点*/ printf(n请重新输入图书信息:n); printf(图书编号:); /*输入图书编号(唯一)*/ scanf(%s,p-number); printf(图书名称:); /*输入图书名称*/ scanf(%s,p-title); printf(图书作者:); /*输入图书作者*/ scanf(%s,p-author); printf(图书出版日期:); /*输入图书出版日期*/ scanf(%d,&p-date); printf(图书价格:); /*输入图书价格*/ scanf(%d,&p-price); printf(n修改完毕!按任意键继续下一步操作.n); getch(

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论