数据结构课程设计
报 告
设计题目: 小型图书馆管理系统
专 业: 信息管理与信息系统
学生姓名:
班级学号:
指导教师:
2010 年6月25 日
数据结构课程设计报告
一、 设计时间
2010/6/21-------6/25
二、 设计地点
第一实验楼计算机系机房511
三、 设计目的
1、学习数据结构理论知识, 进一步熟悉基本概念;
2、熟练掌握链表的创建以及进行插入,排序,查找,删除等操作,了
解程序基本的流程。能根据实际问题的具体情况,结合数据结构中
的基本理论和基本算法,正确分析出数据的逻辑结构,合理的选择
相应的存储结构,并能设计出解决问题的有效算法;
3、运用所学C 语言知识,了解并掌握开发的各个流程,以及各功能代
码的实现。我们通过上机学习,学会有效利用基本的调试方法,找
出程序中出现的错误代码并修改;
4、培养查阅资料,独立思考问题的能力。
四、 设计小组成
五、 指导老师
六、 设计课题
小型图书馆管理系统
七、 基本思路及关键问题的解决方法
根据老师给的课题要求,小型图书管理系统的设计主要可以分为图
书信息录入、图书信息浏览、图书信息查询、图书信息修改、图书信息
删除几大功能块。由于课题要求系统得到设计必须用C 语言和数据结构
的相关知识,所以我们首先要创建一个新链表并用链表的每个节点存储
一条图书记录,即结构体(book ),其中各域分别为:分类号(classfy ) 、书
名(bookname ) 、作者(author ) 、定价(price ) 、出版社(publisher ) ,指针域(next)。
小型图书馆系统的信息录入、信息浏览、信息查询、信息修改、信息删
除功能快的实现分别用InsertDoc ,search_book,Print_Book_Doc,
info_change ,DeleteDoc 等来实现。
八、 算法及流程图
(1)主要算法
1、存储结构定义 struct books_list
{char author[20]; /*作者名*/
char bookname[20]; /*书名*/
char publisher[20]; /*出版单位*/
char pbtime[15]; /*出版时间*/
char loginnum[10]; /*登陆号*/
float price; /*价格*/
char classfy[10]; /*分类号*/
struct books_list * next; /*链表的指针域*/
};
struct books_list * Create_Books_Doc(); /*新建链表*/
void InsertDoc(struct books_list * head); /*插入*/
void DeleteDoc(struct books_list * head , int num);/*删除*/
void Print_Book_Doc(struct books_list * head);/*浏览*/
void search_book(struct books_list * head); /*查询*/
void info_change(struct books_list * head);/*修改*/
void save(struct books_list * head);/*保存数据至文件*/
2、新建链表头节点
struct books_list * Create_Books_Doc()
{
struct books_list * head;
head=(struct books_list *)malloc(sizeof(struct books_list));
/*分配头节点空间*/
head->next=NULL; /*头节点指针域初始化,定为空*/
return head;
3、用insterdoc 实现插入操作
void InsertDoc(struct books_list *head)
{
/*定义结构体指针变量 s指向开辟的新结点首地址 p为中间变量
*/
struct books_list *s, *p;
char flag='Y'; /*定义flag, 方便用户选择重复输入*/ p=head; /*遍历到尾结点,p 指向尾结点*/ while(p->next!= NULL) { p=p->next; }„}
4、用search_book实现查询操作
void search_book(struct books_list *head)
{
struct books_list * p;
char temp[20];
p=head;
if(head==NULL || head->next==NULL) /*判断数据库是否为空*/
{
printf(" ━━━
━ 图书库为空!━━━━\n");
}„}
5、用Print_Book_Doc来实现浏览操作
void Print_Book_Doc(struct books_list * head)
{
struct books_list * p;
if(head==NULL || head->next==NULL) /*判断数据库是否为空
*/
{
printf("\n ━
━━━ 没有图书记 录! ━━━━\n\n");
return; }
p=head;
printf("┏━━━┳━━━━━┳━━━━━┳━━━━━┳━━━━
━━┳━━━┳━━━━┓\n");
printf("┃登录号┃ 书 名 ┃ 作 者┃ 出版单位 ┃ 出
版时间 ┃分类号┃ 价格 ┃\n");
printf("┣━━━╋━━━━━╋━━━━━╋━━━━━╋━━━━━━
╋━━━╋━━━━┫\n");
/*指针从头节点开始移动,遍历至尾结点,依次输出图书信息*/
while(p->next!= NULL){
p=p->next;
printf("┃%-6.6s┃%-10.10s┃%-10.10s┃%-10.10s┃%-12.12s
┃%-6.6s┃%.2f ┃\n",p->loginnum,p->bookname,p->author,p->publish
er,p->pbtime,p->classfy,p->price); /*循环输出表格*/}
printf("┗━━━┻━━━━━┻━━━━━┻━━━━━┻━━━━━━
┻━━━┻━━━━┛\n");
printf("\n");
}
6、用info_change来实现修改操作
void info_change(struct books_list * head)
{
struct books_list * p;
int panduan=0; /*此变量用于判断是否找到书目*/
char temp[20];
p=head;
printf("请输入要修改的书名:");
scanf("%s",temp);
while(p->next!= NULL)
{
p=p->next;
if(strcmp(p->bookname,temp)==0)
{
printf("\n
图书登陆卡号:");
fflush(stdin);
scanf("%s",p->loginnum);
„ „ „
fflush(stdin);
scanf("%s",p->classfy);
printf("\n
图书价格:");
fflush(stdin);
scanf("%f",&p->price);
printf("\n");
panduan=1;
}
}
if(panduan==0)
{
printf("\n
━━ 没有图书记录! ━━━━\n\n");
}
return;}
7、用DeleteDoc 来实现删除操作
void DeleteDoc(struct books_list * head) 请输入请输入 ━━
{
struct books_list *s,*p; /*s为中间变量,p 为遍历时使
用的指针*/
char temp[20];
int panduan; /*此变量用于判断是否找到了书目*/
panduan=0;
p=s=head;
printf(" [请输入
您要删除的书名]:");
scanf("%s",temp);
(2)程序流程
系统的执行应从功能菜单的选择开始,依据用户的选择来进行的处理
直到用户选择退出系统为止,其间应对用户的选择做出判断及异常处
理。流程图如下:
程中难免会出现各种各样的错误,导致我们的写的程序不能够正常运行。
我在小型图书管理系统的设计过程中就出现一些或难或易得问题。小到因为粗心大意丢失了“;”,而在编译窗口出现几十个错误。其实错误并不可怕,主要是要找到错误的根源,那样错误就可以任意的被纠正。在我调试的过程中,出现的另一个错误,我吓了一跳。不过好在编译器帮我找到了问题的所在,原来是中间变量P 没有定义。发现了问题所以很容易就解决
啦。由于我的问题很多但是都是一些常见且简单的问题,所以也不在这里
赘述啦。
(1) 执行VC++;(2) 打开library.CPP 文件;(3) 进入系统操作界面;
(4) 进入后根据提示信息可进行:
“ 1、图书信息录入; 2、图书信息浏览; 3、图书信息查询 ;
4、图书信息修改 ;5、图书信息删除;6、退出系统 。
九、 课程设计心得体会
一晃眼,大二第二学期就要结束了。每期一次的课程设计开始了,
这次我的数据结构课程设计的题目是《小型图书馆管理系统》。说实话,刚开始拿到这个题目我的唯一感觉就是头痛。第一次一个人尝试去做一个系统,虽然是小型的,但是还是有点心怯。回想前几次课程设计,我的心收集瞬间勇敢了起来。因为我们学校有图书馆可以借相关书籍,班集体里有同学的热心帮助,机房里还有指导老师的悉心指导,还有网络上的海量信息。虽然老师要求我们独立完成,但是我还是可以去查找相关资料的。
在17周的星期一我开始了我的课程设计,万事开头难,我的课程设计也不例外。开始的时候就遇到了一些不大不小的问题,不过最后我都一一克服啦。当然这些问题的解决离不开老师和同学的无私帮助。到了程序的调试阶段,也是最让我纠心的阶段。总是出现多种各样的问题,不过经过两个小时的艰苦奋战终于它通过了。但是我的课程设计最为难的地方却是算法分析,因为我以前没有写过算法。于是我去网上找到了好多关于算法的资料,也去图书馆借了算法的相关书籍。最后算法也如期的完成了。
这次数据结构的课程设计我收获了很多。对数据结构的知识有进一步的认知,但是跟多的收获是在学习方法上。我们专业的学习不能够只停留在一些理论知识的掌握,还应与实践结合在一起。通过不断的实践和理论的结合练习,提高自己的能力。在这次的课程设计当中也发现了自己的不足:缺少实际动手能力,不过我会在学习中不断的充实自我,改正自我,提高自我。
十、 源程序(见电子文档)
#include
#include
#include
#include
struct books_list
{
char author[20]; /*作者名*/ char bookname[20]; /*书名*/ char publisher[20]; /*出版单位*/
char pbtime[15]; /*出版时间*/ char loginnum[10]; /*登陆号*/
float price; /*价格*/ char classfy[10]; /*分类号*/ struct books_list * next; /*链表的指针域*/
};
struct books_list * Create_Books_Doc(); /*新建链表*/ void InsertDoc(struct books_list * head); /*插入*/
void DeleteDoc(struct books_list * head , int num);/*删除*/ void Print_Book_Doc(struct books_list * head);/*浏览*/ void search_book(struct books_list * head); /*查询*/ void info_change(struct books_list * head);/*修改*/
void save(struct books_list * head);/*保存数据至文件*/ /*新建链表头节点*/
struct books_list * Create_Books_Doc()
{
struct books_list * head;
head=(struct books_list *)malloc(sizeof(struct books_list)); /*分配头节点空间*/
head->next=NULL; /*头节点指针域初始化,定为空*/
return head;
}
/*保存数据至文件*/
void save(struct books_list * head)
{
struct books_list *p;
FILE *fp;
p=head;
fp=fopen("data.txt","w+"); /*以写方式新建并打开 data.txt文件*/
fprintf(fp,"┏━━━┳━━━━━┳━━━━━┳━━━━━┳━━━━━━┳━━━┳━━━━┓\n"); /*向文件输出表格*/
fprintf(fp,"┃登录号┃ 书 名 ┃ 作 者┃ 出版单位 ┃ 出版时间 ┃分类号┃ 价格 ┃\n");
fprintf(fp,"┣━━━╋━━━━━╋━━━━━╋━━━━━╋━━━━━━╋━━━╋━━━━┫\n");
/*指针从头节点开始移动,遍历至尾结点,依次输出图书信息*/ while(p->next!= NULL)
{
p=p->next;
fprintf(fp,"┃%-6.6s┃%-10.10s┃%-10.10s┃%-10.10s┃%-12.12s┃%-6.6s┃%.2f ┃\n",p->loginnum,p->bookname,p->author,p->publisher,p->pbtime,p->classfy,p->price);
}
fprintf(fp,"┗━━━┻━━━━━┻━━━━━┻━━━━━┻━━━━━━┻━━━┻━━━━┛\n");
fclose(fp);
printf(" 已将图书数据保存到 data.txt 文件\n");
}
/*插入*/
void InsertDoc(struct books_list *head)
{
/*定义结构体指针变量 s指向开辟的新结点首地址 p为中间变量*/ struct books_list *s, *p;
char flag='Y'; /*定义flag, 方便用户选择重复输入*/
p=head;
/*遍历到尾结点,p 指向尾结点*/
while(p->next!= NULL)
{
p=p->next;
}
/*开辟新空间, 存入数据, 添加进链表*/
while(flag=='Y'||flag=='y')
{
s=(struct books_list *)malloc(sizeof(struct books_list)); printf("\n 请输入图书登陆号:");
fflush(stdin);
scanf("%s",s->loginnum);
printf("\n 请输入图书书名:");
fflush(stdin);
scanf("%s",s->bookname);
printf("\n 请输入图书作者名:");
fflush(stdin);
scanf("%s",s->author);
printf("\n 请输入图书出版社:");
fflush(stdin);
scanf("%s",s->publisher);
printf("\n 请输入图书出版时间:");
fflush(stdin);
scanf("%s",s->pbtime);
printf("\n 请输入图书分类号:");
fflush(stdin);
scanf("%s",s->classfy);
printf("\n 请输入图书价格:");
fflush(stdin);
scanf("%f",&s->price); printf("\n");
p->next=s; /*将新增加的节点添加进链表*/ p=s; /*p指向尾节点,向后移*/ s->next=NULL;
printf(" ━━━━ 添加成功!━━━━");
printf("\n 继续添加?(Y/N):"); fflush(stdin); scanf("%c",&flag); printf("\n");
if(flag=='N'||flag=='n') {break;}
else if(flag=='Y'||flag=='y') {continue;} }
save(head); /*保存数据至文件*/ return; }
/*查询操作*/
void search_book(struct books_list *head) {
struct books_list * p; char temp[20]; p=head;
if(head==NULL || head->next==NULL) /*判断数据库是否为空*/ {
printf(" ━━━━ 图书库为空!━━━━\n"); } else {
printf("请输入您要查找的书名: "); fflush(stdin);
scanf("%s",temp);
/*指针从头节点开始移动,遍历至尾结点,查找书目信息*/ while(p->next!= NULL) {
p=p->next;
if(strcmp(p->bookname,temp)==0) {
printf("\n图书已找到!\n"); printf("\n");
printf("登录号: %s\t\n",p->loginnum); printf("书名: %s\t\n",p->bookname); printf("作者名: %s\t\n",p->author);
printf("出版单位: %s\t\n",p->publisher); printf("出版时间: %s\t\n",p->pbtime); printf("分类号: %s\t\n",p->classfy); printf("价格: %.2f\t\n",p->price); }
if(p->next==NULL) {
printf("\n查询完毕!\n"); } } }
return; }
/*浏览操作*/
void Print_Book_Doc(struct books_list * head) {
struct books_list * p;
if(head==NULL || head->next==NULL) /*判断数据库是否为空*/ {
printf("\n ━━━━ 没有图书记 录! ━━━━\n\n"); return; }
p=head;
printf("┏━━━┳━━━━━┳━━━━━┳━━━━━┳━━━━━━┳━━━┳━━━━┓\n");
pri ntf("┃登录号┃ 书 名 ┃ 作 者┃ 出版单位 ┃ 出版时间 ┃分类号┃ 价格 ┃\n");
printf("┣━━━╋━━━━━╋━━━━━╋━━━━━╋━━━━━━╋━━━╋━━━━┫\n");
/*指针从头节点开始移动,遍历至尾结点,依次输出图书信息*/ while(p->next!= NULL) {
p=p->next;
printf("┃%-6.6s┃%-10.10s┃%-10.10s┃%-10.10s┃%-12.12s┃%-6.6s┃%.2f ┃\n",p->loginnum,p->bookname,p->author,p->publisher,p->pbtime,p->classfy,p->price); /*循环输出表格*/ }
printf("┗━━━┻━━━━━┻━━━━━┻━━━━━┻━━━━━━┻━━━┻━━━━┛\n"); printf("\n"); }
/*修改操作*/
void info_change(struct books_list * head) {
struct books_list * p;
int panduan=0; /*此变量用于判断是否找到书目*/ char temp[20]; p=head;
printf("请输入要修改的书名:"); scanf("%s",temp); while(p->next!= NULL) {p=p->next;
if(strcmp(p->bookname,temp)==0) {
printf("\n 登陆卡号:");
fflush(stdin);
scanf("%s",p->loginnum);
printf("\n 书名:");
fflush(stdin);
scanf("%s",p->bookname);
printf("\n 作者名:");
fflush(stdin);
scanf("%s",p->author);
printf("\n 出版社:");
fflush(stdin);
scanf("%s",p->publisher);
printf("\n 出版时间:");
fflush(stdin);
请输入图书请输入图书请输入图书请输入图书请输入图书
scanf("%s",p->pbtime);
printf("\n 请输入图书分类号:");
fflush(stdin);
scanf("%s",p->classfy);
printf("\n 请输入图书价格:");
fflush(stdin);
scanf("%f",&p->price); printf("\n"); panduan=1;}} if(panduan==0) {
printf("\n ━━━━ 没有图书记录! ━━━━\n\n");} return;}
/*删除操作*/
void DeleteDoc(struct books_list * head) {
struct books_list *s,*p; /*s为中间变量,p 为遍历时使用的指针*/
char temp[20];
int panduan; /*此变量用于判断是否找到了书目*/ panduan=0; p=s=head;
printf(" [请输入您要删除的书名]:"); scanf("%s",temp); /*遍历到尾结点*/ while(p!= NULL) {
if(strcmp(p->bookname,temp)==0) {
panduan++; break; }
p=p->next; }
if(panduan==1) {
for(;s->next!=p;) /*找到所需删除卡号结点的上一个结点*/ {
s=s->next; }
s->next=p->next; /*将后一节点地址赋值给前一节点的指针域*/ free(p);
printf("\n ━━━━ 删除成功! ━━━━\n"); }
else /*未找到相应书目*/ {
printf(" 目不存在,请确认后输入!\n"); }
return; }
int main(void) {
struct books_list * head; char choice; head=NULL;
for(;;) /*实现反复输入选择*/ {
printf(" ━━━━━━━━━┏━┓\n");
printf(" socat 图书管理系统 printf(" ━━━━━━━━━━┛ ┃\n");
printf(" ●[1]图书信息录入 printf(" ┃\n");
printf(" ●[2]图书信息浏览 printf(" ┃\n");
printf(" ●[3]图书信息查询 printf(" ┃\n");
您输入的书 ┃ ┃ ┃\n");
┗━━━━━━━━━ ┃\n"); ┃\n"); ┃\n");
┏━┓━━━━━━━━━━ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃
printf(" ┃ ●[4]图书信息修改 ┃\n"); printf(" ┃ ┃\n");
printf(" ┃ ●[5]图书信息删除 ┃\n"); printf(" ┃ ┃\n");
printf(" ●[6]退出系统 printf(" ━━━━━━━━━━━┛\n");
printf(" 请选择:"); fflush(stdin);
scanf("%c",&choice); if(choice=='1') {
if(head==NULL) {
head=Create_Books_Doc(); }
InsertDoc(head); }
else if(choice=='2') {
Print_Book_Doc(head); }
else if(choice=='3') {
search_book(head); }
else if(choice=='4') {
info_change(head); }
else if(choice=='5') {
DeleteDoc(head); }
else if(choice=='6')
┃ ┃\n"); ┗━━━━━━━━━━━━
{
printf("\n");
printf(" ━━━━━━━━ 感谢使用图书管理系统 ━━━━━━━━\n"); break; } else {
printf(" ━━━━ 输入错误,请重新输入!━━━━"); break; } }
return 0; }
十一、 参考文献
[1] 严蔚敏. 数据结构(C 语言版).清华大学出版社, 1997年
[2] 殷人昆 .数据结构 .清华大学出版社 ,2001年第1版 [3] 谢楚屏 .数据结构.人民邮电出版社, 1994年10月 [4] 许文献. 数据结构 .北京科技大学,2004年 [5] 陈向群 .数据结构 .人民邮电出版社,2001年 [6] 邓文化.数据结构 .清华大学出版社,2004年 [7] 李从丽等 .数据结构 .南京大学出版社,2003年
........ 忽略此处.......
数据结构课程设计
报 告
设计题目: 小型图书馆管理系统
专 业: 信息管理与信息系统
学生姓名:
班级学号:
指导教师:
2010 年6月25 日
数据结构课程设计报告
一、 设计时间
2010/6/21-------6/25
二、 设计地点
第一实验楼计算机系机房511
三、 设计目的
1、学习数据结构理论知识, 进一步熟悉基本概念;
2、熟练掌握链表的创建以及进行插入,排序,查找,删除等操作,了
解程序基本的流程。能根据实际问题的具体情况,结合数据结构中
的基本理论和基本算法,正确分析出数据的逻辑结构,合理的选择
相应的存储结构,并能设计出解决问题的有效算法;
3、运用所学C 语言知识,了解并掌握开发的各个流程,以及各功能代
码的实现。我们通过上机学习,学会有效利用基本的调试方法,找
出程序中出现的错误代码并修改;
4、培养查阅资料,独立思考问题的能力。
四、 设计小组成
五、 指导老师
六、 设计课题
小型图书馆管理系统
七、 基本思路及关键问题的解决方法
根据老师给的课题要求,小型图书管理系统的设计主要可以分为图
书信息录入、图书信息浏览、图书信息查询、图书信息修改、图书信息
删除几大功能块。由于课题要求系统得到设计必须用C 语言和数据结构
的相关知识,所以我们首先要创建一个新链表并用链表的每个节点存储
一条图书记录,即结构体(book ),其中各域分别为:分类号(classfy ) 、书
名(bookname ) 、作者(author ) 、定价(price ) 、出版社(publisher ) ,指针域(next)。
小型图书馆系统的信息录入、信息浏览、信息查询、信息修改、信息删
除功能快的实现分别用InsertDoc ,search_book,Print_Book_Doc,
info_change ,DeleteDoc 等来实现。
八、 算法及流程图
(1)主要算法
1、存储结构定义 struct books_list
{char author[20]; /*作者名*/
char bookname[20]; /*书名*/
char publisher[20]; /*出版单位*/
char pbtime[15]; /*出版时间*/
char loginnum[10]; /*登陆号*/
float price; /*价格*/
char classfy[10]; /*分类号*/
struct books_list * next; /*链表的指针域*/
};
struct books_list * Create_Books_Doc(); /*新建链表*/
void InsertDoc(struct books_list * head); /*插入*/
void DeleteDoc(struct books_list * head , int num);/*删除*/
void Print_Book_Doc(struct books_list * head);/*浏览*/
void search_book(struct books_list * head); /*查询*/
void info_change(struct books_list * head);/*修改*/
void save(struct books_list * head);/*保存数据至文件*/
2、新建链表头节点
struct books_list * Create_Books_Doc()
{
struct books_list * head;
head=(struct books_list *)malloc(sizeof(struct books_list));
/*分配头节点空间*/
head->next=NULL; /*头节点指针域初始化,定为空*/
return head;
3、用insterdoc 实现插入操作
void InsertDoc(struct books_list *head)
{
/*定义结构体指针变量 s指向开辟的新结点首地址 p为中间变量
*/
struct books_list *s, *p;
char flag='Y'; /*定义flag, 方便用户选择重复输入*/ p=head; /*遍历到尾结点,p 指向尾结点*/ while(p->next!= NULL) { p=p->next; }„}
4、用search_book实现查询操作
void search_book(struct books_list *head)
{
struct books_list * p;
char temp[20];
p=head;
if(head==NULL || head->next==NULL) /*判断数据库是否为空*/
{
printf(" ━━━
━ 图书库为空!━━━━\n");
}„}
5、用Print_Book_Doc来实现浏览操作
void Print_Book_Doc(struct books_list * head)
{
struct books_list * p;
if(head==NULL || head->next==NULL) /*判断数据库是否为空
*/
{
printf("\n ━
━━━ 没有图书记 录! ━━━━\n\n");
return; }
p=head;
printf("┏━━━┳━━━━━┳━━━━━┳━━━━━┳━━━━
━━┳━━━┳━━━━┓\n");
printf("┃登录号┃ 书 名 ┃ 作 者┃ 出版单位 ┃ 出
版时间 ┃分类号┃ 价格 ┃\n");
printf("┣━━━╋━━━━━╋━━━━━╋━━━━━╋━━━━━━
╋━━━╋━━━━┫\n");
/*指针从头节点开始移动,遍历至尾结点,依次输出图书信息*/
while(p->next!= NULL){
p=p->next;
printf("┃%-6.6s┃%-10.10s┃%-10.10s┃%-10.10s┃%-12.12s
┃%-6.6s┃%.2f ┃\n",p->loginnum,p->bookname,p->author,p->publish
er,p->pbtime,p->classfy,p->price); /*循环输出表格*/}
printf("┗━━━┻━━━━━┻━━━━━┻━━━━━┻━━━━━━
┻━━━┻━━━━┛\n");
printf("\n");
}
6、用info_change来实现修改操作
void info_change(struct books_list * head)
{
struct books_list * p;
int panduan=0; /*此变量用于判断是否找到书目*/
char temp[20];
p=head;
printf("请输入要修改的书名:");
scanf("%s",temp);
while(p->next!= NULL)
{
p=p->next;
if(strcmp(p->bookname,temp)==0)
{
printf("\n
图书登陆卡号:");
fflush(stdin);
scanf("%s",p->loginnum);
„ „ „
fflush(stdin);
scanf("%s",p->classfy);
printf("\n
图书价格:");
fflush(stdin);
scanf("%f",&p->price);
printf("\n");
panduan=1;
}
}
if(panduan==0)
{
printf("\n
━━ 没有图书记录! ━━━━\n\n");
}
return;}
7、用DeleteDoc 来实现删除操作
void DeleteDoc(struct books_list * head) 请输入请输入 ━━
{
struct books_list *s,*p; /*s为中间变量,p 为遍历时使
用的指针*/
char temp[20];
int panduan; /*此变量用于判断是否找到了书目*/
panduan=0;
p=s=head;
printf(" [请输入
您要删除的书名]:");
scanf("%s",temp);
(2)程序流程
系统的执行应从功能菜单的选择开始,依据用户的选择来进行的处理
直到用户选择退出系统为止,其间应对用户的选择做出判断及异常处
理。流程图如下:
程中难免会出现各种各样的错误,导致我们的写的程序不能够正常运行。
我在小型图书管理系统的设计过程中就出现一些或难或易得问题。小到因为粗心大意丢失了“;”,而在编译窗口出现几十个错误。其实错误并不可怕,主要是要找到错误的根源,那样错误就可以任意的被纠正。在我调试的过程中,出现的另一个错误,我吓了一跳。不过好在编译器帮我找到了问题的所在,原来是中间变量P 没有定义。发现了问题所以很容易就解决
啦。由于我的问题很多但是都是一些常见且简单的问题,所以也不在这里
赘述啦。
(1) 执行VC++;(2) 打开library.CPP 文件;(3) 进入系统操作界面;
(4) 进入后根据提示信息可进行:
“ 1、图书信息录入; 2、图书信息浏览; 3、图书信息查询 ;
4、图书信息修改 ;5、图书信息删除;6、退出系统 。
九、 课程设计心得体会
一晃眼,大二第二学期就要结束了。每期一次的课程设计开始了,
这次我的数据结构课程设计的题目是《小型图书馆管理系统》。说实话,刚开始拿到这个题目我的唯一感觉就是头痛。第一次一个人尝试去做一个系统,虽然是小型的,但是还是有点心怯。回想前几次课程设计,我的心收集瞬间勇敢了起来。因为我们学校有图书馆可以借相关书籍,班集体里有同学的热心帮助,机房里还有指导老师的悉心指导,还有网络上的海量信息。虽然老师要求我们独立完成,但是我还是可以去查找相关资料的。
在17周的星期一我开始了我的课程设计,万事开头难,我的课程设计也不例外。开始的时候就遇到了一些不大不小的问题,不过最后我都一一克服啦。当然这些问题的解决离不开老师和同学的无私帮助。到了程序的调试阶段,也是最让我纠心的阶段。总是出现多种各样的问题,不过经过两个小时的艰苦奋战终于它通过了。但是我的课程设计最为难的地方却是算法分析,因为我以前没有写过算法。于是我去网上找到了好多关于算法的资料,也去图书馆借了算法的相关书籍。最后算法也如期的完成了。
这次数据结构的课程设计我收获了很多。对数据结构的知识有进一步的认知,但是跟多的收获是在学习方法上。我们专业的学习不能够只停留在一些理论知识的掌握,还应与实践结合在一起。通过不断的实践和理论的结合练习,提高自己的能力。在这次的课程设计当中也发现了自己的不足:缺少实际动手能力,不过我会在学习中不断的充实自我,改正自我,提高自我。
十、 源程序(见电子文档)
#include
#include
#include
#include
struct books_list
{
char author[20]; /*作者名*/ char bookname[20]; /*书名*/ char publisher[20]; /*出版单位*/
char pbtime[15]; /*出版时间*/ char loginnum[10]; /*登陆号*/
float price; /*价格*/ char classfy[10]; /*分类号*/ struct books_list * next; /*链表的指针域*/
};
struct books_list * Create_Books_Doc(); /*新建链表*/ void InsertDoc(struct books_list * head); /*插入*/
void DeleteDoc(struct books_list * head , int num);/*删除*/ void Print_Book_Doc(struct books_list * head);/*浏览*/ void search_book(struct books_list * head); /*查询*/ void info_change(struct books_list * head);/*修改*/
void save(struct books_list * head);/*保存数据至文件*/ /*新建链表头节点*/
struct books_list * Create_Books_Doc()
{
struct books_list * head;
head=(struct books_list *)malloc(sizeof(struct books_list)); /*分配头节点空间*/
head->next=NULL; /*头节点指针域初始化,定为空*/
return head;
}
/*保存数据至文件*/
void save(struct books_list * head)
{
struct books_list *p;
FILE *fp;
p=head;
fp=fopen("data.txt","w+"); /*以写方式新建并打开 data.txt文件*/
fprintf(fp,"┏━━━┳━━━━━┳━━━━━┳━━━━━┳━━━━━━┳━━━┳━━━━┓\n"); /*向文件输出表格*/
fprintf(fp,"┃登录号┃ 书 名 ┃ 作 者┃ 出版单位 ┃ 出版时间 ┃分类号┃ 价格 ┃\n");
fprintf(fp,"┣━━━╋━━━━━╋━━━━━╋━━━━━╋━━━━━━╋━━━╋━━━━┫\n");
/*指针从头节点开始移动,遍历至尾结点,依次输出图书信息*/ while(p->next!= NULL)
{
p=p->next;
fprintf(fp,"┃%-6.6s┃%-10.10s┃%-10.10s┃%-10.10s┃%-12.12s┃%-6.6s┃%.2f ┃\n",p->loginnum,p->bookname,p->author,p->publisher,p->pbtime,p->classfy,p->price);
}
fprintf(fp,"┗━━━┻━━━━━┻━━━━━┻━━━━━┻━━━━━━┻━━━┻━━━━┛\n");
fclose(fp);
printf(" 已将图书数据保存到 data.txt 文件\n");
}
/*插入*/
void InsertDoc(struct books_list *head)
{
/*定义结构体指针变量 s指向开辟的新结点首地址 p为中间变量*/ struct books_list *s, *p;
char flag='Y'; /*定义flag, 方便用户选择重复输入*/
p=head;
/*遍历到尾结点,p 指向尾结点*/
while(p->next!= NULL)
{
p=p->next;
}
/*开辟新空间, 存入数据, 添加进链表*/
while(flag=='Y'||flag=='y')
{
s=(struct books_list *)malloc(sizeof(struct books_list)); printf("\n 请输入图书登陆号:");
fflush(stdin);
scanf("%s",s->loginnum);
printf("\n 请输入图书书名:");
fflush(stdin);
scanf("%s",s->bookname);
printf("\n 请输入图书作者名:");
fflush(stdin);
scanf("%s",s->author);
printf("\n 请输入图书出版社:");
fflush(stdin);
scanf("%s",s->publisher);
printf("\n 请输入图书出版时间:");
fflush(stdin);
scanf("%s",s->pbtime);
printf("\n 请输入图书分类号:");
fflush(stdin);
scanf("%s",s->classfy);
printf("\n 请输入图书价格:");
fflush(stdin);
scanf("%f",&s->price); printf("\n");
p->next=s; /*将新增加的节点添加进链表*/ p=s; /*p指向尾节点,向后移*/ s->next=NULL;
printf(" ━━━━ 添加成功!━━━━");
printf("\n 继续添加?(Y/N):"); fflush(stdin); scanf("%c",&flag); printf("\n");
if(flag=='N'||flag=='n') {break;}
else if(flag=='Y'||flag=='y') {continue;} }
save(head); /*保存数据至文件*/ return; }
/*查询操作*/
void search_book(struct books_list *head) {
struct books_list * p; char temp[20]; p=head;
if(head==NULL || head->next==NULL) /*判断数据库是否为空*/ {
printf(" ━━━━ 图书库为空!━━━━\n"); } else {
printf("请输入您要查找的书名: "); fflush(stdin);
scanf("%s",temp);
/*指针从头节点开始移动,遍历至尾结点,查找书目信息*/ while(p->next!= NULL) {
p=p->next;
if(strcmp(p->bookname,temp)==0) {
printf("\n图书已找到!\n"); printf("\n");
printf("登录号: %s\t\n",p->loginnum); printf("书名: %s\t\n",p->bookname); printf("作者名: %s\t\n",p->author);
printf("出版单位: %s\t\n",p->publisher); printf("出版时间: %s\t\n",p->pbtime); printf("分类号: %s\t\n",p->classfy); printf("价格: %.2f\t\n",p->price); }
if(p->next==NULL) {
printf("\n查询完毕!\n"); } } }
return; }
/*浏览操作*/
void Print_Book_Doc(struct books_list * head) {
struct books_list * p;
if(head==NULL || head->next==NULL) /*判断数据库是否为空*/ {
printf("\n ━━━━ 没有图书记 录! ━━━━\n\n"); return; }
p=head;
printf("┏━━━┳━━━━━┳━━━━━┳━━━━━┳━━━━━━┳━━━┳━━━━┓\n");
pri ntf("┃登录号┃ 书 名 ┃ 作 者┃ 出版单位 ┃ 出版时间 ┃分类号┃ 价格 ┃\n");
printf("┣━━━╋━━━━━╋━━━━━╋━━━━━╋━━━━━━╋━━━╋━━━━┫\n");
/*指针从头节点开始移动,遍历至尾结点,依次输出图书信息*/ while(p->next!= NULL) {
p=p->next;
printf("┃%-6.6s┃%-10.10s┃%-10.10s┃%-10.10s┃%-12.12s┃%-6.6s┃%.2f ┃\n",p->loginnum,p->bookname,p->author,p->publisher,p->pbtime,p->classfy,p->price); /*循环输出表格*/ }
printf("┗━━━┻━━━━━┻━━━━━┻━━━━━┻━━━━━━┻━━━┻━━━━┛\n"); printf("\n"); }
/*修改操作*/
void info_change(struct books_list * head) {
struct books_list * p;
int panduan=0; /*此变量用于判断是否找到书目*/ char temp[20]; p=head;
printf("请输入要修改的书名:"); scanf("%s",temp); while(p->next!= NULL) {p=p->next;
if(strcmp(p->bookname,temp)==0) {
printf("\n 登陆卡号:");
fflush(stdin);
scanf("%s",p->loginnum);
printf("\n 书名:");
fflush(stdin);
scanf("%s",p->bookname);
printf("\n 作者名:");
fflush(stdin);
scanf("%s",p->author);
printf("\n 出版社:");
fflush(stdin);
scanf("%s",p->publisher);
printf("\n 出版时间:");
fflush(stdin);
请输入图书请输入图书请输入图书请输入图书请输入图书
scanf("%s",p->pbtime);
printf("\n 请输入图书分类号:");
fflush(stdin);
scanf("%s",p->classfy);
printf("\n 请输入图书价格:");
fflush(stdin);
scanf("%f",&p->price); printf("\n"); panduan=1;}} if(panduan==0) {
printf("\n ━━━━ 没有图书记录! ━━━━\n\n");} return;}
/*删除操作*/
void DeleteDoc(struct books_list * head) {
struct books_list *s,*p; /*s为中间变量,p 为遍历时使用的指针*/
char temp[20];
int panduan; /*此变量用于判断是否找到了书目*/ panduan=0; p=s=head;
printf(" [请输入您要删除的书名]:"); scanf("%s",temp); /*遍历到尾结点*/ while(p!= NULL) {
if(strcmp(p->bookname,temp)==0) {
panduan++; break; }
p=p->next; }
if(panduan==1) {
for(;s->next!=p;) /*找到所需删除卡号结点的上一个结点*/ {
s=s->next; }
s->next=p->next; /*将后一节点地址赋值给前一节点的指针域*/ free(p);
printf("\n ━━━━ 删除成功! ━━━━\n"); }
else /*未找到相应书目*/ {
printf(" 目不存在,请确认后输入!\n"); }
return; }
int main(void) {
struct books_list * head; char choice; head=NULL;
for(;;) /*实现反复输入选择*/ {
printf(" ━━━━━━━━━┏━┓\n");
printf(" socat 图书管理系统 printf(" ━━━━━━━━━━┛ ┃\n");
printf(" ●[1]图书信息录入 printf(" ┃\n");
printf(" ●[2]图书信息浏览 printf(" ┃\n");
printf(" ●[3]图书信息查询 printf(" ┃\n");
您输入的书 ┃ ┃ ┃\n");
┗━━━━━━━━━ ┃\n"); ┃\n"); ┃\n");
┏━┓━━━━━━━━━━ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃
printf(" ┃ ●[4]图书信息修改 ┃\n"); printf(" ┃ ┃\n");
printf(" ┃ ●[5]图书信息删除 ┃\n"); printf(" ┃ ┃\n");
printf(" ●[6]退出系统 printf(" ━━━━━━━━━━━┛\n");
printf(" 请选择:"); fflush(stdin);
scanf("%c",&choice); if(choice=='1') {
if(head==NULL) {
head=Create_Books_Doc(); }
InsertDoc(head); }
else if(choice=='2') {
Print_Book_Doc(head); }
else if(choice=='3') {
search_book(head); }
else if(choice=='4') {
info_change(head); }
else if(choice=='5') {
DeleteDoc(head); }
else if(choice=='6')
┃ ┃\n"); ┗━━━━━━━━━━━━
{
printf("\n");
printf(" ━━━━━━━━ 感谢使用图书管理系统 ━━━━━━━━\n"); break; } else {
printf(" ━━━━ 输入错误,请重新输入!━━━━"); break; } }
return 0; }
十一、 参考文献
[1] 严蔚敏. 数据结构(C 语言版).清华大学出版社, 1997年
[2] 殷人昆 .数据结构 .清华大学出版社 ,2001年第1版 [3] 谢楚屏 .数据结构.人民邮电出版社, 1994年10月 [4] 许文献. 数据结构 .北京科技大学,2004年 [5] 陈向群 .数据结构 .人民邮电出版社,2001年 [6] 邓文化.数据结构 .清华大学出版社,2004年 [7] 李从丽等 .数据结构 .南京大学出版社,2003年
........ 忽略此处.......