c语言图书馆管理系统.docx
《c语言图书馆管理系统.docx》由会员分享,可在线阅读,更多相关《c语言图书馆管理系统.docx(22页珍藏版)》请在冰豆网上搜索。
c语言图书馆管理系统
C源代码如下:
viewplaincopytoclipboardprint?
#include
#include
#include
structbook{
charbook_name[30];
intbianhao;
doubleprice;
charauthor[20];
charstate[20];
charname[20];
charsex[10];
intxuehao;
structbook*book_next;
};
structclub{
charname[20];
charsex[10];
intxuehao;
charborrow[30];
structclub*club_next;
};
voidPrint_Book(structbook*head_book);/*浏览所有图书信息*/
voidPrint_Club(structclub*head_club);/*浏览所有会员信息*/
structbook*Create_New_Book();/*创建新的图书库,图书编号输入为0时结束*/
structbook*Search_Book_bianhao(intbianhao,structbook*head_book);
structbook*Search_Book_name(char*b_name,structbook*head_book);
structbook*Search_Book_price(doubleprice_h,doubleprice_l,structbook*head_book);
structbook*Insert_Book(structbook*head_book,structbook*stud_book);/*增加图书,逐个添加*/
structbook*Delete_Book(structbook*head_book,intbianhao);/*删除图书*/
structclub*Create_New_Club();
structclub*Search_Club_xuehao(intxuehao,structclub*head_club);
structclub*Search_Club_name(char*c_name,structclub*head_club);
structclub*Insert_Club(structclub*head_club,structclub*stud_club);
structclub*Delete_Club(structclub*head_club,intxuehao);
structbook*Lent_Book(intbianhao,intxuehao,structbook*head_book,structclub*head_club);
structbook*back(intbianhao,intxuehao,structbook*head_book,structclub*head_club);
intmain()
{
structbook*head_book,*p_book;
charbook_name[30],name[20],author[20],sex[10];
intbianhao;
doubleprice,price_h,price_l;
intsize_book=sizeof(structbook);
intm=1,n=1,f;
char*b_name,*c_name;
structclub*head_club,*p_club;
intxuehao;
intsize_club=sizeof(structclub);
intchoice;
printf("\n欢迎您第一次进入图书管理系统!
\n\n");
printf("----->[向导]----->[新建图书库]\n\n");
printf("注意:
当输入图书编号为0时,进入下一步.\n\n");
head_book=Create_New_Book();
system("cls");
printf("\n欢迎您第一次进入图书管理系统!
\n\n");
printf("----->[向导]----->[新建会员库]\n\n");
printf("注意:
当输入会员学号为0时,进入主菜单.\n\n");
head_club=Create_New_Club();
system("cls");
do{
printf("\n\t\t\t〓〓〓〓〓图书管理系统〓〓〓〓〓\n\n");
printf("\n");
printf("\t\t\t[1]:
借书办理\t");printf("[6]:
还书办理\n");
printf("\n");
printf("\t\t\t[2]:
查询图书\t");printf("[7]:
查询会员\n");
printf("\t\t\t[3]:
添加图书\t");printf("[8]:
添加会员\n");
printf("\t\t\t[4]:
删除图书\t");printf("[9]:
删除会员\n");
printf("\t\t\t[5]:
遍历图书\t");printf("[10]:
遍历会员\n\n");
printf("\t\t\t〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓\n\n");
printf("\t\t\t0:
退出\n\n");
printf("请选择<0~10>:
");
scanf("%d",&choice);
switch(choice){
case1:
printf("\n\t\t\t〓〓〓〓〓图书管理系统〓〓〓〓〓\n\n");
printf("输入所借图书编号:
\n");
scanf("%d",&bianhao);
printf("输入借书人的学号:
\n");
scanf("%d",&xuehao);
head_book=Lent_Book(bianhao,xuehao,head_book,head_club);
system("cls");
printf("\n借阅成功!
\n\n");
printf("相关信息如下:
\n\n");
head_book=Search_Book_bianhao(bianhao,head_book);
break;
case2:
system("cls");
printf("\n\t\t\t〓〓〓〓〓图书管理系统〓〓〓〓〓\n\n");
printf("1.按编号查询\n\n");
printf("2.按名称查询\n\n");
printf("3.按价格区间查询\n\n");
printf("0.返回主菜单\n\n");
printf("请选择:
");
scanf("%d",&f);
if(f==1){
printf("请输入查询图书编号:
");
scanf("%d",&bianhao);
printf("相关信息如下:
\n\n");
head_book=Search_Book_bianhao(bianhao,head_book);
break;
}
elseif(f==2){
b_name=book_name;
getchar();
printf("请输入查询图书名称:
");
gets(b_name);
printf("相关信息如下:
\n\n");
head_book=Search_Book_name(b_name,head_book);
break;
}
elseif(f==3){
printf("请输入最高价格:
");
scanf("%lf",&price_h);
printf("请输入最低价格:
");
scanf("%lf",&price_l);
printf("相关信息如下:
\n\n");
head_book=Search_Book_price(price_h,price_l,head_book);
break;
}
elseif(f==0){
break;
}
break;
case6:
printf("\n\t\t\t〓〓〓〓〓图书管理系统〓〓〓〓〓\n\n");
printf("输入所还图书编号:
\n");
scanf("%d",&bianhao);
printf("输入还书人的学号:
\n");
scanf("%d",&xuehao);
head_book=back(bianhao,xuehao,head_book,head_club);
system("cls");
printf("\n归还成功!
\n\n");
printf("相关信息如下:
\n\n");
head_book=Search_Book_bianhao(bianhao,head_book);
break;
case3:
system("cls");
printf("\n\t\t\t〓〓〓〓〓图书管理系统〓〓〓〓〓\n\n");
printf("请输入图书名称:
");
scanf("%s",book_name);
printf("请输入图书编号:
");
scanf("%d",&bianhao);
printf("请输入单价:
");
scanf("%lf",&price);
printf("请输入作者名字:
");
scanf("%s",author);
printf("\n");
structbook*ptr_b;
for(ptr_b=head_book;ptr_b;ptr_b=ptr_b->book_next)
{
if(ptr_b->bianhao==bianhao)
{
printf("此编号图书已存在\n");
m=0;
break;
}
}
if(m){
p_book=(structbook*)malloc(size_book);
strcpy(p_book->book_name,book_name);
p_book->bianhao=bianhao;
p_book->price=price;
p_book->xuehao=0;
strcpy(p_book->author,author);
strcpy(p_book->state,"存在");
strcpy(p_book->sex,"待定");
strcpy(p_book->name,"待定");
head_book=Insert_Book(head_book,p_book);
printf("\n添加图书成功!
\n\n");
}
break;
case4:
system("cl