上一个图书管理系统的优化,学习链表逐渐成熟后写的,但是没有用到文件
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct book{
char book_name[30];
int bianhao;
double price;
char author[20];
char state[20];
char name[20];
char sex[10];
int xuehao;
struct book *book_next;
};
struct club
{
char name[20];
char sex[10];
int xuehao;
char borrow[30];
struct club *club_next;
};
void Print_Book(struct book *head_book);/*浏览所有图书信息*/
void Print_Club(struct club *head_club);/*浏览所有会员信息*/
struct book *Create_New_Book();/*创建新的图书库,图书编号输入为0时结束*/
struct book *Search_Book_bianhao(int bianhao,struct book *head_book);/*根据书的编号查找书 */
struct book *Search_Book_name(char *b_name,struct book *head_book);/*根据书的书名查找书 */
struct book *Search_Book_price(double price_h,double price_l,struct book *head_book);/*根据书的价格查找书 */
struct book *Insert_Book(struct book *head_book,struct book *stud_book);/*增加图书,逐个添加*/
struct book *Delete_Book(struct book *head_book,int bianhao);/*删除图书*/
struct club *Create_New_Club();/*创建新的会员库,图书编号输入为0时结束*/
struct club *Search_Club_xuehao(int xuehao,struct club *head_club);/*根据会员的学号查找会员 */
struct club *Search_Club_name(char *c_name,struct club *head_club);/*根据会员的姓名查找会员 */
struct club *Insert_Club(struct club *head_club,struct club *stud_club);/*增加会员*/
struct club *Delete_Club(struct club *head_club,int xuehao);/*删除会员*/
struct book *Lent_Book(int bianhao,int xuehao,struct book *head_book,struct club *head_club);/*借书*/
struct book *back(int bianhao,int xuehao,struct book *head_book,struct club *head_club);/*还书*/
void background1();
int main(void)
{
struct book *head_book,*p_book;
char book_name[30],name[20],author[20],sex[10];
int bianhao;
double price,price_h,price_l;
int size_book=sizeof(struct book);
int m=1,n=1,f;
char *b_name,*c_name;
struct club *head_club,*p_club;
int xuehao;
int size_club=sizeof(struct club);
int choice;
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("\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){
case 1:
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;
case 2:
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;
}
else if(f==2){
b_name=book_name;
getchar();
printf("请输入查询图书名称:");
gets(b_name);
printf("相关信息如下:\n\n");
head_book=Search_Book_name(b_name,head_book);
break;
}
else if(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;
}
else if(f==0){
break;
}
break;
case 6