小型图书管理系统C语言程序.docx

上传人:b****7 文档编号:23746323 上传时间:2023-05-20 格式:DOCX 页数:12 大小:15.80KB
下载 相关 举报
小型图书管理系统C语言程序.docx_第1页
第1页 / 共12页
小型图书管理系统C语言程序.docx_第2页
第2页 / 共12页
小型图书管理系统C语言程序.docx_第3页
第3页 / 共12页
小型图书管理系统C语言程序.docx_第4页
第4页 / 共12页
小型图书管理系统C语言程序.docx_第5页
第5页 / 共12页
点击查看更多>>
下载资源
资源描述

小型图书管理系统C语言程序.docx

《小型图书管理系统C语言程序.docx》由会员分享,可在线阅读,更多相关《小型图书管理系统C语言程序.docx(12页珍藏版)》请在冰豆网上搜索。

小型图书管理系统C语言程序.docx

小型图书管理系统C语言程序

小型图书管理系统C语言程序

#include

#include

#include

structbook

{

charwriter[20];

chartitle[20];

charpublishinghouse[20];

charnumber[10];

floatprice;

structbook*next;

};

structbook*Create_Book();

voidInsert(structbook*head);

voidDelete(structbook*head);

voidPrint_Book(structbook*head);

voidsearch_book(structbook*head);

voidchange_Book(structbook*head);

voidsave(structbook*head);

structbook*Create_Book()

{

structbook*head;

head=(structbook*)malloc(sizeof(structbook));

head->next=NULL;

returnhead;

}

voidsave(structbook*head)

{

structbook*p;

FILE*fp;

p=head;

fp=fopen("kucun.txt","w+");

fprintf(fp,"************************************************\n");

fprintf(fp,"书号\t书名\t作者\t出版社\t价格\t\n");

fprintf(fp,"\n");

while(p->next!

=NULL)

{

p=p->next;

fprintf(fp,"%s\t%s\t%s\t%s\t%.2f\t\n",p->number,p->title,p->writer,p->publishinghouse,p->price);

}

fprintf(fp,"************************************************\n");

fclose(fp);

printf("已将图书数据保存到kucun.txt文件\n");

}

//插入//

voidInsert(structbook*head)

{

structbook*s,*p,*p1,*swap;

charflag='Y';

swap=(structbook*)malloc(sizeof(structbook));

p1=swap;

p=head;

while(flag=='Y'||flag=='y')

{

s=(structbook*)malloc(sizeof(structbook));

printf("\n请输入图书书号:

");

fflush(stdin);

scanf("%s",s->number);

printf("\n请输入图书书名:

");

fflush(stdin);

scanf("%s",s->title);

printf("\n请输入图书作者名:

");

fflush(stdin);

scanf("%s",s->writer);

printf("\n请输入图书出版社:

");

fflush(stdin);

scanf("%s",s->publishinghouse);

printf("\n请输入图书价格:

");

fflush(stdin);

scanf("%f",&s->price);

printf("\n");

//排序//

p1=p->next;

if(head->next!

=NULL)

do

{

if(strcmp((p1->number),(s->number))>0)

{

strcpy(swap->number,p1->number);

strcpy(swap->title,p1->title);

strcpy(swap->writer,p1->writer);

strcpy(swap->publishinghouse,p1->publishinghouse);

swap->price=p1->price;

strcpy(p1->number,s->number);

strcpy(p1->title,s->title);

strcpy(p1->writer,s->writer);

strcpy(p1->publishinghouse,s->publishinghouse);

p1->price=s->price;

strcpy(s->number,swap->number);

strcpy(s->title,swap->title);

strcpy(s->writer,swap->writer);

strcpy(s->publishinghouse,swap->publishinghouse);

s->price=swap->price;

}

p=p1;

p1=p->next;

}while(p1!

=NULL);

p->next=s;

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);

}

//查找//

voidsearch_book(structbook*head)

{

structbook*p;

chartemp[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->title,temp)==0)

{

printf("\n图书已找到!

\n");

printf("\n");

printf("书号:

%s\t\n",p->number);

printf("书名:

%s\t\n",p->title);

printf("作者名:

%s\t\n",p->writer);

printf("出版社:

%s\t\n",p->publishinghouse);

printf("价格:

%.2f\t\n",p->price);

}

if(p->next==NULL)

{

printf("\n查询完毕!

\n");

}

}

}

}

voidPrint_Book(structbook*head)

{

structbook*p;

if(head==NULL||head->next==NULL)

{

printf("\n*******没有图书记录!

*******\n\n");

}

p=head;

printf("*************************************\n");

printf("书号\t书名\t作者\t出版社\t价格\t\n");

printf("*************************************\n");

while(p->next!

=NULL)

{

p=p->next;

printf("%s\t%s\t%s\t%s\t%.2f\t\n",p->number,p->title,p->writer,p->publishinghouse,p->price);

}

printf("*************************************\n");

printf("\n");

}

//更改//

voidchange_Book(structbook*head)

{

structbook*p;

intpanduan=0;

chartemp[20];

p=head;

printf("请输入要修改图书的书号:

");

scanf("%s",temp);

while(p->next!

=NULL)

{p=p->next;

if(strcmp(p->number,temp)==0)

{

printf("\n请输入图书书名:

");

fflush(stdin);

scanf("%s",p->title);

printf("\n请输入图书作者名:

");

fflush(stdin);

scanf("%s",p->writer);

printf("\n请输入图书出版社:

");

fflush(stdin);

scanf("%s",p->publishinghouse);

printf("\n请输入图书价格:

");

fflush(stdin);

scanf("%f",&p->price);

printf("\n");

panduan=1;}}

if(panduan==0)

{

printf("\n******没有图书记录!

******\n\n");}

}

//删除//

voidDelete(structbook*head)

{

structbook*s,*p;

chartemp[20];

intpanduan;

panduan=0;

p=s=head;

printf("[请输入您要删除的书名]:

");

scanf("%s",temp);

p=p->next;

while(p!

=NULL)

{

if(strcmp(p->title,temp)==0)

{

panduan=1;

break;

}

p=p->next;

}

if(panduan==1)

{

while(s->next!

=p)

{

s=s->next;

}

s->next=p->next;

free(p);

printf("\n*******删除成功!

*******\n");

save(head);

}

else

{

printf("您输入的书目不存在,请确认后输入!

\n");

}

}

//主函数//

voidmain()

{

structbook*head;

intchoice;

head=NULL;

while

(1)

{

printf("*************************************************\n");

printf("*小型图书管理系统*\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("%d",&choice);

switch(choice)

{

case1:

if(head==NULL)

{

head=Create_Book();

}

Insert(head);

break;

case2:

Print_Book(head);

break;

case3:

search_book(head);

break;

case4:

change_Book(head);

break;

case5:

Delete(head);

break;

case6:

printf("\n");

printf("*******感谢使用图书管理系统******\n");

break;

default:

printf("*******输入错误,请重新输入!

*******");

break;

}

}

}

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 法律文书 > 调解书

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1