Library management system (C language)

Library management system (C language)


The functional framework is as follows
write picture description here

The management system mainly uses the following operations
  • Create, add, delete, traverse, search, and sort a singly linked list.
  • The linked list writes to the file and reads data from the file to the linked list.
  • Implicit input of passwords, input detection.
  • Register to generate a random account
  • Account login detection
  • Account forgot password
  • The password is simply encrypted and stored in a file, and decrypted and loaded into the linked list

main function

#include "head.h"

int main(void)
{
    Book_head=(Book *)malloc(sizeof(Book));
    Student_head=(Student *)malloc(sizeof(Student));
    Manager_head=(Manager *)malloc(sizeof(Manager));

    Book_head->next=Book_load();
    Student_head->next=Student_load();
    Manager_head->next=Manager_load();

    char ma='1';

    while(ma!='0')
    {
        show_main();
        printf("\t\t\t:");
        scanf("%c",&ma);
        while(getchar()!='\n');
        switch(ma)
        {
            case '1':Student_Port();break;  //学生端
            case '2':Manager_Port();break;  //管理员端
            case '0':Massage_Save();break;  //退出程序,保存链表数据至文件中
            default:printf("\t\t输入错误,请重新输入\n");Sleep(3000);break;
        }
    }
    system("PAUSE");
    return 0;
}

The header file must declare the head nodes of three linked lists (student linked list, book linked list, administrator linked list) in advance. In the main function, the first three lines are to allocate memory for three variables, and then the three lines are loaded from the file. The information to linked list (equivalent to creating a linked list) assigns the created linked list to the next of each node. If the file is empty, it means there is no information. The function to load the information returns NULL, and the next value is set to NULL. Please download the source code to view the specific function.

The following are specific precautions for each function

Student end

  1. Login The
    login port is to enter the account first, and then enter the password. The length of the password input is determined within a certain range. If the password format is incorrect, you will be prompted to re-enter. When entering the password, you should pay attention that the password cannot be displayed (displayed as *). The second is to delete it. For the function of wrong input, firstly check whether the account exists. If it does not exist, it will directly prompt that the account does not exist and return to the previous layer. Otherwise, check the correctness of the password. If it is incorrect, record the number of errors.
  2. Registration For
    registration, you need to pay attention to the problem of password, the length of the password, the number of errors detected, and the operation of the relevant password can be written as a function and called multiple times.
  3. Retrieve the password
    First check whether the account exists, if there is no prompt that there is no such account, exit the previous layer, otherwise, enter the password according to the password input requirements.

Administrator side

The login is the same as the student's login, and the password verification is similar, but the administrator account is fixed and written directly in the file. Every time you enter the program, the linked list is read from the file.

file writing and reading

This is that you can encrypt the password and store it in the file according to your own ideas. When reading, you can decrypt it with your own rules. You can refer to my simple encryption.

linked list

1. Student list
typedef struct stu{
    char stu_acc[10];               //学生账号
    char stu_passw[15];             //学生密码
    char stu_find_question[30];     //密保问题
    char stu_find_passw[15];        //密保问题密码    
    char stu_num[10];               //学生学号
    char stu_name[20];              //学生姓名
    char stu_tel[15];               //学生电话
    char stu_bor_book[10][20];      //所借书号
    struct stu *next;               //下位学生
}Student;
2. Book List
typedef struct book{
    char book_num[10];              //书号
    char book_name[20];             //书名
    char book_at_name[30];          //作者名
    char book_cp_name[30];          //出版社
    float book_price;               //价格
    int book_rest;                  //库存
    struct book *next;              //下本书
}Book;
3. Admin list
typedef struct manager{
    char man_name[15];              //管理员姓名
    char man_acc[10];               //管理员账号
    char man_passw[15];             //管理员密码
    struct manager *next;           //下个管理员
}Manager;

function

void show_main(void);                           //主界面
void show_stu(void);                            //学生端
void show_stu_enter(void);                      //学生页
void show_manager(void);                        //管理员端
void show_manager_enter(void);                  //管理员页
Book *Book_load(void);                          //将书籍文件中的信息加载至书籍链表
Student *Student_load(void);                    //将学生文件中的信息加载至学生链表
Manager *Manager_load(void);                    //将管理员文件的信息加载至管理员链表
void RandStr(int l,char* ch);                   //随机获取一定长度字符串
void Student_Port(void);                        //学生端口
void Manager_Port(void);                        //管理员端口 
void Student_Login(void);                       //学生端登录
void Student_Register(void);                    //学生注册账号
void Find_Password(void);                       //学生找回密码
void Password_Input(char *Password);            //输入密码函数
int Password_Text(char *Password_temp);         //检测密码
Student *Find_Num(char *Stu_num);               //按学号查找学生
int Password_Text_Find(char *Password);         //密保问题密码验证
void Stu_Borrow(Student *Stu_num);              //学生借书
void Stu_Back(Student *Stu_num);                //学生还书
void Find_Book(void);                           //查找书
void Find_Theborrow(Student *Stu_num);          //学生查看所借书
void Change_Stupassword(Student *Stu_num);      //修改密码
Book *Find_BookofName(char *Book_num);          //按书号查找书
void Print_Book(void);                          //打印书单
Book *Book_exit(char *Book_num);                //寻找该书是否存在
int Ifborrow(Student *Stu_num,char *Book_num);  //查询学生是否结果此书
void Print_Borbook(Student *Stu_num);           //打印所借书街
void Bake_Book(Student *Stu_num,char *Book_num);//还书具体操作
void Manager_Login(void);                       //管理员登录
Manager *Manager_check(char *Manager_num);      //核对管理员账号
void Manager_Add_Book(void);                    //管理员上架书籍
void Manager_Down_Book(void);                   //管理员下架书籍
void Manager_Look_Book(void);                   //管理员浏览书架
void Manager_Manager_Stu(void);                 //管理员管理学生
void Manager_Change_Password(Manager *Man_num);//管理员修改密码
void Lookofnum(void);                           //编号升序查看书架
void Lookofrest(void);                          //库存升序查看书架
void Lookofprice(void);                         //价格升序查看
void Manager_Print_Book(void);                  //管理员打印书架
void Manager_Add_Book1(void);                   //增加库存
void Manager_Add_Book2(void);                   //上架新书
void Save_Book(void);                           //保存书籍链表至文件
void Save_Student(void);                        //保存学生链表至文件
void Save_Manger(void);                         //保存管理员链表至文件
void Massage_Save(void);                        //所有信息保存至文件
void Manager_Look_Stu(void);                    //管理员查看学生名单
void Manager_Return_Stu(void);                  // 管理员强制学生还书
void Manager_Del_Stu(void);                     // 删除学生号码并归还所有书籍
Student *Find_Stu(char *Stu_Stuty);             //按学号查学生

File Directory

source code

Source code download

Note: There are only two administrator accounts
Account : 931942280 Password 123456
Account: 10861646 Password 123456

main page

Student end

Login successfully to enter the student page

Administrator side

admin page

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325720928&siteId=291194637