数据结构课程设计图书管理系统实验报告_第1页
数据结构课程设计图书管理系统实验报告_第2页
数据结构课程设计图书管理系统实验报告_第3页
数据结构课程设计图书管理系统实验报告_第4页
数据结构课程设计图书管理系统实验报告_第5页
已阅读5页,还剩39页未读 继续免费阅读

下载本文档

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

文档简介

1、beijing institute of petrochemical technology数据结构课程设计课程设计实验报告 院(系、部):信息工程学院 姓 名:计141范文虎 指导教师签名:2016年 6月29日·北京目录一. 设计题目·····························

2、83;······二. 设计目的····································三. 实验分工·····&

3、#183;······························四. 算法思想分析·················

4、3;··············五. 算法描述实现································1.数据结构类型定义 2.

5、算法流程图 3.程序代码六. 运行结果····································七.结论··········&

6、#183;·····························一. 设计题目图书管理基本业务模拟图书管理一般包括图书采编、图书编目、图书查询及图书流通(借、还书)等基本业务。要求设计一个图书管理信息系统,用计算机模拟实现上述系统功能。(1)书的登记内容包括书号、书名、著作者、现存量和库存量等;学生信息包

7、括借书证号、借阅信息等;(2)以书号建立索引表(线性表)以提高查找效率;(3)主要功能如下:a) 采编入库:新购一种书,确定书号后,登记到图书帐目表中,如果表中已有,则只将库存量增加;b) 借阅:如果一种书的现存量大于0,则借出一本,登记借阅者的书号和归还期限,改变现存量;c) 归还:注销对借阅者的登记,改变该书的现存量。(4)输出形式:能按书号、书名、著作者查找库存的书籍信息 能按学生的借书证号显示学生信息和借阅信息 书籍入库 借书功能实现 还书功能实现二. 设计目的1 了解并掌握数据结构与算法的设计方法,具备初步的独立分析和设计能力;2初步掌握软件开发过程的问题分析、系统设计、程序编码、测

8、试等基本方法和技能;3提高综合运用所学的理论知识和方法独立分析和解决问题的能力;4训练用系统的观点和软件开发一般规范进行软件开发,培养软件工作者所应具备的科学的工作方法和作风。2 开发环境:vc6.0或者dev c+.三. 实验分工范文虎:总体程序框架构思,算法分析,主程序编写,子函数调用,图书信息记录存储子函数编写,结合,主控制面板编写,哈希函数,结构体定义。算法实现,添加图书信息子函数编写,借阅图书字函数编写,查询子函数设计编写,还书子函数设计编写,最终程序调试,写报告。算法实现,删除图书子函数设计编写,查找图书信息子函数编写,测试整体程序,程序缺陷纠正,最终修改后程序综合。算法实现,查询

9、图书信息子函数设计编写,程序缺陷修改和测试。四. 算法思想分析用线性表进行存储,充分利用它易添加、易删除、查找方便的特点,进行程序的编写,符合题目的需求。而线性表是最基本、最简单、也是最常用的一种数据结构。五. 算法描述实现1. 数据结构类型定义typedefstruct int year; int month; int day; data;typedefstruct char num5; /读者编号记录data bro; data back; readernode;typedefstructchar title15; char writer15; int current; int total

10、; int key; /书的编号readernode reader10; /记录借读该书的读者记录booknode;typedefstructbooknode *elem; int count; /记录节点中的总数hashtable;2. 算法流程图建立哈希表删除函数添加函数查找函数添加图书增量子函数借阅书子函数添加书子函数查看已添加书子函数归还书子函数查看已借阅书子函数查找书子函数主函数完成3. 程序代码#include"stdafx.h"#include<stdio.h>#include<stdlib.h>#include<malloc.h

11、>#include<string.h>#include<conio.h>#define success 1#define unsuccess 0#define duplicate -1#define null_key 0/无记录元素 int hashsize=17,19,23,29;/存储容量 int m=0;/表长 typedef struct int year; int month; int day; data;typedef struct char num5; /读者编号记录 data bro; data back; readernode;typedef s

12、truct char title15; char writer15; int current; int total; int key; int more;/书的编号 readernode reader10; /记录借读该书的读者记录 booknode;typedef struct booknode *elem; int count; /记录节点中的总数 hashtable;void inithashtable(hashtable *h) int i; (*h).count=0; m=hashsize0; (*h).elem=(booknode *)malloc(m*sizeof(booknod

13、e); for(i=0;i<m;i+) (*h).elemi.key=null_key; unsigned hash(int k)/哈希函数,自己设定 return k%m; void collision(int *p,int d) / 开放定址法处理冲突 *p=(*p+d)%m; int searchhash(hashtable h,int k,int *p,int *c)/p为数据的地址位置,返回 *p=hash(k); while(h.elem*p.key != null_key && (k != h.elem*p.key) (*c)+; if(*c<m) c

14、ollision(p,*c); /下一地址 else break; if (k = h.elem*p.key) return success; else return unsuccess; int inserthash(hashtable *h,booknode e) int c,p; c=0; if(searchhash(*h,e.key,&p,&c) return duplicate; else if(c<hashsize0/2) (*h).elemp=e; +(*h).count; return 1; return 0;int deletehash(hashtabl

15、e *h,booknode e) int c,p; c=0; if(searchhash(*h,e.key,&p,&c) (*h).elemp.key=null_key; -(*h).count; return 1; else printf("不好意思,不存在n"); return 0;void addbook(hashtable *h) booknode e; int i; system("cls"); printf("nn*n"); printf("t你能在此目录下添加图书信息"); print

16、f("n*n"); printf("nt 请输入书的编号(形如: 1*): "); scanf("%d",&e.key); getchar(); printf("nt 请输入书名: "); gets(e.title); printf("nt 请输入该书作者: "); gets(e.writer); printf("nt 请输入该书现库存量: "); scanf("%d",&e.current); printf("nt 请输入该书总

17、库存量: "); scanf("%d%*c",&e.total); for(i=0;i<10;i+) (e.readeri).num0='0' /用'0'来初始化借该书的读者证号,表示一开始时没人借书 if(inserthash(&(*h),e) printf("图书添加成功!n"); (*h).count+; void showbook(hashtable h) int i; system("cls"); printf("nn*n"); printf

18、("t你能在此目录查看图书信息"); printf("n*n"); for(i=0;i<m;i+) if(h.elemi.key != null_key) /* 有数据 */ printf("图书编号:%dn",h.elemi.key); printf("书名: %sn",h.elemi.title); printf("作者: %sn",h.elemi.writer); printf("图书现存量: %dn",h.elemi.current); printf("

19、;图书总量 : %dn",h.elemi.total); printf("*n"); void bosearch(hashtable *h)/借阅查询 int e,r,t; system("cls"); printf("nn*n"); printf("t你能在此目录下按借书证号查找图书信息"); printf("n*n"); printf("nt 请输入你的借书证号: "); scanf("%d%*c",&e); if(searchhas

20、h(*h,e,&r,&t) printf("借书证编号: %dn",(*h).eleme.key); printf("书名: %sn",(*h).eleme.title); printf("作者: %sn",(*h).eleme.writer); printf("图书现存量:%dn",(*h).eleme.current); printf("图书总量 :%dn",(*h).eleme.total); else printf("您没有借过书!");void fi

21、nd(hashtable *h) int x,p,c; system("cls"); printf("nn*n"); printf("t你能在此目录下按编号查找图书信息"); printf("n*n"); printf("nt 请输入你想查找的书的编号: "); scanf("%d%*c",&x); if(searchhash(*h,x,&p,&c) printf("图书编号:%dn",(*h).elemp.key); printf

22、("书名: %sn",(*h).elemp.title); printf("作者: %sn",(*h).elemp.writer); printf("图书现存量: %dn",(*h).elemp.current); printf("图书总量 : %dn",(*h).elemp.total); else printf("对不起,不存在该书!n"); void borrowbook(hashtable *h) int i,k, x, f,t; system("cls"); pri

23、ntf("nn*n"); printf("t你能在此目录下按编号借阅图书"); printf("n*n"); printf("nt 请输入你想借的书编号: "); scanf("%d%*c",&x); if(searchhash(*h,x,&k,&f) printf("nt 你想借这本书吗 ?(y/n)"); printf("nt 书名: %s",(*h).elemk.title); printf("nt 作者: %s&q

24、uot;,(*h).elemk.writer); printf("nt 现库存量: %d",(*h).elemk.current); printf("nt 总库存量: %d",(*h).elemk.total); t=getch(); if(t='y'|t='y') if( (*h).elemk.current)=0) printf("nt对不起,这本书已经被借光了."); else for(i=0;i<10;i+) if( (*h).elemk.readeri).num0='0'

25、) break; printf("nt 请输入你的借书证号: "); scanf("%s",(*h).elemk.readeri).num); printf("nt 请输入借书日期: "); /输入借书日期 printf("nt 年: "); scanf("%d",&(*h).elemk.readeri).bro.year); printf("t 月: "); scanf("%d",&(*h).elemk.readeri).bro.mont

26、h); printf("t 日: "); scanf("%d",&(*h).elemk.readeri).bro.day); printf("nt 输入应还书日期: "); /输入应还书日期 printf("nt 年: "); scanf("%d",&(*h).elemk.readeri).back.year); printf("t 月: "); scanf("%d",&(*h).elemk.readeri).back.month)

27、; printf("t 日: "); scanf("%d%*c",&(*h).elemk.readeri).back.day); (*h).elemk.current-; /现存书量减1 printf("nt 你已借了该书."); else printf("nt 这本书不存在!n"); void returnbook(hashtable *h) int i,k, x, f,t,j; int year,month,day,d; float pay; char temp20; system("cls&

28、quot;); printf("nn*n"); printf("t你能在此目录下按编号归还图书"); printf("n*n"); printf("nt 请输入你还的书: "); scanf("%d%*c",&x); if(searchhash(*h,x,&k,&f) printf("nt 你想还这本书吗 ?(y/n)"); printf("nt 书名: %s",(*h).elemk.title); printf("nt

29、作者: %s",(*h).elemk.writer); printf("nt 现库存量: %d",(*h).elemk.current); printf("nt 总库存量: %d",(*h).elemk.total); t=getch(); if(t='y'|t='y') printf("nt 请输入你的借书证号: "); scanf("%s",temp); j=0; for(i=0;i<5;i+) if(!(strcmp(temp,(*h).elemk.reader

30、i).num) j=1;break; /查看是否有借书 if(j=0) printf("nt 你没有借书.");return; /该借书证号的人没借书 printf("nt 今天是:"); printf("nt 年: "); scanf("%d",&year); printf("t 月: "); scanf("%d",&month); printf("t 日: "); scanf("%d%*c",&day); d

31、=0; if(year<(*h).elemk.readeri).back.year) d=1; /判断是否已过了还书日期,d=1还没过期,d=0过期 if(year<=(*h).elemk.readeri).back.year && month<(*h).elemk.readeri).back.month) d=1; if(year<=(*h).elemk.readeri).back.year && month<=(*h).elemk.readeri).back.month && day<(*h).elemk.

32、readeri).back.day) d=1; if(d=0) pay=(year-(*h).elemk.readeri).back.year)*365+(month-(*h).elemk.readeri).back.month)*30+(day-(*h).elemk.readeri).back.day); printf("nt 你在 %d-%d-%d 借了这本书",(*h).elemk.readeri).bro.year,(*h).elemk.readeri).bro.month,(*h).elemk.readeri).bro.day); printf("nt

33、你应该在 %d-%d-%d 还这本书",(*h).elemk.readeri).back.year,(*h).elemk.readeri).back.month,(*h).elemk.readeri).back.day); printf("nt 今天是 %d-%d-%d",year,month,day); printf("nnt 所以你超出了还书日期"); printf("nt 你应该被罚款 %2.1f 元.",0.1*pay); /过期一天还1角钱 (*h).elemk.readeri).num0='0'

34、/已还,清除该读者借书记录 (*h).elemk.current+; /现存书量加1 printf("nt 你已经还了这本书.n"); else printf("nt 你要还一本没库存的书 ?n"); void savebook(hashtable h) file *fp1; int i; fp1=fopen("c:/record.txt","w"); fprintf(fp1,"= 图书信息记录表 =n"); for(i=0;i<m;i+) if(h.elemi.key != null_k

35、ey) fprintf(fp1,"=n"); fprintf(fp1,"图书编号:%dn",h.elemi.key); fprintf(fp1,"书名:%sn",h.elemi.title); fprintf(fp1,"作者:%sn",h.elemi.writer); fprintf(fp1,"现库存量:%dn",h.elemi.current); fprintf(fp1,"总库存量:%dn",h.elemi.total); fprintf(fp1,"*n"

36、;); fclose(fp1); printf("nn成功储存!你能在c:/record.txt找到相应纪录n"); printf("*n");void addtatol(hashtable *h)booknode e; int k, x, f,t; int m; int r,i; system("cls"); printf("nn*n"); printf("t你能在此目录下按编号修改图书信息"); printf("n*n"); printf("nt 输入你想增加的

37、图书量:"); scanf("%d",&e.more);printf("nt 请输入你要修改的书的编号: "); scanf("%d%*c",&x); if(searchhash(*h,x,&k,&f) printf("nt 书名: %s",(*h).elemk.title); printf("nt 作者: %s",(*h).elemk.writer); printf("nt 现库存量: %d",(*h).elemk.current)

38、; printf("nt 总库存量: %d",(*h).elemk.total); printf("nt 增加图书量成功!"); for(i=0;i<=(e.more);i+) (*h).elemk.total+; /(*h).elemk.total=r; else printf("nt 这本书不存在!n");void deletebook(hashtable h) int x,p,c,t; system("cls"); printf("nn*n"); printf("t你能在此

39、目录下按编号删除图书信息"); printf("n*n"); printf("nt 请输入你想删除的书的编号: "); scanf("%d%*c",&x); if(searchhash(h,x,&p,&c) printf("nt 你想删除这本书吗 ?(y/n)n"); printf("图书编号: %dn",(h).elemp.key); printf("书名: %sn",(h).elemp.title); printf("作者: %

40、sn",(h).elemp.writer); printf("图书现存量: %dn",(h).elemp.current); printf("图书总量 : %dn",(h).elemp.total); else printf("对不起,不存在该书!n"); t=getch(); if(t='y'|t='y') (h).elemp.key=null_key; printf("删除成功!n"); void menu(void) system("cls"); system("color 3f");/改变颜色 system("cls"); printf("*n"); printf("*n"); printf("* 图书管理系统 *n"); printf("*n"); printf("*n"); printf("n

温馨提示

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

评论

0/150

提交评论