图书管理系统源代码原创Word文件下载.docx
《图书管理系统源代码原创Word文件下载.docx》由会员分享,可在线阅读,更多相关《图书管理系统源代码原创Word文件下载.docx(40页珍藏版)》请在冰豆网上搜索。
//对图书进行排序
voidnum_paixu(structbook*head);
//按图书编号排序
voidtime_paixu(structbook*head);
//按图书出版时间排序
voidprice_paixu(structbook*head);
//按图书价格排序
voidbname_paixu(structbook*head);
//按图书名排序
voidwname_paixu(structbook*head);
//按作者名排序
intmain()
{
intchoice,n,x,y=1,c,c1=1;
chara,d,b[10],b1[10]="
1”;
structbook*head=NULL;
while(y){
system(”cls"
);
printf(”\n\n\n\n\n"
);
printf("
—--—-------—-———--——-——--—-—-——----—--——-——-—---—--——--—----———--——---\n"
printf(”—--||-—---—-——————||---————图书信息管理系统--—-——--||———-—--—---||-—-\n"
—-—||-—-—---———--—||—————-—登陆界面—--————-||--—--——————||-—-\n”);
printf("
——--———-——-——————----————--—-—-------—-----——-—-———----——-------————-—\n"
\n"
============1-进入系统===========\n”);
printf(”============0—退出系统===========\n”);
-——--————---———---———-——---——--——-—--—-——--———-———-——--—-----————--—--\n"
请输入选择:
”);
scanf(”%d”,&n);
\n”);
getchar();
switch(n){
case0:
y=0;
break;
case1:
请输入您的用户名(输入1即可):
”);
gets(b);
请输入您的密码(输入1即可):
"
scanf("
%d"
,&
c);
printf(”\n"
if(strcmp(b,b1)!
=0||c!
=c1){
验证失败,请重新输入!
\n”);
scanf(”%c"
d);
getchar();
system(”cls”);
}
else{
验证通过!
请按Enter键进入!
d);
x=1;
while(x){
system("
cls”);
system(”color1F”);
printf(”--——-——-—---———----—---—-——----———-—-———-—-------——-—--——-——---———————\n\n"
—-—||--—-——-—--——-||-—--———图书信息管理系统—--——-—-||--——————---||———\n\n”);
——-||-—-—-—--——-——||------—--—-操作界面—--—-—-—--——||----——————-||———\n\n”);
printf(”———---———-—--————--——-—-——————--—-—-———-———--—--——--——--—-—-———-——---—\n\n"
—--——--———--——-——-—--———-——-———----——-————-—--\n"
printf(”—---||——-———----—系统菜单选项—---——--——-||—---\n"
printf(”-——--—-———--—-—--—--————----——-----—-—————--—-\n”);
-||1-添加图书删除图书-2||-\n\n"
-||3—图书列表图书排序-4||-\n\n”);
printf(”—||5-查询图书修改图书-6||-\n\n"
printf(”-||7—录入数据退出系统-0||—\n\n"
---—-—-——---——-———---—--——-———--—--—-—-—---——-\n”);
printf(”—--—--——--———--——----——--—-————-—————-—-—-—-——\n\n”);
printf(”请输入所选择的序号:
%d"
,&choice);
getchar();
system("
cls"
switch(choice)
{
case0:
x=0;
break;
head=load();
if(head==NULL){
printf(”文件为空,请先录入数据!
getchar();
break;
}
else{
head=addbook(head);
printf("
添加成功!
是否将新信息保存到文件?
(y/n)\n”);
scanf(”%c"
,&a);
switch(a){
case’n’:
break;
case'
y'
:
fprint(head);
printf("
保存成功!
getchar();
break;
}
}
case2:
if(head==NULL){
文件为空,请先录入数据!
getchar();
else{
deletebook(head);
}
case3:
head=load();
文件为空,请先录入数据!
print_book(head);
case4:
head=load();
if(head==NULL){
文件为空,请先录入数据!
paixu(head);
case5:
printf(”文件为空,请先录入数据!
}
else{
chaxun(head);
getchar();
case6:
文件为空,请先录入数据!
else{
xiugai(head);
break;
case7:
printf("
注意:
输入图书编码为0时结束!
head=creatbook();
是否将输入的信息保存到文件以覆盖文件中已存在的信息?
scanf("
%c”,&a);
switch(a){
case’0’:
break;
case’y'
保存成功!
default:
printf(”输入有误,请重新输入!
getchar();
break;
}
}
break;
输入有误,请重新输入!
getchar();
}
}
//录入数据并形成链表
structbook*creatbook()
{
structbook*head,*tail,*p;
intnum,time,n;
charbname[50],wname[20],press[50],sort[50];
floatprice;
intsize=sizeof(structbook);
head=tail=NULL;
请输入图书编号:
scanf(”%d"
&
num);
printf(”请输入图书名:
scanf(”%s”,bname);
printf(”请输入作者名:
%s”,wname);
printf(”请输入出版社:
%s"
press);
printf(”请输入类别:
scanf(”%s"
sort);
请输入出版时间:
%d”,&time);
请输入价格:
%f”,&price);
while
(1){
p=(structbook*)malloc(size);
p—〉num=num;
strcpy(p-〉bname,bname);
strcpy(p-〉wname,wname);
strcpy(p->
press,press);
strcpy(p—>
sort,sort);
p—>
time=time;
p—〉price=price;
p->
next=NULL;
if(head==NULL)
head=p;
else
tail—>
next=p;
tail=p;
do{
printf(”请输入图书编号:
%d”,&
num);
n=yanzheng(head,num);
if(n==0)
printf(”您输入的编号已存在,请重新输入!
}while
(1);
if(num==0)
{
请输入图书名:
scanf("
%s”,bname);
printf(”请输入作者名:
scanf(”%s"
,wname);
请输入出版社:
press);
printf(”请输入类别:
scanf(”%s”,sort);
请输入出版时间:
&time);
printf(”请输入价格:
%f”,&price);
}
}
returnhead;
}
//插入结点,并且插入后仍按一定顺序
structbook*addbook(structbook*head)
structbook*ptr,*p1,*p2,*p;
charbname[50],wname[20],press[50],sort[50];
intnum,time,n=1;
do{
printf(”请输入图书编号:
%d”,&
n=yanzheng(head,num);
printf(”您输入的编号已存在,请重新输入!
}while
(1);
printf(”请输入图书名:
%s”,bname);
%s"
scanf(”%s”,sort);
printf(”请输入出版时间:
scanf(”%d”,&time);
printf(”请输入价格:
%f"
price);
p=(structbook*)malloc(size);
p—〉num=num;
strcpy(p—〉bname,bname);
strcpy(p—〉wname,wname);
strcpy(p-〉press,press);
strcpy(p->
sort,sort);
p—〉time=time;
p—〉price=price;
p2=head;
ptr=p;
while((ptr-〉num>
p2—〉num)&
&(p2->
next!
=NULL)){
p1=p2;
p2=p2—〉next;
if(ptr->
num<
=p2—>
num){
if(head==p2)
head=ptr;
p1-〉next=ptr;
next=p2;
else{
p2—>
next=ptr;
next=NULL;
//验证添加的图书编号是否已存在
intyanzheng(structbook*head,intm)
structbook*p;
p=head;
while(p!
=NULL){
if(p-〉num==m)
p=p->
next;
if(p==NULL)
return0;
else
return1;
}
//将新链表写入文件中
voidfprint(structbook*head)
FILE*fp;
charch='
1'
;
structbook*p1;
if((fp=fopen("
f1。
txt"
”w”))==NULL){
Fileopenerror!
exit(0);
fputc(ch,fp);
for(p1=head;
p1;
p1=p1-〉next){
fprintf(fp,"
%d%s%s%s%s%d%f\n”,p1—>
num,p1—〉bname,p1—>
wname,p1->
press,p1->
sort,p1—〉time,p1->
price);
fclose(fp);
//从文件中读取图书信息
structbook*load()
charch;
structbook*head,*tail,*p1;
if((fp=fopen(”f1.txt"
,"
r”))==NULL){
Fileopenerror!
ch=fgetc(fp);
if(ch==’1'
){
while(!
feof(fp)){
p1=(structbook*)malloc(sizeof(structbook));
fscanf(fp,”%d%s%s%s%s%d%f\n”,&
p1—〉num,p1->
bname,p1—〉wname,p1—>
press,p1—〉sort,&
p1—〉time,&p1—〉price);
head=p1;
tail—〉next=p1;
tail=p1;
tail—〉next=NULL;
returnNULL;
//将整个链表的信息输出
voidprint_book(structbook*head)
structbook*ptr;
printf(”\n没有信息!
return;
图书信息列表如下\n”);
printf(”============================================================================\n"
printf(”编号图书名作者名出版社类别出版时间价格\n"
for(ptr=head;
ptr;
ptr=ptr—>
next)
%3d%—12s%—8s%—14s%-2s%-4d%。
2f\n”,
ptr—>
num,ptr->
bname,ptr—>
wname,ptr—〉press,ptr—〉sort,ptr—〉time,ptr—〉price);
//删除图书信息
voiddeletebook(structbook*head)
inta;
charb,ch='
;
structbook*p1,*p2;
FILE*fp;
请输入要删除的图书编号:
scanf(”%d”,&a);
p1=head;
if(p1-〉num==a&
&
p1-〉next==NULL){//对于文件中只有一组数据
printf(”是否清空文件!
scanf(”%c”,&
b);
switch(b){
case’n’:
case’y'
if((fp=fopen(”f1。
w"
))==NULL){
printf(”Fileopenerror!
fclose(fp);
文件已清空!
else{
while(p1-〉num!
=a&
p1—>
=NULL){
p2=p1;
p1=p1—>
next;
if(p1—>
next==NULL){
if(p1—〉num==a){
p2->
是否确定从文件中彻底删除该图书?
(y/n)\n"
getchar(