图书管理系统C语言实现源代码Word格式文档下载.docx
- 文档编号:18762264
- 上传时间:2023-01-01
- 格式:DOCX
- 页数:18
- 大小:18.07KB
图书管理系统C语言实现源代码Word格式文档下载.docx
《图书管理系统C语言实现源代码Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《图书管理系统C语言实现源代码Word格式文档下载.docx(18页珍藏版)》请在冰豆网上搜索。
};
intmain(void)
{
intx=1,n,k;
structbook*head;
charch;
/*charmima[12];
printf("
请输入密码\n"
);
for(i=1;
i<
=3;
i++)
{
scanf("
%s"
mima);
if(strcmp(mima,"
201046830904"
)==0)
{
x=1;
break;
}
else
printf("
密码输入有误,请重新输入!
\n"
}*/
while(x)
{system("
cls"
printf("
*******************************************************************************\n"
图书管理系统\n"
0---退出系统1---录入数据\n"
2---保存文件3---输出信息\n"
4---根据编号查询信息5---插入数据\n"
6---删除数据7---修改数据\n"
8---统计图书数目9---根据价格排序\n"
10--从文件读取数据\n"
scanf("
%d"
&
n);
getchar();
switch(n)
case0:
x=0;
break;
case1:
head=chu_jian();
case2:
if(head==NULL||head->
next==NULL)
{
printf("
请先录入图书的数据!
"
getchar();
break;
}
else
baocun(head);
case3:
printf_(head);
case4:
else{
num_chaxun(head);
case5:
head=charu(head);
case6:
head=shanchu(head);
case7:
{
xiugai(head);
case8:
k=tongji(head);
总共有%3d本图书"
k);
case9:
head=paixu(head);
是否显示排序结果Y/N"
ch=getchar();
if(ch=='
y'
||ch=='
Y'
)
{
printf("
printf_(head);
}
case10:
head=load();
next==NULL){
default:
printf("
输入有误,请重新输入!
getchar();
}
return0;
}
//建立链表,并输入数据
structbook*chu_jian()
structbook*head,*tail,*p;
charnum[N],name[M],autor[L],dizhi[K],leixing[E],time[F];
head=tail=NULL;
当输入价格为0时则结束\n"
输入编号书名作者出版社类型时间价格\n"
%s%s%s%s%s%s%f"
num,name,autor,dizhi,leixing,time,&
price);
while(price!
=0)
p=(structbook*)malloc(sizeof(structbook));
strcpy(p->
num,num);
name,name);
strcpy(p->
autor,autor);
dizhi,dizhi);
leixing,leixing);
time,time);
p->
price=price;
next=NULL;
if(head==NULL)
head=p;
tail->
next=p;
tail=p;
getchar();
returnhead;
//保存链表至文件
voidbaocun(structbook*head)
structbook*ptr;
FILE*fp;
if((fp=fopen("
图书管理系统.txt"
"
w"
))==NULL)
文件图书管理系统.txt打开失败!
exit(0);
for(ptr=head;
ptr;
ptr=ptr->
next)
fprintf(fp,"
%10s%10s%10s%10s%10s%10s%20f\n"
ptr->
num,ptr->
name,ptr->
autor,ptr->
dizhi,ptr->
leixing,ptr->
time,ptr->
fclose(fp);
文件成功保存到图书管理系统.txt中\n"
//输出图书的信息
voidprintf_(structbook*head)
structbook*p;
p=head;
if(head!
=NULL)
do
编号:
puts(p->
num);
书名:
name);
作者:
autor);
出版社:
dizhi);
类型:
leixing);
时间:
time);
价格:
%f"
p->
p=p->
next;
}while(p!
=NULL);
//根据图书的编号查询图书的信息,并输出数据
voidnum_chaxun(structbook*head)
chara[N];
输入要查询的图书的编号:
gets(a);
while(p!
=NULL){
if(strcmp(p->
num,a)==0)
p=p->
if(p==NULL)
没有找到编号为%s的图书!
a);
else{
num,p->
name,p->
autor,p->
dizhi,p->
leixing,p->
time,p->
}
structbook*shanchu(structbook*head)
structbook*p1,*p2,*p3;
输入要删除的图书的编号:
p1=head;
p2=p1;
while(p2!
=NULL&
&
(strcmp(p2->
num,a)!
=0))
p3=p2;
p2=p2->
if(p2==NULL)
没有找到要删除的数据!
elseif(p2==head){
head=p2->
删除成功\n"
p3->
next=p2->
//统计图书的总数目
inttongji(structbook*head)
intx=0;
for(p=head;
p!
=NULL;
p=p->
x++;
returnx;
//根据价格排序
structbook*paixu(structbook*head)
structbook*p1,*p2,*p3,*p4,*p5,*p6,*p7;
intx=1;
for(p1=head;
p1->
next!
p4=p1,p1=p1->
next)
{
p3=p1;
for(p2=p1->
next,p5=p7=p2;
p2!
p7=p2,p2=p2->
if(p3->
price>
p2->
price)
p3=p2;
p5=p7;
}
if(p3!
=p1)
if(x&
p1==head)
p6=p1->
p1->
next=p3->
p3->
next=p6;
p5->
next=p1;
head=p3;
p1=p3;
x=0;
else
p4->
next=p3;
排序成功!
//从文件中读入图书信息
structbook*load()
structbook*p1,*tail,*head;
r"
while(!
feof(fp))
p1=(structbook*)malloc(sizeof(structbook));
fscanf(fp,"
num,&
name,&
autor,&
dizhi,&
leixing,&
time,&
if(head==NULL)
head=p1;
tail=p1;
tail->
next=NULL;
//修改图书信息
voidxiugai(structbook*head)
intk;
输入要修改的图书的编号"
没有要找的图书信息\n"
else
***********************************************************\n"
0--放弃修改1--修改编号\n"
2--修改书名3--修改作者\n"
4--修改出版社5--修改类型\n"
6--修改出版时间7--修改价格\n"
8--修改全部\n"
k);
switch(k)
case1:
请输入新的编号:
gets(p->
修改成功!
case2:
请输入新的书名:
请输入新的作者:
请输入新的出版社:
case5:
请输入新的类型:
case6:
请输入新的出版时间:
case7:
请输入新的价格:
scanf("
p->
price=price;
case8:
请输入编号书名作者出版社类型出版时间价格\n"
default:
您的输入有误!
//插入图书的信息
structbook*charu(structbook*head)
structbook*p1,*p2,*p3;
p1=(structbook*)malloc(sizeof(structbook));
strcpy(p1->
p3=head;
while((strcmp(p1->
num,p3->
num)>
0)&
(p3->
=NULL)){
p2=p3;
p3=p3->
if(strcmp(p1->
num)<
=0){
if(head==p3)
head=p1;
else
p2->
p1->
else{
p3->
p1-
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 图书 管理 系统 语言 实现 源代码
![提示](https://static.bdocx.com/images/bang_tan.gif)