C语言程序设计(图书管理系统)源代码

#include"stdio.h"
#include
#include


/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
struct book_node{
int num;
char leibie[20];
char name[30];
char author[20];
char press[20];
char time[20];
double price;
struct book_node*next;};

FILE *fpp; /*定义fpp为全局变量*/
struct book_node*head,*tail,*p;

int root(); /* 核查权限的函数 */
int inputchioce(); /* 显示主菜单的函数 */
void save(); /* 保存链表为文件的函数 覆盖以前的信息 */
void save1(); /* 保存链表为文件的函数 不覆盖以前的信息 只在创建时调用一次*/


struct book_node* wjtolb(); /* 从文件中读取数据并建立图书信息的链表的函数 */


int luruxinxi(); /* 录入学生信息的函数 */
struct book_node * luruxinxi_chuangjian(); /* 创建图书信息的函数 */
struct book_node * luruxinxi_charu(); /*插入图书信息的函数*/
struct book_node * luruxinxi_shanchu(); /*删除图书信息的函数*/
struct book_node * luruxinxi_xiugai(); /*修改图书信息的函数*/




int liulanbook(); /* 浏览图书信息的函数 */



int chaxunbook(); /* 查询图书信息的函数 */
void chaxunbook_num(); /* 按编号查询图书 */
void chaxunbook_name(); /* 按书名查询图书 */
void chaxunbook_price(); /* 按价格查询图书 */



void paixubook(); /* 为图书排序的函数 */
struct book_node* paixubook_price(); /* 为图书按价格排序的函数 */
struct book_node* paixubook_time(); /* 为图书按出版时间排序的函数 */
void sfjx() ; /* 写个小函数,判断是否继续,让程序更完美 在排序中使用 */

int tongjibook_shumu(); /* 统计图书数目的函数 */


void shiyongshuoming(); /* 使用说明的函数 */

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

int main()
{

int chioce;
chioce=root(); /*核查用户是否有使用该管理系统的权限的函数*/
if(chioce==1) /*若取得权限 则返回值为1 */
{
system("cls");inputchioce();
}
exit(0);
}


/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

~~~~~~~~~~~~~*/

int inputchioce() /* 主菜单 */
{
int mychioce,x=-1;
printf("\n++++++++++++++++++++++++++++++++++++++欢 迎 你++++++++++++++++++++++++++++++++++\n\n");
printf("**+++++++++++++++++++++++++++++++++++ 主 菜 单 +++++++++++++++++++++++++++++++**\n");
printf("** 1-- 录入(删除 修改)图书信息 ** ** 2--(按规则)查询图书信息 **\n");
printf("** 3-- 浏览图书信息 ** ** 4-- 为图书(按规则)排序 **\n");
printf("** 5-- 统计图书(数目) ** ** 6-- 帮助 **\n");
printf("** 0-- 退出系统 ** ** **\n");
printf("**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++**\n");
printf("\n 恭喜你获得使用权限,请你选择:");
scanf("%d",&mychioce);
switch(mychioce)
{
case 1:
{ luruxinxi();break;}
case 2:
{chaxunbook();break;}
case 3:
{ liulanbook();break;}
case 4:
{ paixubook();break;}
case 5:
{ tongjibook_shumu();
printf("\n\n是否继续操作? 请选择(继续-1/退出-0)");
scanf("%d",&x);
if(x==1){ system("cls");inputchioce();}
if(x==0){printf("\n\n谢谢你的使用! 再见\n");
exit (0); }
if(x!=1&&x!=0)
{system("cls");
printf("选择有误,默认返回主菜单,请重新选择:\n");
inputchioce();
}
break;}
case 6:
{ shiyongshuoming();break;}
case 0:
{ printf(" \n\n 谢谢你的使用!!再见 \n\n");break;}
default:
{ system("cls");
printf("\n 选择有误,请重新选择:\n");
inputchioce();
}break;

}

}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
int root()
{
int m=1,n=3,flag=0;
char mima[20];

do{
printf("\n\n 你好,欢迎使本图书信息管理系统!\n");
printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
printf("【现在进行权限核查】 \n--------------------友情提醒:你共有3次输入密码的机会!\n");
printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n ");
if(n==2||n==1){printf("注意:你已输入错误%d次 剩余输入次数: %d 请输入密码:",3-n,n);}
if(n==3) printf("剩余输入次数: %d 请输入密码:",n);
scanf("%s",mima);
if(strcmp(mima,"fuck")==0)
{flag=1;
return flag;
}

m++;
n--;
system("cls");
}while(strcmp(mima,"fuck.")!=0&&m<=3) ;


printf("\n\n对不起,你连续三次输入密码错误,没有使用该图书管理系统的权限!\n");
exit(0);


}

/*~~~~

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

struct book_node* wjtolb(struct book_node*head,int *n) /* 从文件中读取数据并建立图书信息的链表的函数 */
{
FILE *fp;
struct book_node*p,*p1,*p2;

if((fp=fopen("1.txt","r"))==NULL)
{
printf(" 打开文件失败! \n");
exit(1);
}

while(!feof(fp))
{
(*n)++;
p=(struct book_node*)malloc(sizeof(struct book_node));
fscanf(fp,"%d%s%s%s%s%s%lf",&p->num,p->leibie,p->name,p->author,p->press,p->time,&p->price);

if(head==NULL)
{
head=p;
p1=p;
}
else
{
p1->next=p;
p2=p1;
p1=p;
}
}

p2->next=NULL;
free(p);
(*n)--;
fclose(fp);
return head;


}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/



int luruxinxi()
{
int k;
printf(" |++++++++++++++++++++++++++++录入 信息++++++++++++++++++++++++++++++++|\n");
printf(" | 1-- 创建或添加图书信息 ** ** 2-- 删除图书信息 |\n");
printf(" | 3-- 修改图书信息 ** ** 0-- 还回主菜单 |\n");
printf("请你再次选择具体操作:");
scanf ("%d",&k);
system("cls"); /* 清屏*/
switch(k)
{
case 1:
{ luruxinxi_chuangjian();break;}
case 2:
{
luruxinxi_shanchu();break;}
case 3:
{
luruxinxi_xiugai();break;}
case 0:
{ inputchioce();break;}
default:
{ system("cls");
printf("选择有误,默认返回主菜单,请重新选择:\n");
inputchioce();
}break;
}

}



/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/


struct book_node * luruxinxi_chuangjian() /* 创建图书信息的函数 */
{
int num;
char leibie[10];
char name[30];
char author[20];
char press[20];
char time[20];
double price;
int size=sizeof(struct book_node);

head=tail=NULL;
printf("\n请依次输入图书的\n编号 类别 书名 作者 出版社 出版时间 价格(以“0”结束输入): \n");
scanf("%d",&num);
if(num!=0)
scanf("%s%s%s%s%s%lf",leibie,name,author,press,time,&price);
while(num!=0)
{
p=(struct book_node*)malloc(size);

p->num=num;
strcpy(p->leibie,leibie);
strcpy(p->name,name);
strcpy(p->author,author);
strcpy(p->press,press);
strcpy(p->time,time);
p->price=price;
p->next=NULL;

if(head==NULL)
head=p;
else
tail->next=p;
tail=p;
printf("\n请继续输入图书的\n编号 类别 书名 作者 出版社 出版时间 价格(以“0”结束输入): \n");


scanf("%d",&num);
if(num!=0)
{
scanf("%s%s%s%s%s%lf",leibie,name,author,press,time,&price);
}
}

if(num==0) /* 若判断数字为0,则退出 */
{
system("cls");
save1(head);
inputchioce();
}



return head;


}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/


void save1(struct book_node* p1){ /* 将链表保存为文件的函数 不覆盖以前的信息 */

if( (fpp=fopen("1.txt","a"))==NULL )
{
printf("打开文件失败!");
exit(0);
}

while(p1!=NULL)
{
fprintf(fpp," %d %s %s %s %s %s %lf \n",p1->num,p1->leibie,p1->name,p1->author,p1->press,p1->time,p1->price);
p1=p1->next;
}

if(fclose(fpp))
{
printf("关闭文件失败!\n");
exit(0);
}
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/


void save(struct book_node* p1) /* 将链表保存为文件的函数 覆盖以前的信息 */
{
if(( fpp=fopen("1.txt","w"))==NULL )
{
printf("打开文件失败!");
exit(0);
}

while(p1!=NULL)
{
fprintf(fpp," %d %s %s %s %s %s %lf \n",p1->num,p1->leibie,p1->name,p1->author,p1->press,p1->time,p1->price);
p1=p1->next;
}

if(fclose(fpp))
{
printf("关闭文件失败!\n");
exit(0);
}

}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
struct book_node * luruxinxi_shanchu() /* 删除某本图书信息(按编号删除) */
{
int x=-1,n=0;
int numm;

int num;
char leibie[10];
char name[30];
char author[20];
char press[20];
char time[20];
double price;
struct book_node*ptr1,*ptr2;
struct book_node*head=NULL;

printf("\n所有的图书信息如下:\n"); /* 删除前 先遍历所有图书,方便看清要删除哪一本*/

if((fpp=fopen("1.txt","r"))==NULL) /* 输入要删除的图书编号之前 先遍历所有图书信息 */
{
printf(" 打开文件失败 ! ");
exit(0);
}
else
{
printf("\n\n编号 类别 书名 作者 出版社 出版时间 价格\n");
while(!feof(fpp))
{
fscanf(fpp,"%d%s%s%s%s%s%lf",&num,leibie,name,author,press,time,&price);
printf("%d %s %s %s %s %s %lf\n",num,leibie,name,author,press,time,price);
}
}
if(fclose(fpp))
{
printf("关闭文件失败!\n");
exit(0);
}


head=wjtolb(head,&n); /* 从文件中读取数据 将数据创建为链表 */
printf("\n 输入需要删除的图书的编号:");
scanf("%d",&

numm);


while(head!=NULL&&head->num==numm)
{
ptr2=head;
head=head->next;
free(ptr2);
}
if(head==NULL)
return NULL;
ptr1=head;
ptr2=head->next;

while(ptr2!=NULL)
{
if(ptr2->num==numm)
{
ptr1->next=ptr2->next;
free(ptr2);
}
else
ptr1=ptr2;

ptr2=ptr1->next;
}

save(head); /* 重新保存为文件 */

printf(" 编号为%d的图书已删除 并将删除后的信息保存至文件 ",numm);
printf("\n\n是否继续操作? 请选择(继续-1/退出-0)");
scanf("%d",&x);
if(x==1)
{
system("cls");
inputchioce();
}
if(x==0)
{
printf("\n\n谢谢你的使用! 再见\n");
exit (0);
}
if(x!=1&&x!=0)
{
system("cls");
printf("选择有误,默认返回主菜单,请重新选择:\n");
inputchioce();
}

return head;

}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
struct book_node * luruxinxi_xiugai() /*修改图书信息的函数(按编号修改)*/
{ int n=0,x=-1,t;
int num;
int numm;
char leibie[10];
char name[30];
char author[20];
char press[20];
char time[20];
double price;
struct book_node*head=NULL;
struct book_node*p;

printf("\n所有的图书信息如下:\n");
if( (fpp=fopen("1.txt","r"))==NULL ) /* 输入要修改的图书编号之前 先遍历所有图书信息 */
{
printf(" 打开文件失败 ! ");
exit(0);
}
else
{
printf("\n\n编号 类别 书名 作者 出版社 出版时间 价格\n");
while(!feof(fpp))
{

fscanf(fpp,"%d%s%s%s%s%s%lf",&num,leibie,name,author,press,time,&price);
printf("%d %s %s %s %s %s %lf\n",num,leibie,name,author,press,time,price);
}
}
if(fclose(fpp))
{
printf("关闭文件失败!\n");
exit(0);
}

printf("\n输入需要修改的图书的编号:");
scanf("%d",&numm);
system("cls"); /* 先遍历后选择完要修改的图书编号后 清屏*/

head=wjtolb(head,&n);

printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
printf("1--修改图书编号 2--修改图书类别\n");
printf("3--修改图书书名 4--修改图书作者\n");
printf("5--修改图书出版社 6--修改图书出版时间\n");
printf("7--修改图书价格 \n");
printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
printf("编号为%d本图书的信息为:\n",numm);

if(head!=NULL&&head->num==numm) /*修改头结点*/
{
printf("编

号 类别 书名 作者 出版社 出版时间 价格\n");
printf("%d %s %s %s %s %s %lf\n",head->num,head->leibie,head->name,head->author,head->press,head->time,head->price);
printf("请选择需要修改的图书信息的成分:");
scanf("%d",&t);
switch(t)
{
case 1:
{ printf(" 请输入图书%d的新编号:\n",numm);
scanf("%d",&num);
head->num=num;break;}
case 2:
{
printf(" 请输入图书%d的新类别:\n",numm);
scanf("%s",leibie);
strcpy(head->leibie,leibie);break;}
case 3:
{ printf(" 请输入图书%d的新书名:\n",numm);
scanf("%s",name);
strcpy(head->name,name);break;}
case 4:
{ printf(" 请输入图书%d的新作者:\n",numm);
scanf("%s",author);
strcpy(head->author,author);break;}
case 5:
{ printf(" 请输入图书%d的新出版社:\n",numm);
scanf("%s",press);
strcpy(head->press,press);break;}
case 6:
{ printf(" 请输入图书%d的新出版时间:\n",numm);
scanf("%s",time);
strcpy(head->time,time);break;}
case 7:
{ printf(" 请输入图书%d的新价格:\n",numm);
scanf("%lf",&price);
head->price=price;break;}
default:
{ system("cls");
printf("选择有误,默认返回主菜单,请重新选择:\n");
inputchioce();}break;


}
save(head);

printf("\n\n是否继续操作? 请选择(继续-1/退出-0)");
scanf("%d",&x);
if(x==1)
{
system("cls");inputchioce();
}
if(x==0)
{
printf("\n\n谢谢你的使用! 再见\n");
exit (0);
}
if(x!=1&&x!=0)
{
system("cls");
printf("选择有误,默认返回主菜单,请重新选择:\n");
inputchioce();
}


}
else /* 要修改的不是头节点 */
{
p=head->next;}

//do 用do-while语句事不能对第二本图书进行修改
//{p=p->next;}while(p!=NULL&&p->num!=numm);

while(p!=NULL&&p->num!=numm)
{
p=p->next;
}

if(p!=NULL&&p->num==numm) /* 修改其他节点 */
{
printf("\n\n编号 类别 书名 作者 出版社 出版时间 价格\n");
printf("%d %s %s %s %s %s %lf\n", p->num,p->leibie,p->name,p->author,p->press,p->time,p->price);
printf("请选择需要修改的图书信息的成分:");
scanf("%d",&t);
switch(t)
{
case 1:
{ printf(" 请输入图书%d的新编号:\n",numm);
scanf("%d",&num);
p->num=num;break;}
case 2:
{
printf(" 请输入图书%d的新类别:\n",numm);
scanf("%s",leibie);
strcpy(p->leibie,leibie);break;}
case 3:
{ printf(" 请输入图书%d的新书名:\n",numm);
scanf("%s",name);
strcpy(p->name,name);break;}
ca

se 4:
{ printf(" 请输入图书%d的新作者:\n",numm);
scanf("%s",author);
strcpy(p->author,author);break;}
case 5:
{ printf(" 请输入图书%d的新出版社:\n",numm);
scanf("%s",press);
strcpy(p->press,press);break;}
case 6:
{ printf(" 请输入图书%d的新出版时间:\n",numm);
scanf("%s",time);
strcpy(p->time,time);break;}
case 7:
{ printf(" 请输入图书%d的新价格:\n",numm);
scanf("%lf",&price);
p->price=price;break;}
default:
{ system("cls");
printf("选择有误,请重新选择:\n");
inputchioce();}break;

}
save(head);

printf("\n\n是否继续操作? 请选择(继续-1/退出-0)");
scanf("%d",&x);
if(x==1)
{
system("cls");
inputchioce();
}
if(x==0)
{
printf("\n\n谢谢你的使用! 再见\n");
exit (0);
}
if(x!=1&&x!=0)
{
system("cls");
printf("选择有误,默认返回主菜单,请重新选择:\n");
inputchioce();
}

}

return head;

}


/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
int liulanbook() /* 浏览图书信息的函数 */
{
int num;
char leibie[10];
char name[30];
char author[20];
char press[20];
char time[20];
double price;

int x=-1;

if( (fpp=fopen("1.txt","r"))==NULL )
{
printf(" 打开文件失败 ! ");
exit(0);
}
else
{
printf("\n\n编号 类别 书名 作者 出版社 出版时间 价格\n");
while(!feof(fpp))
{
fscanf(fpp,"%d%s%s%s%s%s%lf",&num,leibie,name,author,press,time,&price);
printf("%d\t%s\t%s\t%s\t%s\t%s\t%lf\n",num,leibie,name,author,press,time,price);
}
}
if(fclose(fpp))
{
printf("关闭文件失败!\n");
exit(0);
}


printf("\n\n是否继续操作? 请选择(继续-1/退出-0)");
scanf("%d",&x);
if(x==1)
{
system("cls");
inputchioce();
}
if(x==0)
{
printf("\n\n谢谢你的使用! 再见\n");
exit (0);
}
if(x!=1&&x!=0)
{
system("cls");
printf("选择有误,默认返回主菜单,请重新选择:\n");
inputchioce();
}

}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

int chaxunbook() /* 查询图书信息 */
{
int k;
int n=0;
struct book_node*head=NULL;

head=wjtolb(head,&n);
printf(" |++++++++++++++++++++++++++++ 查询图书信息++++++++++++++++++++++++++++++++|\n");
printf(" | 1-- 按编号查询图书信息 ** ** 2-- 按书名查询图书信息 |\n");
printf(" | 3-- 按价格查询图书信息 ** ** 0-- 还回主菜单 |\n");
printf("请你再次选择具

体操作:");
scanf ("%d",&k);
system("cls"); /* 清屏*/
switch(k)
{
case 1:
{ chaxunbook_num(head);break;}
case 2:
{ chaxunbook_name(head);break;}
case 3:
{ chaxunbook_price(head);break;}
case 0:
{ inputchioce();break;}
default:
{ system("cls");
printf("选择有误,默认返回主菜单,请重新选择:\n");
inputchioce();
}break;
}
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

void chaxunbook_num(struct book_node*h) /* 按编号查询图书 */
{
int found,flag=1,num;
int x;
struct book_node*p;

do
{
found=0;
p=h;
printf("请输入需要查找的图书的编号:");
scanf( "%d",&num);
printf("\n");

while(p!=NULL)
{
if(p->num==num)
{
if(found==0)
printf("\n编号 类别 书名 作者 出版社 出版时间 价格\n");
printf("%d %s %s %s %s %s %lf\n",p->num,p->leibie,p->name,p->author,p->press,p->time,p->price);
found=1; /* 如果要查询的图书为头节点内的图书 输出后将标记found变为1 */
}

p=p->next;
}

if(found==0) /* 若不为头节点 found不变 继续往后面查找 */
printf("编号为 %d 的图书未找到!\n",num);
printf("\n\n是否继续查找?(继续--1/返回主菜单--0)");
scanf("%d",&x);

if(x==0)
flag=0;
if(x==1)
flag=1;
if(x!=1&&x!=0)
flag=2;

}while(flag==1); /* flag为判断是否需要继续的函数 继续查找时 flag为1 用do-while控制循环 */

if(flag==0)
{
system("cls");
inputchioce();
}
if(flag==2)
{
system("cls");
printf("选择有误,默认返回主菜单,请重新选择:\n");
inputchioce();
}
}


/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

void chaxunbook_name(struct book_node*h) /* 按书名查询图书 */
{

int found,flag=1;
char name[30];
int x;
struct book_node*p;

do
{
found=0;
p=h;
printf("请输入需要查找的图书的书名:");
scanf( "%s",name);

printf("\n");

while(p!=NULL)
{

if(strcmp(p->name,name)==0)

{
if(found==0)
printf("\n编号 类别 书名 作者 出版社 出版时间 价格\n");

printf("%d %s %s %s %s %s %lf\n",p->num,p->leibie,p->name,p->author,p->press,p->time,p->price);

found=1;
}
p=p->next;
}

if(found==0)
printf("书名为《%s》的图书未找到!\n",name);
printf("\n\n是否继续查找?(继续--1/返回主菜单--0)");
scanf("

%d",&x);

if(x==0)
flag=0;
if(x==1)
flag=1;
if(x!=1&&x!=0)
flag=2;

}while(flag==1);

if(flag==0)
{
system("cls");
inputchioce();}
if(flag==2)
{
system("cls");
printf("选择有误,默认返回主菜单,请重新选择:\n");
inputchioce();
}

}


/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

void chaxunbook_price(struct book_node*h) /* 按价格查询图书 */
{
int found,flag=1;
double price;
int x;
struct book_node*p;

do
{
found=0;
p=h;
printf("请输入需要查找的图书的价格:");
scanf( "%lf",&price);
printf("\n");

while(p!=NULL)
{
if(p->price==price)
{
if(found==0)
printf("\n编号 类别 书名 作者 出版社 出版时间 价格\n");
printf("%d %s %s %s %s %s %lf\n",p->num,p->leibie,p->name,p->author,p->press,p->time,p->price);

found=1;
}
p=p->next;
}

if(found==0)
printf("价格为%lf的图书未找到!\n",price);
printf("\n\n是否继续查找?(继续--1/返回主菜单--0)");
scanf("%d",&x);

if(x==0)
flag=0;
if(x==1)
flag=1;
if(x!=1&&x!=0)
flag=2;

}while(flag==1);

if(flag==0)
{
system("cls");
inputchioce();
}
if(flag==2)
{
system("cls");
printf("选择有误,默认返回主菜单,请重新选择:\n");
inputchioce();
}

}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
void paixubook() /* 为图书排序的函数 */
{
int k;
int n=0;
struct book_node*head=NULL;
head=wjtolb(head,&n);
printf(" |++++++++++++++++++++++++ 为图书按规则排序+++++++++++++++++++++++++++++|\n");
printf(" | 1-- 按价格为图书排序 ** ** 2-- 按出版时间为图书排序 |\n");
printf(" | 0-- 还回主菜单 ** |\n");
printf("请你再次选择具体操作:");
scanf ("%d",&k);
system("cls"); /* 清屏*/
switch(k)
{
case 1:
{
head=paixubook_price(head);
sfjx();break;}
case 2:
{
head=paixubook_time(head);
sfjx();break;}
case 0:
{
inputchioce();break;}
default:
{
system("cls");
printf("选择有误,默认返回主菜单,请重新选择:\n");
inputchioce();}break;
}

}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

struct book_node* paixubook_price(struct book_node *head) /* 为图书按价格排序的函数 */

{
int n;
struct book_node*p1,*p2,*p3,*p4;
int

i,j;
int size=sizeof(struct book_node);

n=tongjibook_shumu();
p1=head;
p2=head->next;

if(head==NULL||head->next==NULL)
return head;
if(p2->next==NULL)
{
if(p1->priceprice)
return head;
else
{
p2->next=p1;
p1->next=NULL;
head=p2;

save(head);
printf("\n\n 按价格排序 操作已完成 并保存完毕\n是否继续操作? 请选择(继续-1/退出-0)");

return head;
}

}

for(i=1;i{
p4=(struct book_node*)malloc(size);p4->next=head;
p3=p4;
p1=head;
p2=head->next;
for(j=0;j{
if(p2->price>p1->price)
{
p3=p1;
p1=p2;
p2=p2->next;
}
else
{
p1->next =NULL;
p1->next=p2->next;
p3->next=p2;
p2->next =p1;
p3=p2;
p2=p1->next;
}
}
head=p4->next;free(p4);
}
save(head);
printf("\n\n按价格排序 操作已完成 并保存完毕\n是否继续操作? 请选择(继续-1/退出-0)");

return head;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
void sfjx() /* 写个小函数,判断是否继续,让程序更完美 */
{
int x=-1;
scanf("%d",&x);
if(x==1)
{
system("cls");
inputchioce();
}
if(x==0)
{
printf("\n\n谢谢你的使用! 再见\n");
exit(0);
}
if(x!=1&&x!=0)
{
system("cls");
printf("选择有误,默认返回主菜单,请重新选择:\n");
inputchioce();
}
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
struct book_node* paixubook_time(struct book_node *head) /* 为图书按出版时间排序的函数 */

{
int n;
struct book_node*p1,*p2,*p3,*p4;
int i,j;
int size=sizeof(struct book_node);

n=tongjibook_shumu();
p1=head;
p2=head->next;

if(head==NULL||head->next==NULL)
return head;
if(p2->next==NULL)
{
if(strcmp(p1->time,p2->time)>0)
return head;
else
{
p2->next=p1;
p1->next=NULL;
head=p2;

save(head);
printf("\n\n按出版时间排序 操作已完成 并保存完毕\n是否继续操作? 请选择(继续-1/退出-0)");
return head;

}

}
for(i=1;i{
p4=(struct book_node*)malloc(size);p4->next=head;
p3=p4;
p1=head;
p2=head->next;
for(j=0;j{
if(strcmp(p1->time,p2->time)<0)
{
p3=p1;
p1=p2;
p2=p2->next;
}
else
{
p1->next =NULL;
p1->next=p2->next;
p3->next=p2;
p2->next =p1;
p3=p2;
p2=p1->next;
}
}
head=p4->next;free(p4);
}
save(head);
printf("\n\n 按出版时间排序 操作已完成 并保存完毕\n是否继续操作? 请选择(继续-1/退出-0)");

return head;

}

/*~~~~~~~~~~~~~~~~~~

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
int tongjibook_shumu() /* 统计图书数目的函数 */
{
int num;
char leibie[10];
char name[30];
char author[20];
char press[20];
char time[20];
double price;

int x=-1,n=0;
if((fpp=fopen("1.txt","r"))==NULL)
{
printf(" 打开文件失败 ! ");
exit(0);
}
else
{
while(!feof(fpp))
{
fscanf(fpp,"%d%s%s%s%s%s%lf",&num,leibie,name,author,press,time,&price);
n++;
}
}
if(fclose(fpp))
{
printf("关闭文件失败!\n");
exit(0);
}

printf("共有%d本图书",n-1);
return n-1 ;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/


/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/


/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
void shiyongshuoming() /* 使用说明的函数 */
{
int x=-1;
system("cls");

printf("\n\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~使用说明~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n ");
printf(" 你好,欢迎使用本图书管理系统!\n 1.首先你需要获得本系统的使用权限,进入本系统后,你有三次输入密码");
printf("的机会,在三次内输入正确密码即可获得使用权限,三次输入错误后,系统将自动退出。\n 2.本系统的主菜单");
printf("包括录入图书信息;查询图书信息;浏览图书信息;为图书按规则排序排序等。\n 3.录入图书子菜单又包括");
printf("对图书信息的创建、删除和修改,查询和排序的子菜单中又包括具体的按某种方式查询和排序以及返回主菜单的具体选项。");
printf("\n 4.每一项具体操作都有结束提示,完成后又有是否继续或者返回主菜单的询问。这样,你就可以在你想要退出系统时退出,方便");
printf("打开一次系统进行多项操作。\n 希望你使用愉快!!!");
printf("");
printf("");
printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n ");

printf("\n\n是否继续操作? 请选择(继续-1/退出-0)");
scanf("%d",&x);
if(x==1)
{
system("cls");
inputchioce();
}
if(x==0)
{
printf("\n\n谢谢你的使用! 再见\n");
exit (0);
}
if(x!=1&&x!=0)
{
system("cls");
printf("选择有误,默认返回主菜单,请重新选择:\n");
inputchioce();
}
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

相关文档
最新文档