C语言模拟图书馆管理系统_c语言编写图书管理系统要求有管理员负责管理账号-程序员宅基地

技术标签: c++  C/C++学习  编程语言  

这道题是我自己一个个码出来的,中间完全没有参考别人的代码,所以可能看起来并不美观。因为要求也不是很明确,所以我的密码功能就基本敷衍了事了,直接用人员编号来代替密码验证,反正题目也没要求。但是感觉不加点啥好像有太简陋了,所以又敷衍的加了显示读者和书籍信息的功能和显示自己借阅书籍的功能,此外还加了很多容错机制来增加这个小程序的健壮性。当然基本功能还是实现了。要用的话请至少改一下变量名和函数顺序并且搞懂为什么,不要直接抄袭。
中间遇到了许多蜜汁问题,比如之所以用英文是因为我的中文文档读入修改输出后会出现乱码,大概是编码上哪里出了问题,我试了几次都没有成功,因此只能用全英文了。。。。。此外因为捉鸡的能力,对文档的格式要求很严,书籍的单词之间必须要用下划线而不是空格来区分,否则读入会有问题。文档的空格和换行不能错否则就会崩。
此外还有很多能改进的地方,比如我本来应该用链表而不是用数组的,比如提示信息是否能再改一改,比如密码登录能不能再完善下,比如书和读者的编号应该是字符串之类然而我一想到这个课学分只有一个,而且改了以后我要重新测试一遍然后把截图全部附到报告里,就果断放弃这些更宏大的目标。。。。。。
代码看起来长,实际上基本是没啥水平含量的数组遍历查找,比较无聊。更多的还是锻炼怎么设计和怎么完善一个完整的小项目的能力

原题:

涉及知识点:文件读写、内存管理、结构体定义、基本数据结构、高级格式化输入输出

要求:

编写一个程序模拟图书管理系统。用户分为管理员和读者两类,分别显示不同文本格式菜单,通过菜单项对应数字进行选择。读者菜单包括借书、还书、查询等功能。管理员菜单包括图书和读者信息录入、修改和删除。图书信息至少应包括:编号、书名、数量,读者信息至少应包括:编号、姓名、所借图书。可根据图书名称或编号进行图书信息查询,可查询某本书现在被哪些读者借走。

命令行参数如下:

Libsim –a(-u)  xxxx

第一个参数为可执行程序名称;第二个参数为用户身份,-a表示管理员,-u表示读者;第三个参数为用户名

问题分析

问题要求模拟一个图书馆管理系统,要考虑的细节问题很多,但最主要的问题在于:

1.文档中需要存储哪些关于图书馆的信息?怎么组织这些信息?

2.如何将文档中的信息录入程序处理并将程序处理后的信息重新录入原来的文档?

3.在程序该如何处理这些数据达到以下功能

读者:

  • 借阅图书
  • 归还图书
  • 查询图书信息

管理员:

  • 录入图书信息
  • 录入读者信息
  • 修改图书信息
  • 修改读者信息
  • 删除图书信息
  • 删除图书信息

4.如何实现管理系统与使用者的交互?

5.除了上述题目要求的功能,还需要加入哪些功能来让管理系统更加完善?

解决方案(思路)

思考过后,得出以下对应解决方案

1.建立四个txt文档(administratorlist.txt,booklist.txt,bookborrowedlist.txt,readerlist.txt)

四个文档的内容为:

  • administratorlist.txt: the number of administrator+the name of administrator
  • booklist.txt:the number of the book+the name of the book+the totalnumber of the book in the library now(注:由于后续输入的要求,书名必须采用下划线而不是空格来区分单词)
  • bookborrowedlist.txt:the name of the book borrowed+the name of the reader who borrowed it
  • readerlist.txt:the number of the reader+the name of the reader

2.建立三种结构体

  • reader:内部为读者的编号number,读者的名字name,读者借阅的图书总数bookborrowedsum,读者借阅的图书bookborrowed(为一个字符串数组)
  • book:内部为图书的编号number,图书的名字name,该图书现在馆内的书目totalnumber
  • administrator:内部为管理员的编号number,管理员的名字name

建立三个对应的结构体数组reader_list,book_list,administrator_list。

建立三个全局变量booksum,readersum,administratorsum记录操作中随时会发生变动的馆藏书种类数,读者总数,管理员总数为后续的数组遍历所用

在程序的开始把文件内容解析读入对应的结构体数组,管理系统的一系列操作都针对结构体数组的内容进行改写。所有操作结束后再一次性将结构体的内容写入文件同时退出系统。

3.通过打印出菜单实现和用户的交互,用户按下数字就会调用相关函数完成菜单上所提示的对应功能

4.除了以上功能外额外添加了几个功能来完善系统。同时加了很多容错机制来尽量避免因为输入的问题而造成程序崩溃以增加代码的健壮性

*登录和验证功能

题目没有要求验证用户的身份和密码,但是为了更完善程序要根据用户输入的命令行参数确定用户是否属于输入的对应身份,若不属于则直接退出。同时把管理员和读者的编号作为密码要求用户输入,若用户输入的编号与命令行参数获得的姓名不一致也不可以进行后续操作

*读者附加功能

显示自己目前借阅的书目

*管理员附加功能

查看所有的书目信息和所有读者的信息,但是出于安全考虑不能查看管理员的信息

算法分析

程序开始后调用load系函数初始化结构体数组并将将txt文档内的信息读入结构体数组。

之后根据命令行参数要求进行用户身份验证,密码正确则根据用户的身份弹出管理员界面和读者界面,根据菜单栏提示键入操作对应的数字实现交互。所有操作结束后输入0退出图书管理系统并调用save系函数遍历结构体数组将结构体数组的数据写入txt文档。

在操作过程中键入数字后会调用相应的函数,各个操作对应的函数机理如下,每个函数基本都是遍历和修改数组操作,相对比较简单,故不仔细进行说明:

读者

0->退出循环,结束程序

1->借阅图书

一开始要求输入想要借阅的图书的名字。然后遍历若读者借阅的书总数超过10本则输出提示信息并终止操作。否则若找不到书则输出提示信息,若找到时发现此时馆藏库存为0同样输出提示信息,若发现该读者已经借阅过该书同样不能借阅。否则完成借阅操作

2->归还图书

一开始要求输入想要借阅的图书的名字。若发现要归还的书不属于馆藏书目则输出提示信息,否则完成归还操作

3->查询图书信息

要求输入数字选择采用名字还是编号的方式查询图书信息。根据输入的数字遍历数组,若找不到图书则输出提示信息,否则输出馆藏总数和借阅该数的人

4->查看借阅书目

遍历数组找到自己对应的单元输出借阅的书目,输出后按任意键可以实现清屏操作并重新显示读者菜单

管理员

0:原理同读者0操作

1->录入图书信息

要求输入新书的编号,名字和总数。遍历数组发现编号和名字重复则输出提示信息阻止操作继续进行。否则添加新元素

2->录入读者信息

要求输入读者的编号,名字。遍历数组发现编号和名字重复则输出提示信息阻止操作继续进行。否则添加新元素

3->修改图书信息

要求输入图书编号,寻找对应图书。若找不到就输出提示信息,若找到则输出该书的信息并要求重新输入图书的总数

4->修改读者信息

要求输入读者编号,遍历reader_list寻找对应读者。若找不到就输出提示信息,若找到则输出该读者的信息并要求重新输入该读者借阅的图书总数,根据该总数要求依次输入读者借阅的图书,若发现输入的图书不属于馆藏书目则输出提示信息强制要求重新输入

5->删除图书信息

要求输入要删除的图书编号,遍历数组进行删除。若发现这本书存在外借未归还的现象则输出提示信息表示无法删除,若找不到这本书同样要输出提示信息。

6->删除读者信息

要求输入要删除的读者编号,遍历数组进行删除操作。若发现该读者存在未归还图书的现象则输出提示信息表示无法删除,若找不到该读者同样输出提示信息。

7:原理同读者3操作

8->输出全部图书信息

遍历数组。输出所有图书的信息和由哪些读者借阅。输出后按任意键可以实现清屏操作并重新显示管理员菜单

9->输出全部读者信息

遍历数组。输出所有读者信息,包括每个读者借阅的书目。输出后按任意键可以实现清屏操作并重新显示管理员菜单

源代码:

#include<stdio.h>
#include<string.h>
#include<stdlib.h>

//显示管理员界面和读者界面
void readermenu(){
    
    printf("............................................................\n");
    printf(".                      reader menu                         .\n");
    printf(".  Please enter the number for the corresponding operation .\n");
    printf(".  0->Exit the library management system                   .\n");
    printf(".  1->Borrow the book                                      .\n");
    printf(".  2->Return the book                                      .\n");
    printf(".  3->Inquiry the book information                         .\n");
    printf(".  4->display all book you borrowed                        .\n");
    printf("............................................................\n");
}
void administratormenu(){
    
    printf("............................................................\n");
    printf(".                          administrator menu              .\n");
    printf(".  Please enter the number for the corresponding operation .\n");
    printf(".  0->Exit the library management system                   .\n");
    printf(".  1->Book information entry                               .\n");
    printf(".  2->Reader information entry                             .\n");
    printf(".  3->Book information modify                              .\n");
    printf(".  4->Reader information modify                            .\n");
    printf(".  5->Book information delete                              .\n");
    printf(".  6->Reader information delete                            .\n");
    printf(".  7->Book information inquiry                             .\n");
    printf(".  8->display the information of all books                 .\n");
    printf(".  9->display the information of all readers               .\n");
    printf("............................................................\n");
}

//书结构体,包括编号,书名,图书馆内该书现馆藏量
typedef struct Book{
    
    int number;
    char name[100];
    int  totalnumber;
}book;

//读者结构体,包括编号,用户名,该读者借走的书,该读者借走的书的总量
typedef struct Reader{
    
    int number;
    char name  [100];
    char bookborrowed[10][100];
    int bookborrowedsum;
}reader;

//管理员结构体,包括编号,用户名
typedef struct Administrator{
    
    int number;
    char name[100];
}administrator;




//馆藏图书数组,读者数组,管理员数组
book book_list[200000];
reader reader_list[10000];
administrator administrator_list[100];
int choice;                          //用户选择选项
FILE *readerlist;                    //读者文件指针
FILE *booklist;                      //馆藏书目文件指针
FILE *administratorlist;             //管理员文件指针
FILE *borrowedlist;                  //出借书目文件指针
int administratorsum=0;              //管理员总数
int readersum=0;                     //读者总数
int booksum=0;                       //馆藏图书总数



void display_booklist();                //显示现存馆藏书目
void display_readerlist();              //显示读者信息
void display_myborrowed();              //显示读者借的书目
void book_borrow();                     //图书出借
void book_return();                     //图书出借
void book_inquiry();                    //查询图书信息
void book_information_entry();          //图书信息录入
void book_information_modify();         //图书信息修改
void book_information_delete();         //图书信息删除
void reader_information_entry();        //读者信息录入
void reader_information_modify();       //读者信息修改
void reader_information_delete();       //读者信息删除
void load_administratorlist();          //读入管理员列表
void load_readerlist();                 //读入读者列表
void load_booklist();                   //读入馆藏图书列表
void load_borrowedlist();               //读入出借图书列表
void save_administratorlist();          //写入管理员列表
void save_readerlist();                 //写入读者列表
void save_booklist();                   //写入书列表
void save_borrowedlist();               //写入出借图书列表


void display_booklist(){
    
  for(int i=0;i<booksum;i++){
    
   printf("number:%d name:%s totalnumber:%d\n\n",book_list[i].number,book_list[i].name,book_list[i].totalnumber);
  }
  printf("Press any key to continue!");
  getchar();
  getchar();
  system("cls");
  administratormenu();
}

void display_readerlist(){
    
  for(int i=0;i<readersum;i++){
    
   printf("number:%d name:%s the number of book borrowed:%d\n",reader_list[i].number,reader_list[i].name,reader_list[i].bookborrowedsum);
   if(reader_list[i].bookborrowedsum==0){
    
       printf("he/she didn't borrow any book.\n");
   }else{
    
     printf("the name of book he/she borrowed:\n");
     for(int j=0;j<reader_list[i].bookborrowedsum;j++){
    
     printf("%s\n",reader_list[i].bookborrowed[j]);
    }
   }
  printf("\n");
  }
  printf("Press any key to continue!");
  getchar();
  getchar();
  system("cls");
  administratormenu();
}              

void display_myborrowed(char *reader){
    
  for(int i=0;i<readersum;i++){
    
   if(strcmp(reader_list[i].name,reader)==0){
    
    if(reader_list[i].bookborrowedsum==0){
    
     printf("You didn't borrow any book.\n");
    }else{
    
     printf("The books you borrowed:\n");
     for(int j=0;j<reader_list[i].bookborrowedsum;j++){
    
      printf("%s\n",reader_list[i].bookborrowed[j]);
     }
    }
   }
  }
  printf("Press any key to continue!");
  getchar();
  getchar();
  system("cls");
  readermenu();
}             

void load_borrowedlist()
{
     
  for(int i=0;i<readersum;i++){
    
  reader_list[i].bookborrowedsum=0;
  for(int j=0;j<10;j++){
    
   strcpy(reader_list[i].bookborrowed[j],"\0");
  }
  }
  borrowedlist=fopen("borrowedlist.txt","r");
  char bookname[100];
  char readername[100];
  while(fscanf(borrowedlist,"%s%s\n",bookname,readername)!=EOF){
    
   for(int i=0;i<readersum;i++){
    
    if(strcmp(reader_list[i].name,readername)==0){
    
       strcpy(reader_list[i].bookborrowed[reader_list[i].bookborrowedsum],bookname);
       reader_list[i].bookborrowedsum++;
    }
   }
  }
  fclose(borrowedlist);
}



void load_administratorlist()
{
     
  administratorlist=fopen("administrator.txt","r");
  while(fscanf(administratorlist,"%d%s\n",&administrator_list[administratorsum].number,administrator_list[administratorsum].name)!=EOF){
    
    administratorsum++;
  }
  fclose(administratorlist);
}



void load_readerlist()
{
    
   readerlist=fopen("readerlist.txt","r");
   while(fscanf(readerlist,"%d%s\n",&reader_list[readersum].number,reader_list[readersum].name)!=EOF){
    
    readersum++;
   }
   fclose(readerlist);
}



void load_booklist()
{
    
  booklist=fopen("booklist.txt","r");
  while(fscanf(booklist,"%d%s%d\n",&book_list[booksum].number,book_list[booksum].name,&book_list[booksum].totalnumber)!=EOF){
    
   booksum++;
  }
  fclose(booklist);
}



void save_administratorlist()
{
    
  administratorlist=fopen("administrator.txt","w");
  for(int i=0;i<administratorsum;i++){
    
   fprintf(administratorlist,"%d %s\n",administrator_list[i].number,administrator_list[i].name);
  }
  fclose(administratorlist);
}                 



void save_readerlist()
{
    
  readerlist=fopen("readerlist.txt","w");
  for(int i=0;i<readersum;i++){
    
   fprintf(readerlist,"%d %s\n",reader_list[i].number,reader_list[i].name);
  }
  fclose(readerlist);
}                         



void save_booklist()
{
    
  booklist=fopen("booklist.txt","w");
  for(int i=0;i<booksum;i++){
    
   fprintf(booklist,"%d %s %d\n",book_list[i].number,book_list[i].name,book_list[i].totalnumber);
  }
  fclose(booklist);
}                           



void save_borrowedlist()
{
    
  borrowedlist=fopen("borrowedlist.txt","w");
  for(int i=0;i<readersum;i++){
    
   for(int j=0;j<reader_list[i].bookborrowedsum;j++){
    
    fprintf(borrowedlist,"%s %s\n",reader_list[i].bookborrowed[j],reader_list[i].name);
   }
  }
  fclose(borrowedlist);
} 



void book_borrow(char *reader){
    
  char bookwanttoborrow[100];
  printf("Please enter the name of the book you want to borrow!\n");
  scanf("%s",bookwanttoborrow);
  for(int i=0;i<readersum;i++){
    
   if(strcmp(reader_list[i].name,reader)==0){
    
    if(reader_list[i].bookborrowedsum==10){
    
     printf("You have borrowed more than 10 books!\n");
     return;
    }
    for(int j=0;j<reader_list[i].bookborrowedsum;j++){
    
     if(strcmp(reader_list[i].bookborrowed[j],bookwanttoborrow)==0){
    
      printf("Sorry,you have borrowed this book!\n");
      return;
     }
    }
   }
  }
  int iffind=0;
  for(int i=0;i<booksum;i++){
    
   if(strcmp(book_list[i].name,bookwanttoborrow)==0){
    
    iffind=1;
    if(book_list[i].totalnumber==0){
    
     printf("I'm sorry, this book has all been borrowed by others!\n");
    }else{
    
          book_list[i].totalnumber--;
          for(int j=0;j<readersum;j++){
    
           if(strcmp(reader_list[j].name,reader)==0){
    
            strcpy(reader_list[j].bookborrowed[reader_list[j].bookborrowedsum],bookwanttoborrow);
            reader_list[j].bookborrowedsum++;
           }
          }
         }
   }
  }
  if(iffind==0){
    
   printf("Sorry, this book is not in our collection!\n");
  }
}



void book_return(char *reader){
    
  char bookwantreturn[30];
  printf("Please enter the name of the book you want to return\n");
  scanf("%s",bookwantreturn);
  int iffind=0;
  for(int i=0;i<booksum;i++){
    
   if(strcmp(book_list[i].name,bookwantreturn)==0){
    
    iffind=1;
    book_list[i].totalnumber++;
    break;
   }
  }
  if(iffind==0){
    
   printf("Sorry,the book you want to return does not belong to this library!");
   return;
  }
  for(int i=0;i<readersum;i++){
    
   if(strcmp(reader_list[i].name,reader)==0){
    
    for(int j=0;j<reader_list[i].bookborrowedsum;j++){
    
     if(strcmp(reader_list[i].bookborrowed[j],bookwantreturn)==0){
    
      for(int k=j;k<reader_list[i].bookborrowedsum;k++){
    
       strcpy(reader_list[i].bookborrowed[k],reader_list[i].bookborrowed[k+1]);
      }
      reader_list[i].bookborrowedsum--;
     }
    }
   }
  }
}


void book_inquiry(){
    
 printf("Which way do you want to find books?\n");
 printf("  1.Enter the name to find the book.\n");
 printf("  2.Enter the book number to find the book\n");
 printf("Please enter the corresponding number to select the search method.\n");
 int waynumber;
 scanf("%d",&waynumber);
  if(waynumber==1){
    
   char bookinquiry1[100];
   printf("Please enter the name of the book you want to inquiry.\n");
   scanf("%s",bookinquiry1);
   int iffind1=0;
   for(int i=0;i<booksum;i++){
    
    if(strcmp(book_list[i].name,bookinquiry1)==0){
    
     iffind1=1;
     printf("The books you want to inquire about are now in the library:%d\n",book_list[i].totalnumber);
    }
   }
   if(iffind1==0){
    
    printf("I'm sorry,the book you are inquiring about is not find\n");         
    return;
   }
   for(int i=0;i<readersum;i++){
    
    for(int j=0;j<reader_list[i].bookborrowedsum;j++){
    
     if(strcmp(reader_list[i].bookborrowed[j],bookinquiry1)==0){
    
      printf("%s borrowed the book\n",reader_list[i].name);
     }
    }
   }
  }else if(waynumber==2){
    
    int bookinquiry2;
    printf("Please enter the number of the book you want to inquiry\n");
    scanf("%d",&bookinquiry2);
    int iffind2=0;
    char bookinquiry2name[30];
    for(int i=0;i<booksum;i++){
    
    if(book_list[i].number==bookinquiry2){
    
    iffind2=1;
    strcpy(bookinquiry2name,book_list[i].name);
     printf("The books you want to inquire about are now in the library:%d.\n",book_list[i].totalnumber);
    }
   }
   if(iffind2==0){
    
    printf("I'm sorry,the book you are inquiring about is not find!\n");   
    return;      
   }
   for(int i=0;i<readersum;i++){
    
    for(int j=0;j<reader_list[i].bookborrowedsum;j++){
    
     if(strcmp(reader_list[i].bookborrowed[j],bookinquiry2name)==0){
    
      printf("%s borrowed the book.\n",reader_list[i].name);
     }
    }
   }
  }else{
    
    printf("Input error.Please enter again!\n");
  }
}



void book_information_entry(){
    
 printf("Please enter the book information in the format of 'number+name+totalnumber'\n");
 int booknumber;
 char bookname[100];
 int booktotalnumber;
 scanf("%d %s %d",&booknumber,bookname,&booktotalnumber);
 for(int i=0;i<booksum;i++){
    
  if(strcmp(book_list[i].name,bookname)==0||book_list[i].number==booknumber){
    
   printf("This book already exists!\n");
   return;
  }
 }
 book_list[booksum].number=booknumber;
 strcpy(book_list[booksum].name,bookname);
 book_list[booksum].totalnumber=booktotalnumber;
 booksum++;
}



void book_information_modify(){
    
  printf("Please enter the number of the book you want to modify\n");
  int bookmodifynumber;
  scanf("%d",&bookmodifynumber);
  int iffind=0;
  for(int i=0;i<booksum;i++){
    
   if(book_list[i].number==bookmodifynumber){
    
    iffind=1;
    printf("Please enter the modified totalnumber'\n");
    printf("number:%d name:%s totalnumber:",book_list[i].number,book_list[i].name);
    scanf("%d",&book_list[i].totalnumber);
   }
  }
  if(iffind==0){
    
   printf("Sorry,We can't find the number of the book you want to modify!\n");
  }
}



void book_information_delete(){
    
  printf("Please enter the number of the book you want to delete.\n");
  int bookdeletenumber;
  scanf("%d",&bookdeletenumber);
  int iffind=0,isdeleted=0;
  for(int i=0;i<booksum;i++){
    
   if(book_list[i].number==bookdeletenumber){
    
    printf("The name of the book you want to delete:%s.\n",book_list[i].name);
    iffind=1;
    for(int j=0;j<readersum;j++){
    
     if(isdeleted==1){
    
      break;
     }
     for(int k=0;k<reader_list[j].bookborrowedsum;k++){
    
      if(strcmp(reader_list[j].bookborrowed[k],book_list[i].name)==0){
    
       printf("The book cannot be deleted because the reader has not returned all of it!\n");
       isdeleted=1;
       break;
      }
     }
    }
   if(isdeleted==0){
    
   for(int j=i;j<booksum;j++){
    
    book_list[j]=book_list[j+1];
   }
   booksum--;
   }
  }
 }
 if(iffind==0){
    
  printf("Sorry,We can't find the number of the book you want to delete!\n");
 }
}



void reader_information_entry(){
    
     int readernumber;
     char readername[100];
     printf("Please enter the reader information in the format of 'number+name'\n");
     scanf("%d %s",&readernumber,readername);
     for(int i=0;i<readersum;i++){
    
         if(reader_list[i].number==readernumber||strcmp(reader_list[i].name,readername)==0){
    
            printf("This reader already exists!\n");
            return;
         }
     }
     reader_list[readersum].number=readernumber;
     strcpy(reader_list[readersum].name,readername);
     reader_list[readersum].bookborrowedsum=0;
     readersum++;
}


void reader_information_modify(){
    
  printf("Please enter the number of the reader you want to modify!\n");
  int readermodifynumber;
  scanf("%d",&readermodifynumber);
  for(int i=0;i<readersum;i++){
    
   if(reader_list[i].number==readermodifynumber){
    
    printf("the name of the reader you want to modify:%s.\n",reader_list[i].name);
    printf("Please enter the number of book this reader borrowed!\n");
    scanf("%d",&reader_list[i].bookborrowedsum);
    printf("please enter the name of the book he/she borrowed!\n");
    for(int j=0;j<reader_list[i].bookborrowedsum;j++){
    
     char bookwanttomodify[100];
     scanf("%s",bookwanttomodify);
     int isincollection=0;
     for(int k=0;k<booksum;k++){
    
      if(strcmp(book_list[k].name,bookwanttomodify)==0){
    
       isincollection=1;
       break;
      }
     }
     if(isincollection==1){
    
      strcpy(reader_list[i].bookborrowed[j],bookwanttomodify);
     }else{
    
         printf("This book is not in our collection!Please enter again!\n");
         j--;
     }
    }
   }
  }
 }



void reader_information_delete(){
    
  printf("Please enter the number of the reader you want to delete\n");
  int readerdeletenumber;
  scanf("%d",&readerdeletenumber);
  int iffind=0;
  for(int i=0;i<readersum;i++){
    
   if(reader_list[i].number==readerdeletenumber){
    
    iffind=1;
    if(reader_list[i].bookborrowedsum>0){
    
     printf("The reader still has books to return,you cannot delete it!\n");
     break;
    }
    printf("The name of the reader you want to delete:%s\n",reader_list[i].name);
    for(int j=i;j<readersum;j++){
    
     reader_list[j]=reader_list[j+1];
    }
    readersum--;
   }
  }
  if(iffind==0){
    
   printf("Sorry,We can't find the number of the reader you want to delete!\n");
  }
}





int main(int argc,char **argv){
    

    //开始前导入用户,读者,馆藏书目,出借书目对应txt文件的信息   
    load_administratorlist();
    load_readerlist();
    load_booklist();
    load_borrowedlist();
    printf("Data is successfully loaded!\n\n");
    
    if(strcmp(argv[1],"-a")==0){
    
       int isfind1=0;
       for(int i=0;i<administratorsum;i++){
    
           if(strcmp(argv[2],administrator_list[i].name)==0){
    
              isfind1=1;
              break;
           }
       }
       if(isfind1==0){
    
          printf("You are not an administrator, please login again!");
          return 0;
       }
       //检验密码是否正确
       printf("Please enter the corresponding administrator number!\n");
       int inputadministratornumber;
       scanf("%d",&inputadministratornumber);
       for(int i=0;i<administratorsum;i++){
    
           if(strcmp(argv[2],administrator_list[i].name)==0){
    
              if(inputadministratornumber!=administrator_list[i].number){
    
                  printf("Password mistake!");
                  return 0;
              }
              break;
           }
       }
       administratormenu();
       printf("\n");
       while(1){
    
            scanf("%d",&choice);
            if(choice==0){
    
               break;
            }
           switch (choice)
          {
    
              case(1):
                     book_information_entry();
                     break;
              case(2):
                     reader_information_entry();
                     break;
              case(3):
                     book_information_modify();
                     break;
              case(4):
                     reader_information_modify();
                     break;     
              case(5):
                     book_information_delete();
                     break;
              case(6):
                     reader_information_delete();
                     break;
              case(7):
                     book_inquiry();
                     break;
              case(8):
                     display_booklist();
                     break;
              case(9):
                     display_readerlist();
                     break;              
              default:
                     printf("You have entered the wrong information!\n");
            }
        } 
        
        save_administratorlist();                  
        save_readerlist();                         
        save_booklist();                          
        save_borrowedlist();                     
    
    }else if(strcmp(argv[1],"-u")==0){
    
       int isfind2=0;
       for(int i=0;i<readersum;i++){
    
           if(strcmp(argv[2],reader_list[i].name)==0){
    
              isfind2=1;
              break;
           }
       }
       if(isfind2==0){
    
          printf("You are not an reader, please login again!");
          return 0;
       }
       printf("Please enter the corresponding administrator number!\n");
       int inputreadernumber;
       scanf("%d",&inputreadernumber);
       for(int i=0;i<readersum;i++){
    
           if(strcmp(argv[2],reader_list[i].name)==0){
    
              if(inputreadernumber!=reader_list[i].number){
    
                  printf("Password mistake!");
                  return 0;
              }
              break;
           }
       }
       readermenu();
       printf("\n");
       while(1){
    
           scanf("%d",&choice);
           if(choice==0){
    
               break;
            }
           switch (choice)
          {
    
              case(1):
                     book_borrow(argv[2]);
                     break;
              case(2):
                     book_return(argv[2]);
                     break;
              case(3):
                     book_inquiry();
                     break;
              case(4):
                     display_myborrowed(argv[2]);
                     break; 
              default:
                 printf("You have entered the wrong information!\n");
           }       
        }
        
        save_administratorlist();                  
        save_readerlist();                         
        save_booklist();                          
        save_borrowedlist();      

    }else{
    
        printf("You entered the wrong parameter!\n");
    }
    return 0;
}

测试数据(输入,输出):

测试环境

在这里插入图片描述
由于各种容错机制众多没必要全部写在报告内,因此这里只附上关键函数的执行效果检验

1.登录并检验密码是否正确

在这里插入图片描述
在这里插入图片描述

2.显示全部书目和全部读者的信息(管理员),显示读者用户现在借阅的书籍并实现清屏效果

用管理员账号登录并输入操作码8测试对应的显示全部书目功能
在这里插入图片描述
在这里插入图片描述
按下任意键后清屏,重新选择操作码9测试对应的显示全部读者信息的功能
在这里插入图片描述
在这里插入图片描述
按下任意键后清屏,之后退出换为读者模式。测试操作码4对应的显示读者用户现在借阅的书籍功能
在这里插入图片描述
按任意键可实现清屏效果,之后退出完成测试。

3.读者剩余功能测试(借书,还书,查询)

开始操作前的图书馆库信息(管理员教过我的老师,读者为同班的巨佬同学们,书籍为机械工业出版社的计算机丛书,希望以上人员不介意我当初的一时兴起~)

在这里插入图片描述
依次输入操作码1,2,3检验借书,还书,查询功能
在这里插入图片描述
在这里插入图片描述
打开改变后的txt文档可以发现借书,还书操作达到了效果。
在这里插入图片描述

4.管理员剩余功能测试(图书信息录入,读者信息录入,图书信息修改,读者信息修改,图书信息删除,读者信息删除)

开始操作前的图书馆库信息
在这里插入图片描述
依次输入操作码1,2,3,4,5,6检验对应功能
在这里插入图片描述
在这里插入图片描述
打开改变后的txt文档可以发现操作达到了效果。
在这里插入图片描述

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/zimuzi2019/article/details/106721862

智能推荐

没有U盘Win10电脑下如何使用本地硬盘安装Ubuntu20.04(单双硬盘都行)_没有u盘怎么装ubuntu-程序员宅基地

文章浏览阅读3.6k次,点赞2次,收藏2次。DELL7080台式机两块硬盘。_没有u盘怎么装ubuntu

【POJ 3401】Asteroids-程序员宅基地

文章浏览阅读32次。题面Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape of an N x N grid (1 <= N <= 500). The grid contains K asteroids (1 <= K <= 10,000), which are conv...

工业机器视觉系统的构成与开发过程(理论篇—1)_工业机器视觉系统的构成与开发过程(理论篇—1-程序员宅基地

文章浏览阅读2.6w次,点赞21次,收藏112次。机器视觉则主要是指工业领域视觉的应用研究,例如自主机器人的视觉,用于检测和测量的视觉系统等。它通过在工业领域将图像感知、图像处理、控制理论与软件、硬件紧密结合,并研究解决图像处理和计算机视觉理论在实际应用过程中的问题,以实现高效的运动控制或各种实时操作。_工业机器视觉系统的构成与开发过程(理论篇—1

plt.legend的用法-程序员宅基地

文章浏览阅读5.9w次,点赞32次,收藏58次。legend 传奇、图例。plt.legend()的作用:在plt.plot() 定义后plt.legend() 会显示该 label 的内容,否则会报error: No handles with labels found to put in legend.plt.plot(result_price, color = 'red', label = 'Training Loss') legend作用位置:下图红圈处。..._plt.legend

深入理解 C# .NET Core 中 async await 异步编程思想_netcore async await-程序员宅基地

文章浏览阅读2.2k次,点赞3次,收藏11次。深入理解 C# .NET Core 中 async await 异步编程思想引言一、什么是异步?1.1 简单实例(WatchTV并行CookCoffee)二、深入理解(异步)2.1 当我需要异步返回值时,怎么处理?2.2 充分利用异步并行的高效性async await的秘密引言很久没来CSDN了,快小半年了一直在闲置,也写不出一些带有思想和深度的文章;之前就写过一篇关于async await 的异步理解 ,现在回顾,真的不要太浅和太陋,让人不忍直视!好了,废话不再啰嗦,直入主题:一、什么是异步?_netcore async await

IntelliJ IDEA设置类注释和方法注释带作者和日期_idea作者和日期等注释-程序员宅基地

文章浏览阅读6.5w次,点赞166次,收藏309次。当我看到别人的类上面的多行注释是是这样的:这样的:这样的:好装X啊!我也想要!怎么办呢?往下瞅:跟着我左手右手一个慢动作~~~File--->Settings---->Editor---->File and Code Templates --->Includes--->File Header:之后点applay--..._idea作者和日期等注释

随便推点

发行版Linux和麒麟操作系统下netperf 网络性能测试-程序员宅基地

文章浏览阅读175次。Netperf是一种网络性能的测量工具,主要针对基于TCP或UDP的传输。Netperf根据应用的不同,可以进行不同模式的网络性能测试,即批量数据传输(bulk data transfer)模式和请求/应答(request/reponse)模式。工作原理Netperf工具以client/server方式工作。server端是netserver,用来侦听来自client端的连接,c..._netperf 麒麟

万字长文详解 Go 程序是怎样跑起来的?| CSDN 博文精选-程序员宅基地

文章浏览阅读1.1k次,点赞2次,收藏3次。作者| qcrao责编 | 屠敏出品 | 程序员宅基地刚开始写这篇文章的时候,目标非常大,想要探索 Go 程序的一生:编码、编译、汇编、链接、运行、退出。它的每一步具体如何进行,力图弄清 Go 程序的这一生。在这个过程中,我又复习了一遍《程序员的自我修养》。这是一本讲编译、链接的书,非常详细,值得一看!数年前,我第一次看到这本书的书名,就非常喜欢。因为它模仿了周星驰喜剧..._go run 每次都要编译吗

C++之istringstream、ostringstream、stringstream 类详解_c++ istringstream a >> string-程序员宅基地

文章浏览阅读1.4k次,点赞4次,收藏2次。0、C++的输入输出分为三种:(1)基于控制台的I/O (2)基于文件的I/O (3)基于字符串的I/O 1、头文件[cpp] view plaincopyprint?#include 2、作用istringstream类用于执行C++风格的字符串流的输入操作。 ostringstream类用_c++ istringstream a >> string

MySQL 的 binglog、redolog、undolog-程序员宅基地

文章浏览阅读2k次,点赞3次,收藏14次。我们在每个修改的地方都记录一条对应的 redo 日志显然是不现实的,因此实现方式是用时间换空间,我们在数据库崩了之后用日志还原数据时,在执行这条日志之前,数据库应该是一个一致性状态,我们用对应的参数,执行固定的步骤,修改对应的数据。1,MySQL 就是通过 undolog 回滚日志来保证事务原子性的,在异常发生时,对已经执行的操作进行回滚,回滚日志会先于数据持久化到磁盘上(因为它记录的数据比较少,所以持久化的速度快),当用户再次启动数据库的时候,数据库能够通过查询回滚日志来回滚将之前未完成的事务。_binglog

我的第一个Chrome小插件-基于vue开发的flexbox布局CSS拷贝工具_chrome css布局插件-程序员宅基地

文章浏览阅读3k次。概述之前介绍过 移动Web开发基础-flex弹性布局(兼容写法) 里面有提到过想做一个Chrome插件,来生成flexbox布局的css代码直接拷贝出来用。最近把这个想法实现了,给大家分享下。play-flexbox插件介绍play-flexbox一秒搞定flexbox布局,可直接预览效果,拷贝CSS代码快速用于页面重构。 你也可以通过点击以下链接(codepen示例)查_chrome css布局插件

win10下安装TensorFlow-gpu的流程(包括cuda、cuDnn下载以及安装问题)-程序员宅基地

文章浏览阅读308次。我自己的配置是GeForce GTX 1660 +CUDA10.0+CUDNN7.6.0 + TensorFlow-GPU 1.14.0Win10系统安装tensorflow-gpu(按照步骤一次成功)https://blog.csdn.net/zqxdsy/article/details/103152190环境配置——win10下TensorFlow-GPU安装(GTX1660 SUPER+CUDA10+CUDNN7.4)https://blog.csdn.net/jiDxiaohuo/arti