数据结构图书管理系统方案

上传人:痛*** 文档编号:89420144 上传时间:2022-05-13 格式:DOC 页数:36 大小:279.50KB
收藏 版权申诉 举报 下载
数据结构图书管理系统方案_第1页
第1页 / 共36页
数据结构图书管理系统方案_第2页
第2页 / 共36页
数据结构图书管理系统方案_第3页
第3页 / 共36页
资源描述:

《数据结构图书管理系统方案》由会员分享,可在线阅读,更多相关《数据结构图书管理系统方案(36页珍藏版)》请在装配图网上搜索。

1、 . . . *实践教学* 理工大学计算机与通信学院2007年春季学期算法与数据结构课程设计题 目:图书借阅管理专业班级:姓 名:学 号:指导教师:成 绩:_目 录摘要2前言3基本算法的实现4采用类c语言定义相关的数据类型4各模块的伪码算法5函数的调用关系图11调试分析12测试结果14源程序(带注释)18总结29参考文献30致31附件部分源程序代码32摘 要图书的借阅涉与到的操作算法都是以链表或顺序表的基本运算作为基础的,此程序包括:图书添加,图书查询,图书资料删除,借书,还书,增加会员,删除会员,查询会员借书信息输出显示的功能。通过链表存储结构实现数据的输入,实现各子程序过程的演示,对异常输

2、入信息报错。关键字:图书借阅的演示;图书添加,图书查询,图书删除,借书,还书,增加会员,删除会员,查询会员借书信息前 言很多涉与图书借阅的操作的算法都是以链表操作为基础,通过链表的建立,结点添加、查询与删除的演示,方便在学习中更好的理解链表结点的添加、查询、删除的过程。通过对链表的建立,结点添加、查询与删除的演示,我们在对一些问题进行求解时,会发现有些问题很难找到规律,或者根本无规律可寻。对于这样的问题,可以利用计算机运算速度快的特点,先搜索查找所有可能出现的情况,再根据题目条件从所有可能的情况中,删除那些不符合条件的解。我们在对一些问题进行求解时,会发现有些问题很难找到规律,或者根本无规律可

3、寻。对于这样的问题,可以利用计算机运算速度快的特点,先搜索查找所有可能出现的情况,再根据题目条件从所有可能的情况中,删除那些不符合条件的解。在插入结点的过程中,首先要生成一个数据域为X的结点,然后插入在链表中。根据插入操作的逻辑定义,还需要修改结点的指针域。在删除结点的过程中,首先查找到要删除的结点,然后删除,再修改结点的指针域。基本算法的实现采用类c语言定义相关的数据类型 (1) 图书结构体的定义如下:typedef struct BookInfo /图书结构int b_Code; /图书编号 char b_Name20; /名称float b_price; /价格 int b_person

4、;/借阅人 int b_Total; /总数 int b_Out; /借出数 BookInfo* nextbook; /下一类图书BookInfo;(2)会员结构体的定义如下:typedef struct MemberInfo /会员结构long m_Code; /会员编号 char m_Name20; /会员名字 char m_Sex20; /会员的性别 int m_Age;/会员的年龄 int l_Codes6; /以借书的编号,最多5 MemberInfo* nextmember; /下一会员MemberInfo;(3)管理系统结构定义如下:typedef struct System /

5、管理系统结构 BookInfo* BI; MemberInfo* MI; int BookTotal; /图书类库存量 int MemberTota; /会员数量System;各模块的伪码算法1. 添加图书算法:void AddBook(System* S)/添加图书 int Tempcode; char sel; BookInfo* p=S-BI; BookInfo* t; BookInfo* m; int num; do coutTempcode; if(m=SearchBook(S,Tempcode) cout这类书以有库存.n输入图书的入库量:num; m-b_Total+=num;

6、else t=(BookInfo*)malloc(sizeof(BookInfo); t-b_Code=Tempcode; coutt-b_Name; coutt-b_price; coutt-b_Total; t-b_Out=0; t-nextbook=p-nextbook; p-nextbook=t; S-BookTotal+; cout添加完毕!BI-nextbook; int bookcode; if(code=-1) coutbookcode; else bookcode=code; while(bi&bi-b_Code!=bookcode)bi=bi-nextbook; if(co

7、de=-1) if(!bi)cout没找到你所要的图书.endl; else cout图书编号为:b_Codeendl; cout图书名称为:b_Nameendl; cout图书价格为:b_priceendl; cout借阅人编号为:b_personendl; cout图书库存量为:b_Totalendl; cout图书借出量为:b_OutBI; MemberInfo* memi; char sel; int tempcode; int i; dopl=S-BI; bi=pl-nextbook; memi=S-MI-nextmember;couttempcode; while(bi) if(b

8、i-b_Code=tempcode)break; pl=bi; bi=bi-nextbook; if(bi=0)cout没有找到要删除的图书nextbook=bi-nextbook; S-BookTotal-; while(memi) for(i=1;il_Codes0;i+) if(memi-l_Codesi=tempcode)break;if(il_Codes0) for(;il_Codes0;i+)memi-l_Codesi=memi-l_Codesi+1; memi-l_Codes0-; memi=memi-nextmember; free(bi); return; while(1);

9、4借书算法:void BrrowBook(System* S)/借书 BookInfo* bi=S-BI-nextbook; BookInfo* p; char sel; int memcode; MemberInfo* mp; int tempcode; do couttempcode; p=SearchBook(S,tempcode); if(!p) cout没有找到要借出的图书.endl; else coutmemcode; mp=SearchMember(S,memcode); if(!mp)cout会员编号输入错误,外借失败l_Codes0=5)coutb_Out+; mp-l_Co

10、des+mp-l_Codes0=tempcode; cout外借成功.b_person=mp-m_Code; return; while(1);5还书算法:void TurnBackBook(System* S)/还书 BookInfo* bi=S-BI-nextbook; BookInfo* p; MemberInfo* mp; int membercode; int tempcode; int i; char sel; do couttempcode; p=SearchBook(S,tempcode); if(!p) cout书号输入错误.endl; else cout此书的现存量为b_T

11、otal-p-b_Out)endl; coutmembercode; if(!(mp=SearchMember(S,membercode)cout会员编号输入错误,归还失败b_Out-; for(i=1;il_Codes0;i+) if(mp-l_Codesi=tempcode)break; while(il_Codes0) mp-l_Codesi=mp-l_Codesi+1; i+; mp-l_Codes0-; cout归还成功.MI; MemberInfo* t; do coutTempcode; t=(MemberInfo*)malloc(sizeof(MemberInfo); t-m_

12、Code=Tempcode; coutt-m_Name; coutt-m_Sex; coutt-m_Age; t-l_Codes0=0; t-nextmember=p-nextmember; p-nextmember=t; S-MemberTota+; cout添加完毕!MI-nextmember; pl=S-MI; couttempcode; while(bi) if(bi-m_Code=tempcode)break; pl=bi; bi=bi-nextmember; if(!bi)coutb_Out-; book-b_Total-; free(bi); while(1);8查询会员算法:M

13、emberInfo* SearchMember(System* S,int code)/查询会员借书信息 MemberInfo* bi=S-MI-nextmember; int membercode; int i; if(code=-1) coutmembercode; else membercode=code; while(bi&bi-m_Code!=membercode)bi=bi-nextmember; if(code=-1) if(!bi)cout没找到指定会员.endl; else cout会员编号为:m_Codeendl; cout名称为:m_Nameendl; cout性别为:m

14、_Sexendl; cout年龄为:m_Ageendl; cout已借的图书有:l_Codes0本.endl; return bi;函数的调用关系图Main()主函数AddBook()增加图书DelMember()删除会员BorrowBook()借书处理TurnBackBook()还书处理SearchBook()查询图书SearchMember()查询会员借书信息DelBook()删除图书AddMember()添加会员LoadData()载入数据StoreData()保存数据ExitSystem()退出程序调试分析a、 调试中遇到的问题与对问题的解决方法在输入要查询的图书编号时,起初未能对不符

15、合输入条件的数据做报错处理,如当输入一个大于定义n的数,函数会产生死循环,有比如当输入如“1,1”一个结点自身关系时,函数将无法继续进行下去,或退出,对此问题,我做了以下处理方法。if(code=-1) coutbookcode; else bookcode=code; while(bi&bi-b_Code!=bookcode)bi=bi-nextbook; if(code=-1) if(!bi)cout没找到你所要的图书.endl;else cout图书编号为:b_Codeb_Code!=bookcode)bi=bi-nextbook;到if(code=-1) if(!bi)cout没找到你

16、所要的图书.endl;else cout图书编号为:b_Codeendl;即判断其是否符合要求,若不符,则报错,重新输入。b、算法的时间复杂度和空间复杂度图书的添加、查询、删除空间复杂度分别占:6%、6%、18%会员的添加、删除、查询空间复杂度分别占:6%、18%、6%借书空间复杂度占:20%还书空间复杂度占:20%其他占:2%时间复杂度图书的添加、查询、删除时间复杂度都为:O(n)会员的添加、删除、查询时间复杂度都为O(n)借书时间复杂度为O(n) 还书时间复杂度为O(n)测试结果一、图书借阅管理程序初始运行结果:二、详细操作步骤: 增加图书:添加会员:查询图书:借书:查询会员借书信息:还书

17、:删除图书:源程序(带注释)#include#include#include#define NULL 0typedef struct BookInfo /图书结构int b_Code; /图书编号 char b_Name20; /名称 int b_price; /价格 int b_person;/借阅人 int b_Total; /总数 int b_Out; /借出数 BookInfo* nextbook; /下一类图书BookInfo;typedef struct MemberInfo /会员结构long m_Code; /会员编号 char m_Name20; /会员名字 char m_S

18、ex20; /会员的性别 int m_Age;/会员的年龄 int l_Codes6; /以借书的编号,最多5 MemberInfo* nextmember; /下一会员MemberInfo;typedef struct System /管理系统结构 BookInfo* BI; MemberInfo* MI; int BookTotal; /图书类库存量 int MemberTota; /会员数量System;System* InitSystem();/void AddBook(System*);/增加图书BookInfo* SearchBook(System*,int);/查询图书信息voi

19、d DelBook(System*);/删除图书void BrrowBook(System*);/借书处理void TurnBackBook(System*);/还书处理void AddMember(System*);/添加会员void DelMember(System*);/删除会员MemberInfo* SearchMember(System*,int);/查询会员信息void StoreData(System*);void LoadData(System*);void ExitSystem();void main() System* S=InitSystem(); int sel; do

20、 coutntttt图书管理系统endl; coutttt*endl; coutttt*endl; coutttt 1.增加图书.t 2.查询图书.nttt 3.删除图书.t 4.借书处理.nttt 5.还书处理.t 6.添加会员.nttt 7.删除会员.t 8.查询会员借书信息.nttt 9.载入数据.t 10.保存数据.nttt 11.退出程序.n; coutttt*endl; coutttt*endl; coutsel; if(sel=1&sel=11)break; cout选择错误!n重新输入:BI=(BookInfo*)malloc(sizeof(BookInfo); S-BookT

21、otal=0; S-BI-nextbook=NULL; S-MI=(MemberInfo*)malloc(sizeof(MemberInfo); S-MemberTota=0; S-MI-nextmember=NULL; return S;void AddBook(System* S) int Tempcode; char sel; BookInfo* p=S-BI; BookInfo* t; BookInfo* m; int num; do coutTempcode; if(m=SearchBook(S,Tempcode) cout这类书以有库存.n输入图书的入库量:num; m-b_Tot

22、al+=num; else t=(BookInfo*)malloc(sizeof(BookInfo); t-b_Code=Tempcode; coutt-b_Name; coutt-b_price; coutt-b_Total; t-b_Out=0; t-nextbook=p-nextbook; p-nextbook=t; S-BookTotal+; cout添加完毕!endl; coutsel; if(sel=n|sel=N) cout结束添加BI-nextbook; int bookcode; if(code=-1) coutbookcode; else bookcode=code; wh

23、ile(bi&bi-b_Code!=bookcode)bi=bi-nextbook; if(code=-1) if(!bi)cout没找到你所要的图书.endl; else cout图书编号为:b_Codeendl; cout图书名称为:b_Nameendl; cout图书价格为:b_priceendl; cout借阅人编号为:b_personendl; cout图书库存量为:b_Totalendl; cout图书借出量为:b_OutBI; MemberInfo* memi; char sel; int tempcode; int i; do pl=S-BI; bi=pl-nextbook;

24、memi=S-MI-nextmember; couttempcode; while(bi) if(bi-b_Code=tempcode)break; pl=bi; bi=bi-nextbook; if(bi=0)cout没有找到要删除的图书nextbook=bi-nextbook; S-BookTotal-; while(memi) for(i=1;il_Codes0;i+) if(memi-l_Codesi=tempcode)break; if(il_Codes0) for(;il_Codes0;i+)memi-l_Codesi=memi-l_Codesi+1; memi-l_Codes0-

25、; memi=memi-nextmember; free(bi); coutsel; if(sel=N|sel=n) cout删除图书结束BI-nextbook; BookInfo* p; char sel; int memcode; MemberInfo* mp; int tempcode; do couttempcode; p=SearchBook(S,tempcode); if(!p) cout没有找到要借出的图书.endl; else cout此书的现存量为b_Total-p-b_Out)b_Total-p-b_Out)cout0.endl;/已借出 else coutmemcode;

26、 mp=SearchMember(S,memcode); if(!mp)cout会员编号输入错误,外借失败l_Codes0=5)coutb_Out+; mp-l_Codes+mp-l_Codes0=tempcode; cout外借成功.b_person=mp-m_Code; coutsel; if(sel=N|sel=n) cout外借操作结束.BI-nextbook; BookInfo* p; MemberInfo* mp; int membercode; int tempcode; int i; char sel; do couttempcode; p=SearchBook(S,tempc

27、ode); if(!p) cout书号输入错误.endl; else cout此书的现存量为b_Total-p-b_Out)endl; coutmembercode; if(!(mp=SearchMember(S,membercode)cout会员编号输入错误,归还失败b_Out-; for(i=1;il_Codes0;i+) if(mp-l_Codesi=tempcode)break; while(il_Codes0) mp-l_Codesi=mp-l_Codesi+1; i+; mp-l_Codes0-; cout归还成功.endl; coutsel; if(sel=N|sel=n) co

28、ut归还结束.MI; MemberInfo* t; do coutTempcode; t=(MemberInfo*)malloc(sizeof(MemberInfo); t-m_Code=Tempcode; coutt-m_Name; coutt-m_Sex; coutt-m_Age; t-l_Codes0=0; t-nextmember=p-nextmember; p-nextmember=t; S-MemberTota+; cout添加完毕!endl; coutsel; if(sel=n|sel=N) cout结束添加MI-nextmember; int membercode; int i

29、; if(code=-1) coutmembercode; else membercode=code; while(bi&bi-m_Code!=membercode)bi=bi-nextmember; if(code=-1) if(!bi)cout没找到指定会员.endl; else cout会员编号为:m_Codeendl; cout名称为:m_Nameendl; cout性别为:m_Sexendl; cout年龄为:m_Ageendl; cout已借的图书有:l_Codes0本.endl; for(i=1;il_Codes0;i+) coutl_Codesi ; coutMI-nextme

30、mber; pl=S-MI; couttempcode; while(bi) if(bi-m_Code=tempcode)break; pl=bi; bi=bi-nextmember; if(!bi)coutnextmember=bi-nextmember; S-MemberTota-; for(i=1;il_Codes0;i+) if(!(book=SearchBook(S,bi-l_Codesi) cout删除会员出错!b_Out-; book-b_Total-; free(bi); coutsel; if(sel=N|sel=n) cout删除会员结束BI-nextbook; if(!(

31、fp=fopen(BookSys,wb) cout打开文件BookSys失败!BookTotal),sizeof(int),1,fp); while(bi) fwrite(bi,sizeof(BookInfo),1,fp); bi=bi-nextbook; MemberInfo* mi=S-MI-nextmember; fwrite(&(S-MemberTota),sizeof(int),1,fp); while(mi) fwrite(mi,sizeof(MemberInfo),1,fp); mi=mi-nextmember; fclose(fp);void LoadData(System*

32、S) FILE* fp; if(!(fp=fopen(BookSys,rb) cout打开文件BookSys失败BI; BookInfo* tempbi; fread(&(S-BookTotal),sizeof(int),1,fp); for(int i=1;iBookTotal;i+) tempbi=(BookInfo*)malloc(sizeof(BookInfo); fread(tempbi,sizeof(BookInfo),1,fp); bi-nextbook=tempbi; bi=tempbi; bi-nextbook=NULL; MemberInfo* mi=S-MI; Membe

33、rInfo* tempmi; fread(&(S-MemberTota),sizeof(int),1,fp); for(i=1;iMemberTota;i+) tempmi=(MemberInfo*)malloc(sizeof(MemberInfo); fread(tempmi,sizeof(MemberInfo),1,fp); mi-nextmember=tempmi; mi=tempmi; mi-nextmember=NULL; fclose(fp);void ExitSystem() char select; cout警告: 程序结束后未存储的数据将消失.endl; coutselect

34、; if(select=y|select=Y)exit(0); if(select=n|select=N)return;总 结课程设计是对我们所学到的数据结构相关知识以与C语言知识的综合应用,在完成该课题的过程中,我对所学的知识进行了一次全面的复习,更加熟练的掌握了数据结构。在程序设计过程中,我们要灵活运用书本上所学知识,对程序中出现的错误要认真分析,要心、细心,一步一步去调试。我的课程设计题目是图书借阅管理。这个设计是一个比较综合的练习,它主要用到链表、查找等相关知识。这三周课程设计中,通过该题目的设计过程,我加深了对链表的理解,对链表结点的添加、查找、删除基本运算的实现有所掌握,对课本中所

35、学的各种数据结构进一步理解和掌握,学会了如何把学到的知识用于解决实际问题,锻炼了自己动手的能力。在完成该程序的过程中我遇到了很多麻烦,但我虚心学习,不懂得地方向老师和同学请教。在以后的学习中我会更加注意各个方面的能力的协调发展。要培养自己学习和解决问题的能里,为今后在学习工作中能更好的发展打下了坚实的基础。三周的课程设计很短暂,但其间的容是很充实的,在其中我学习到了很多平时书本中无法学到的东西,积累了经验,锻炼了自己分析问题,解决问题的能力,并学会了如何将所学的各课知识融会,组织,来配合学习,三周中我收益很大,学到很多。参考文献1. 严蔚敏,吴伟民, 数据结构(C语言版),清华大学。2. 严蔚

36、敏,吴伟民, 数据结构题集(C语言版),清华大学。3. DATA STRUCTURE WITH C+,William Ford,William Tcpp,清华大学(影印版)。4. 谭浩强,C语言程序设计,清华大学。致 首先感我的指导老师王连相老师,他在我的课程设计过程中提出了指导性的方案和架构,并指引我阅读相关的资料和书籍,使我在不熟悉的领域中仍能迅速掌握新的技术。感我的数据结构老师睿老师和C语言老师任学慧老师在以往的基础课学习中为我打下良好的基础,这是我这次课程设计能够顺利完成的前提。感我的同学在设计完成后对程序的测试以与在程序的设计过程中提的意见,没有同学的帮助不会取得较满意的结果,十分感

37、。附件 部分源程序代码图的深度遍历#define M 20#include #include #include /*定义图*/typedef struct int VM; int RMM; int vexnum;Graph;/*创建图*/void creatgraph(Graph *g,int n) int i,j,r1,r2; g-vexnum=n; /*顶点用i表示*/ for(i=1;iVi=i; /*初始化R*/ for(i=1;i=n;i+) for(j=1;jRij=0; /*输入R*/ printf(Please input R(0,0 END):n); scanf(%d,%d,

38、&r1,&r2); while(r1!=0&r2!=0) g-Rr1r2=1; g-Rr2r1=1; scanf(%d,%d,&r1,&r2); void printgraph(Graph *g)int i,j;for(i=1;ivexnum;i+) for(j=1;jvexnum;j+) printf(%2d ,g-Rij); printf(n); /*全局变量:访问标志数组*/int visitedM;/*访问顶点*/void visitvex(Graph *g,int vex)printf(%d ,g-Vvex);/*获取第一个未被访问的邻接节点*/int firstadjvex(Gra

39、ph *g,int vex)int w,i;for(i=1;ivexnum;i+) if(g-Rvexi=1&visitedi=0) w=i; break; else w=0; return w;/*获取下一个未被访问的邻接节点(深度遍历)*/int nextadjvex(Graph *g,int vex,int w) int t; t=firstadjvex(g,w); return t; /*深度递归遍历*/ void dfs(Graph *g,int vex) int w; visitedvex=1; visitvex(g,vex); for(w=firstadjvex(g,vex);w

40、0;w=nextadjvex(g,vex,w) if(!visitedw) dfs(g,w); void dfstraverse(Graph *g) int i; for(i=1;ivexnum;i+) visitedi=0; for(i=1;ivexnum;i+) if(!visitedi) dfs(g,i); /*主程序*/main() int n; Graph *g=(Graph *)malloc(sizeof(Graph); char menu; printf(Please input the number of vertex:n);scanf(%d,&n); creatgraph(g,n); input: printf(Please input d, Depth_first: d quit: qn); while(menu=getchar()=n); if(menu=d) pri

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

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!