小型图书馆管理系统c语言版.docx
《小型图书馆管理系统c语言版.docx》由会员分享,可在线阅读,更多相关《小型图书馆管理系统c语言版.docx(30页珍藏版)》请在冰豆网上搜索。
小型图书馆管理系统c语言版
课程设计(大作业)报告
课程名称:
数据结构课程设计
设计题目:
小型图书馆管理系统
院系:
信息技术学院
班级:
计算机科学与技术3班
设计者:
学号:
*******
*******
设计时间:
2012.12.24--28
昆明学院课程设计(大作业)任务书
姓名:
院(系):
信息技术学院
专业:
计算机科学与技术学号:
*******
任务起止日期:
2012.12.24--28
课程设计题目:
小型图书馆管理系统
课程设计要求:
设计目的:
对C语言软件开发有一定的认识,了解并掌握开发的各个流程,以及各功能代
码的实现。
创建一个图书馆管理系统,可进行还书(插入),排序,查找,借书(删除)操
作。
设计原理:
⑴所有信息存储在一个带头结点的单向链表中,每个结点存储一条图书记录,即结构体(book),其中各域为:
书号(number)、书名(title)、作者(writer)、定价(pricing)、出版社(publishinghouse),指针域(next)。
⑵系统初始时图书记录为空,由用户录入信息,进行插入(包括创建),排序,查找,删除操作
⑶有两种排序算法可选:
选择排序和直接插入排序,均由链表实现
⑷如输入有错,给出出错提示
工作计划及安排:
⑴设计工作6学时
⑵实现与调试18学时
⑶课程设计说明书6学时
指导教师签字
年月日
课程设计(大作业)成绩
学号:
20111101姓名指导教师:
王亚宁
课程设计题目:
小型图书馆管理系统
总结:
在实验中我学会了和同学一起合作,共同实现一个系统的编写,我们分工合作,共同完成了
在这次课程设计中让我的编程能力得到了一定的提高,让我熟悉了链表的一些操作,但在这个过程中还是有很多地方难以下手,需要同学的帮助。
在这个过程中我更加的懂得了团结合作的重要性,学到了很多课本上学不到的东西,并且也锻炼了我的沟通协调能力,相信我会在这样每次的实践活动中提升自己!
指导教师评语:
成绩:
填表时间:
指导教师签名:
课程设计(大作业)报告
一、题目分析
本题是一个图书馆管理系统,涉及到c语言的一些基本操作,比如,构造结构体,插入,查找等!
这个程序包括构造一个结构体,域为:
书号,书名,作者,出版商,出版日期。
运用文件操作的方式实现文件的保存与调用!
用菜单界面来操作整个过程!
先写每个功能的程序,然后再组合起来,这样显得调理清晰,不容易乱!
二、基本理论
C语言的基本知识,比如结构体的构造,链表的操作,文件的操作
三、总体设计
函数功能:
structbooks_list*Create_Books_Doc();/*新建链表*/
voidInsertDoc(structbooks_list*head);/*插入*/
voidDeleteDoc(structbooks_list*head,intnum);/*删除*/
voidPrint_Book_Doc(structbooks_list*head);/*浏览*/
voidsearch_book(structbooks_list*head);/*查询*/
voidinfo_change(structbooks_list*head);/*修改*/
voidsave(structbooks_list*head);/*保存数据至文件*/
四、实验器材
Pc机
五、方法步骤
1.创建主函数main()
2新建数据文件create()
2.1为节点分配内存
2.2创建二进制文件用于存储图书信息
2.3通过一个循环一次录入图书信息
2.4关闭文件
3.编写删除数据纪录函数delete()
3.1打开文件
3.2遍历文件找到与指定图书信息匹配的记录并删除
3.3关闭文件
4.编写浏览数据记录函数Print_Book_Doc()
4.1打开文件
4.2遍历整个数据。
并显示在于界面上
4.3保存数据至文件
5建立查询函数search_book()
5.1打开文件
5.2遍历整个文件找到与指定图书匹配信息
5.3输出查询到的信息
5.4关闭文件
6.编写修改数据纪录函数info_change()
6.1打开文件
6.2遍历整个文件找到与指定图书信息匹配的记录并修改
6.3关闭文件
7.保存后结束整个程序
六、成效分析
我编写的部分
structbooks_list
{
charauthor[20];/*作者名*/
charbookname[20];/*书名*/
charpublisher[20];/*出版单位*/
charpbtime[15];/*出版时间*/
charloginnum[10];/*登陆号*/
floatprice;/*价格*/
charclassfy[10];/*分类号*/
structbooks_list*next;/*链表的指针域*/
};
structbooks_list*Create_Books_Doc();/*新建链表*/
voidInsertDoc(structbooks_list*head);/*插入*/
voidDeleteDoc(structbooks_list*head,intnum);/*删除*/
voidPrint_Book_Doc(structbooks_list*head);/*浏览*/
voidsearch_book(structbooks_list*head);/*查询*/
voidinfo_change(structbooks_list*head);/*修改*/
voidsave(structbooks_list*head);/*保存数据至文件*/
/*新建链表头节点*/
structbooks_list*Create_Books_Doc()
{
structbooks_list*head;
head=(structbooks_list*)malloc(sizeof(structbooks_list));/*分配头节点空间*/
head->next=NULL;/*头节点指针域初始化,定为空*/
returnhead;
}
/*保存数据至文件*/
voidsave(structbooks_list*head)
{
structbooks_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");
}
/*插入*/
voidInsertDoc(structbooks_list*head)
{
/*定义结构体指针变量s指向开辟的新结点首地址p为中间变量*/
structbooks_list*s,*p;
charflag='Y';/*定义flag,方便用户选择重复输入*/
p=head;
/*遍历到尾结点,p指向尾结点*/
while(p->next!
=NULL)
{
p=p->next;
}
/*开辟新空间,存入数据,添加进链表*/
while(flag=='Y'||flag=='y')
{
s=(structbooks_list*)malloc(sizeof(structbooks_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;}
elseif(flag=='Y'||flag=='y')
{continue;}
}
save(head);/*保存数据至文件*/
return;
}
/*修改操作*/
voidinfo_change(structbooks_list*head)
{
structbooks_list*p;
intpanduan=0;/*此变量用于判断是否找到书目*/
chartemp[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;
}
/*删除操作*/
voidDeleteDoc(structbooks_list*head)
{
structbooks_list*s,*p;/*s为中间变量,p为遍历时使用的指针*/
chartemp[20];
intpanduan;/*此变量用于判断是否找到了书目*/
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;
}
intmain(void)
{
structbooks_list*head;
charchoice;
head=NULL;
for(;;)/*实现反复输入选择*/
{
printf("┏━┓━━━━━━━━━━━━━━━━━━━┏━┓\n");
printf("┃┃socat图书管理系统┃┃\n");
printf("┃┗━━━━━━━━━━━━━━━━━━━┛┃\n");
printf("┃●[1]图书信息录入┃\n");
printf("┃┃\n");
printf("┃●[2]图书信息浏览┃\n");
printf("┃┃\n");
printf("┃●[3]图书信息查询┃\n");
printf("┃┃\n");
printf("┃●[4]图书信息修改┃\n");
printf("┃┃\n");
printf("┃●[5]图书信息删除┃\n");
printf("┃┃\n");
printf("┃●[6]退出系统┃\n");
printf("┗━━━━━━━━━━━━━━━━━━━━━━━┛\n");
printf("请选择:
");
fflush(stdin);
scanf("%c",&choice);
if(choice=='1')
{
if(head==NULL)
{
head=Create_Books_Doc();
}
InsertDoc(head);
}
elseif(choice=='2')
{
Print_Book_Doc(head);
}
elseif(choice=='3')
{
search_book(head);
}
elseif(choice=='4')
{
info_change(head);
}
elseif(choice=='5')
{
DeleteDoc(head);
}
elseif(choice=='6')
{
printf("\n");
printf("━━━━━━━━感谢使用图书管理系统━━━━━━━━\n");
break;
}
else
{
printf("━━━━输入错误,请重新输入!
━━━━");
break;
}
}return0;}
程序源代码
#include
#include
#include
#include
structbooks_list
{
charauthor[20];/*作者名*/
charbookname[20];/*书名*/
charpublisher[20];/*出版单位*/
charpbtime[15];/*出版时间*/
charloginnum[10];/*登陆号*/
floatprice;/*价格*/
charclassfy[10];/*分类号*/
structbooks_list*next;/*链表的指针域*/
};
structbooks_list*Create_Books_Doc();/*新建链表*/
voidInsertDoc(structbooks_list*head);/*插入*/
voidDeleteDoc(structbooks_list*head,intnum);/*删除*/
voidPrint_Book_Doc(structbooks_list*head);/*浏览*/
voidsearch_book(structbooks_list*head);/*查询*/
voidinfo_change(structbooks_list*head);/*修改*/
voidsave(structbooks_list*head);/*保存数据至文件*/
/*新建链表头节点*/
structbooks_list*Create_Books_Doc()
{
structbooks_list*head;
head=(structbooks_list*)malloc(sizeof(structbooks_list));/*分配头节点空间*/
head->next=NULL;/*头节点指针域初始化,定为空*/
returnhead;
}
/*保存数据至文件*/
voidsave(structbooks_list*head)
{
structbooks_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");
}
/*插入*/
voidInsertDoc(structbooks_list*head)
{
/*定义结构体指针变量s指向开辟的新结点首地址p为中间变量*/
structbooks_list*s,*p;
charflag='Y';/*定义flag,方便用户选择重复输入*/
p=head;
/*遍历到尾结点,p指向尾结点*/
while(p->next!
=NULL)
{
p=p->next;
}
/*开辟新空间,存入数据,添加进链表*/
while(flag=='Y'||flag=='y')
{
s=(structbooks_list*)malloc(sizeof(structbooks_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;}
elseif(flag=='Y'||flag=='y')
{continue;}
}
save(head);/*保存数据至文件*