C语言图书管理系统代码

#include

#include

#include

struct book{

       int num;

       char bname[50];

       char wname[20];

       char press[50];

       char sort[50];

       int time;

       float price;

    struct book *next;

};

struct book *creatbook();                          //创建链表

struct book *addbook(struct book *head);           //添加图书

int yanzheng(struct book *head,int m);             //验证新添加的图书编码是否已存在

void deletebook(struct book *head);                //删除图书

void fprint(struct book *head);                    //将链表写入文件

struct book *load();                               //从文件中读取信息并建成链表

void print_book(struct book *head);                //将链表信息输出

void chaxun(struct book *head);                    //查询图书信息

void num_chaxun(struct book *head);                //按图书编号查询图书

void wname_chaxun(struct book *head);              //按作者名查询图书

void sort_chaxun(struct book *head);               //按类别查询图书

void time_chaxun(struct book *head);               //按出版时间查询图书

void bname_chaxun(struct book *head);              //按图书名查询图书

void xiugai(struct book *head);                    //修改图书信息

void paixu(struct book *head);                     //对图书进行排序

void num_paixu(struct book *head);                 //按图书编号排序

void time_paixu(struct book *head);                //按图书出版时间排序

void price_paixu(struct book *head);               //按图书价格排序

void bname_paixu(struct book *head);               //按图书名排序

void wname_paixu(struct book *head);               //按作者名排序

int main()

{

       int choice,n,x,y=1,c,c1=1234;

       char a,d,b[10],b1[10]="yjk";

       struct book *head=NULL;

       while(y){

             

              system("cls");

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

           printf("                         ********** 欢迎光临 **********\n\n");

           printf("         ********************** 图书信息管理系统 ************************\n\n\n");

              printf("\n\n");

              printf("                      ============1-用户登录===========\n");

              printf("                      ============0-退出系统===========\n");

              printf("       请输入您的选择:");

              scanf("%d",&n);

              printf("\n");

              getchar();

              switch(n){

              case 0:

                     y=0;

                     break;

              case 1:

           printf("       请输入您的用户名:");

        gets(b);

                                                                                                                           printf("\n");                                                                                                     

           printf("       请输入您的密码:");

           scanf("%d",&c);

           printf("\n");

           if(strcmp(b,b1)!=0||c!=c1){

              printf("           验证失败,请重新输入!\n");

                 scanf("%c",&d);

              getchar();

              system("cls");

              }

         else{

                  printf("             验证通过!请按Enter键进入!\n");

                  scanf("%c",&d);

                  getchar();

                  x=1;

 

               while(x){

                   system("cls");

                   printf("                             ------------------\n");

                   printf("                             *图书信息管理系统*\n");

                 printf("                             ------------------\n\n");

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

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

                printf("               || 1-添加图书                    2-删除图书 ||\n\n");

                printf("               || 3-图书列表                    4-图书排序 ||\n\n");

                printf("               || 5-查询图书                    6-修改图书 ||\n\n");

                printf("               || 7-录入数据                    0-退出系统 ||\n\n");         

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

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

                   printf("请输入所选择的序号:");

                   scanf("%d",&choice);

                   getchar();

                   system("cls");

                   switch(choice)

                            {

                   case 0:

                            x=0;break;

                      case 1:

                            head=load();

                            if(head==NULL){

                                  printf("文件为空,请先录入数据!\n");

                                  getchar();

                                  break;

                               }

                           else{

                                 head=addbook(head);

                                 printf("添加成功!\n");

                     printf("是否将新信息保存到文件?(y/n)\n");

                     scanf("%c",&a);

                                 getchar();

                                 switch(a){

                                 case 'n':

                                        break;

                                 case 'y':

                                     fprint(head);

                                        printf("保存成功!\n");

                                        getchar();

                                     break;

                                    }

                                 break;

                              }

                    

                     case 2:

                          head=load();

                 if(head==NULL){

                                 printf("文件为空,请先录入数据!\n");

                                 getchar();

                                 break;

                             }

                      

                          else{

                                 deletebook(head);

                     getchar();

                                 break;

                          }

                             break;

                     case 3:

                 head=load();

                          if(head==NULL){

                                 printf("文件为空,请先录入数据!\n");

                                 getchar();

                                 break;

                             }

                          else{

                                 print_book(head);

                                 getchar();

                                 break;

                             }

                     case 4:

                 head=load();

                          if(head==NULL){

                                 printf("文件为空,请先录入数据!\n");

                                 getchar();

                                 break;

                             }

                          else{

                                 paixu(head);

                                 getchar();

                             }

                          break;

               case 5:

                     head=load();

                              if(head==NULL){

                                     printf("文件为空,请先录入数据!\n");

                                     getchar();

                                     break;

                                    }

                                 else{

                                        chaxun(head);

                                        getchar();

                                    }

                                 break;

                     case 6:

                   head=load();

                            if(head==NULL){

                                   printf("文件为空,请先录入数据!\n");

                                   getchar();

                                   break;

                               }

                               else{

                                      xiugai(head);

                                      getchar();

                       break;

                               }

                               break;

               case 7:

                              printf("注意:输入图书编码为0时结束!\n");

                     head=creatbook();

                     printf("是否将输入的信息保存到文件以覆盖文件中已存在的信息?(y/n)\n");

                     getchar();

                                 scanf("%c",&a);

                                 getchar();

                                    switch(a){

                                    case 'n':

                                        break;

                                 case 'y':

                                     fprint(head);

                                        printf("保存成功!\n");

                                        getchar();

                                        break;

                                    }

                                 break;

                     default:

                            printf("您的输入有误,请重新输入!\n");

                            getchar();

                            break;

                            }

                    

                     }

              }

              break;

              default:

                     printf("        您的输入有误!  请重新输入!\n");

                     getchar();

你可能感兴趣的:(c语言)