1、1 设计目标数据结构课程关键介绍最常见数据结构,说明多种数据结构内在逻辑关系,讨论其在计算机中存放表示,和在其上进行多种运算时实现算法,并对算法效率进行简单分析和讨论。进行数据结构课程设计要达成以下目标:n 了解并掌握数据结构和算法设计方法,含有初步独立分析和设计能力;n 初步掌握软件开发过程问题分析、系统设计、程序编码、测试等基础方法和技能;n 提升综合利用所学理论知识和方法独立分析和处理问题能力;训练用系统见解和软件开发通常规范进行软件开发,培养软件工作者所应含有科学工作方法和作风。2. 设计内容和要求关键分为两大功效:(1) 图书管理(增加图书、查询图书、删除图书、图书借阅、还书); (
2、2) 会员管理(增加会员、查询会员、删除会员、借书信息)。设计要求:(1) 符合课题要求,实现对应功效;(2) 要求界面友好美观,操作方便易行;(3) 注意程序实用性、安全性;3本设计所采取数据结构采取两条单链表,其头结点分别为head、mhead全局变量来存放图书信息和会员信息。其定义数据结构以下:/*图书信息结构体*/typedef struct elemchar bookid5;char bookname50;char bookauthor20;char bookmark2;char memberid4;elemtype;/*图书链表结点结构体*/typedef struct nodee
3、lemtype data;struct node *next;lnode,*linknode;/*会员信息结构体*/typedef struct memberelemchar memberid4;char membername20;memberelemtype;/*会员链表结点结构体*/typedef struct membernodememberelemtype data;struct membernode *next;mlnode,*mlinknode;4功效模块具体设计图书借阅管理系统图书管理模块会员管理模块增加图书查询图书删除图书图书借阅还书增加会员查询会员借书信息删除会员4.1 具体
4、设计思想系统开启时,经过读取文件完成对以head、mhead为表头单链表完成初始化。初始化后系统进入系统菜单,其运行界面以下:当选择功效1时,进入图书管理模块,其运行界面以下:当选择功效2时,进入会员管理模块,其运行界面以下:在图书管理界面中,当选择功效1时,查看全部图书,其运行界面图:在会员管理界面中,当选择功效1时,查看全部会员,其运行界面图:4.2各个实现函数为了实现上述功效,特定义以下函数原型,具体代码参见源代码部分:void main() /*入口*/void initallinfo() /*初始化图书和会员链表*/void welform() /*系统总菜单*/void print
5、bookinfo(linknode head) /*输出图书信息函数*/void addbook() /*增加图书模块*/void select() /*按编号查询图书*/void delete() /*按编号删除图书*/void borrow() /*借阅图书*/void returnbook() /*还书*/void bookmanagetitle() /*图书管理二级菜单*/void bookmanage() /*二级图书管理功效选择函数*/void printmemberinfo(mlinknode head) /*输出会员信息函数*/void addmember() /*增加会员模块
6、*/void selectmember() /*按编号查询会员*/void deletemember() /*按编号删除会员*/void membermanagetitle() /*会员管理二级菜单*/void membermanage() /*二级会员管理功效选择函数*/4.4图书会员链表程序调试数据如表:图书初始数据表bookidbooknamebookauthorbookmarkmemberid0001sanguoyanyiluoguanzhongN00002hongloumengcaoxueqinN00003xiyoujiwuchengenY0010004shuihuzhuanshin
7、aianN00005javascriptJoinN00006cprogromtanghaoqiangN00007liaozhaizhiyipusonglingY0070008jiabajinN00009richucaoyuY0030010nahanluxunN0会员信息表memberidmembername001zhouxicai002longqidong003lipengfei004gaopeng005chenwentang006yangminghao4.5 关键代码#include#include#include#include#define NULL 0typedef struct el
8、emchar bookid5;char bookname50;char bookauthor20;char bookmark2;char memberid5;elemtype;typedef struct nodeelemtype data;struct node *next;lnode,*linknode;typedef struct memberelemchar memberid5;char membername25;memberelemtype;typedef struct membernodememberelemtype data;struct membernode *next;mln
9、ode,*mlinknode;linknode head;mlinknode mhead;FILE *bp,*bq;void initallinfo()FILE *bp,*bq;linknode p,q;mlinknode m,n;head=(lnode*)malloc(sizeof(lnode);head-next=NULL;mhead=(mlnode*)malloc(sizeof(mlnode);mhead-next=NULL;bp=fopen(book.txt,rb);printf(%s,feof(bp);bq=fopen(member.txt,rb);printf(%s,feof(bp
10、);if(bp=NULL)printf(can not open bookbat!);getchar();getchar();elsedop=(lnode*)malloc(sizeof(lnode);fread(p,sizeof(lnode),1,bp);q=p-next;p-next=head-next;head-next=p;while(q!=NULL); fclose(bp); if(bq=NULL)printf(can not open memberdat!);getchar();getchar();elsedom=(mlnode*)malloc(sizeof(mlnode);frea
11、d(m,sizeof(mlnode),1,bq);n=m-next;m-next=mhead-next;mhead-next=m;while(n!=NULL); fclose(bq);void mainmenu()system(cls);printf( SYSTEM MAIN MENU n);printf(*n);printf(*1:book manage *n);printf(*-*n);printf(*2:member manage *n);printf(*-*n);printf(*0:quit *n);printf(*n);printf(nPlease input order:n);vo
12、id printbookinfo(linknode head)linknode p=head-next;system(cls);printf(The book informations are:n);printf(%-7s%-20s%-15s%-6s%sn,id,title,author,mark,borrower);printf(*n);for(;p!=NULL;p=p-next)printf(%-7s%-20s%-15s%-6s%sn,p-data.bookid,p-data.bookname,p-data.bookauthor,p-data.bookmark,p-data.memberi
13、d);printf(nPlease anykey return.);getchar();getchar();void addbook()linknode p=(lnode*)malloc(sizeof(lnode);system(cls);printf(Add books.n);printf(%-7s%-20s%-15s%n,id(5),title,author);printf(*n);scanf(%s%s%s,p-data.bookid,p-data.bookname,p-data.bookauthor);p-data.bookmark0=N;p-data.bookmark1=0;p-dat
14、a.memberid0=0;p-data.memberid1=0;p-next=head-next;head-next=p;printf(nAdd success!n);printf(nPress anykey return.);getchar();getchar();void select()char id5;linknode p;system(cls);p=head-next;printf(select book by id.n);printf(Please input book id :n);scanf(%s,id);while(p!=NULL)if(strcmp(p-data.book
15、id,id)=0)break;elsep=p-next;if(p=NULL)printf(nThe book not exit!n);elseprintf(n%-7s%-20s%-15s%-3s%sn,id,title,author,borrowed,borrower);printf(*n);printf(n%-7s%-20s%-15s%-3s%sn,p-data.bookid,p-data.bookname,p-data.bookauthor,p-data.bookmark,p-data.memberid);printf(nPlease anykey return.);getchar();g
16、etchar();void deletebook()char id5;linknode p,q;system(cls);p=head-next;q=head;printf(delete book by id.n);printf(Please input book id:n);scanf(%s,id);while(p!=NULL)if(strcmp(p-data.bookid,id)=0)break;elseq=p;p=p-next;if(p=NULL)printf(nThe book you want to delete are not exit!n);elseq-next=p-next;fr
17、ee(p);printf(nDelete success!n);printf(nPress anykey return.);getchar();getchar();void borrow()char id5;char mid5;linknode p;mlinknode q;system(cls);printf(borrow book.n);dop=head-next;printf(Please input book id:n);scanf(%s,id);while(p!=NULL)if(strcmp(p-data.bookid,id)=0)break;elsep=p-next;if(p=NUL
18、L)printf(nThe book doesnt exit!please input it again!n);while(p!=NULL);if(p!=NULL)doq=mhead-next;printf(nPlease input member id:n);scanf(%s,mid);while(q!=NULL)if(strcmp(q-data.memberid,mid)=0)break;elseq=q-next;if(q=NULL)printf(nYou are not member!input again!n);while(q=NULL);if(q!=NULL&(strcmp(p-da
19、ta.bookmark,Y)!=0)strcpy(p-data.bookmark,Y);strcpy(p-data.memberid,q-data.memberid);printf(nsuccessed!n);getchar();getchar();elseprintf(nThe book have borrowed,please wait afew days.);getchar();getchar();printf(nPress anykey return.);getchar();getchar();void returnbook()char id5;linknode p;system(cl
20、s);p=head-next;printf(return book.n);printf(Please input book id:n);scanf(%s,id);while(p!=NULL)if(strcmp(p-data.bookid,id)=0)break;elsep=p-next;if(p=NULL)printf(nThe book you want to retrun are not exit!n);elsestrcpy(p-data.bookmark,N);strcpy(p-data.memberid,0);printf(nsuccessed!n);printf(nPress any
21、key return.);getchar();getchar();void bookmanagetitle()system(cls);printf( BOOK MANAGE MENU n);printf(*n);printf(*1:Look all books *n);printf(*-*n);printf(*2:Add book *n);printf(*-*n);printf(*3:Select book by id *n);printf(*-*n);printf(*4:Delete book by id *n);printf(*-*n);printf(*5:Borrow book *n);
22、printf(*-*n);printf(*6:Return book *n);printf(*-*n);printf(*0:Return to main form *n);printf(*n);printf(nPlease input order:n);void bookmanage()int ch;while(1)bookmanagetitle();scanf(%d,&ch);if(ch=0)break;switch(ch)case 1:printbookinfo(head);break;case 2:addbook();break;case 3:select();break;case 4:
23、deletebook();break;case 5:borrow();break;case 6:returnbook();break;case 0:break; default:printf(nTou have input the wrong order!n); printf(Press anykey return.);getchar();getchar();void printmemberinfo(mlinknode head)mlinknode mp=head-next;system(cls);printf(The member infomations are.n);printf(%-7s
24、%sn,id,name);printf(*n);for(;mp!=NULL;mp=mp-next)printf(%-7s%sn,mp-data.memberid,mp-data.membername);printf(nPress anykeykey return.);getchar();getchar();void addmember()mlinknode p=(mlnode*)malloc(sizeof(mlnode);system(cls);printf(Add member.n);printf(%-7s%sn,id,name);printf(*n);scanf(%s%s,p-data.m
25、emberid,p-data.membername);p-next=mhead-next;mhead-next=p;printf(nAdd success!);printf(nPress anykey return.);getchar();getchar();void selectmember()char id5;mlinknode p;system(cls);printf(select member by id.n);p=mhead-next;printf(Please input member id:n);scanf(%s,id);while(p!=NULL)if(strcmp(p-dat
26、a.memberid,id)=0)break;elsep=p-next;if(p=NULL)printf(nThe member not exit!n);elseprintf(n%-7s%sn,id,name);printf(*n);printf(%-7s%sn,p-data.memberid,p-data.membername);printf(nPress anykey return.);getchar();getchar();void deletemember()char id5;mlinknode p,q;system(cls);printf(delete member.n);p=mhe
27、ad-next;q=mhead;printf(Please input member id:n);scanf(%s,id);while(p!=NULL)if(strcmp(p-data.memberid,id)=0)break;elseq=p;p=p-next;if(p=NULL)printf(nThe member you want to delete are not exit!n);elseq-next=p-next;free(p);printf(nDelete success!n);printf(nPress anykey return.);getchar();getchar();voi
28、d membermanagetitle()system(cls);printf( MEMBER MANAGE MENU n);printf(*n);printf(*1:Look all memberinfo *n);printf(*-*n);printf(*2:Add member *n);printf(*-*n);printf(*3:Select member by id *n);printf(*-*n);printf(*4:Delete member by id *n);printf(*-*n);printf(*0:Return to main form *n);printf(*n);pr
29、intf(nPlease input order:n);void membermanage()int ch;while(1)membermanagetitle();scanf(%d,&ch);if(ch=0)break;switch(ch)case 1:printmemberinfo(mhead);break;case 2:addmember();break;case 3:selectmember();break;case 4:deletemember();break;case 0:break; default:printf(nYou have input the wrong order!n)
30、;printf(Press anykey return.);getchar();getchar();void main()int ch;initallinfo();while(1)mainmenu();scanf(%d,&ch);switch(ch)case 1:bookmanage();break;case 2:membermanage();break;case 0:exit(0); default:printf(nYou have input the wrong order!n);printf(Press anykey return.);getchar();getchar(); 5课程设计心得及存在问题 在这次课程设计中,我加深了对链表这个数据结构了解和认识,学会了链表建立、结点加入和删除、信息输出、简单图形界面构建等多个功效。在链表方面,即使学习了理论知识,但对它具体应用,经过课程设计实际应用了链表。对于操作界面,我认为还有很多要学,经过课程设计,对此有了部分了解。在调试过程中,从文件中读入数据,建立链表比较困难,要用到”rb”文件,只能用原来文件。这次课程设计,使我加深了对数据结构这门课了解,认识到数据结构关键性,计算机科学思想精妙,我要努力学习。
©2010-2024 宁波自信网络信息技术有限公司 版权所有
客服电话:4008-655-100 投诉/维权电话:4009-655-100