概述
主要包括图书的库存信息,每一本书的借阅信息以及每一个人的借书信息。
系统功能:
(1)借阅资料管理(对相关资料进行添加,删除,修改,查询等操作)
(2)借阅管理(包括借出操作,还书操作)
(3)读者管理(读者等级:可分为教师,学生。并定义每类读者可借书数量)
(4)统计分析(当前借阅和相关资料状态。统计分析借阅排行榜,资料状态统计,借阅统计,显示所有至当日到期未还书信息等功能分析)
如果觉得链表麻烦的话可以使用(数组+文件):https://blog.csdn.net/qq_30253757/article/details/85341155
管理员用户名和密码都是admin
//
// Created by JBC33 on 2019/12/16.
//
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cstring>
#include <windows.h>
#include <ctime>
#include <cstdlib>
using namespace std;
typedef struct books //书籍编号————(作者,名称,出版时间,价格)与书籍编号一一对应,否则为新一类书
{ //数量
int book_id;
char author[50], book_name[50];
int time, count;
double price;
struct books *next;
} BOOK, *Pbook;
typedef struct have_been_borrowed //已借出的图书信息,书籍编号,借书编号,借书数量,书名,所借人的账号名
{
int book_id;
int borrowed_book_id;
int count;
char book_name[50];
char student_id[50];
struct have_been_borrowed *next;
} BORROW, *Pborrow;
typedef struct users //用户信息:用户id,账户名,密码,所借书的上限
{
long long int user_id;
char user_name[50];
char passwd[50];
int book_limit;
int job;
struct users *next;
} USERS, *Pusers;
Pusers user_now = NULL;
/**************************以下为函数声明**********************************/
void user_error(); //无用户信息的错误提示
int read_books_information_to_file(Pbook head, Pborrow head2, Pusers head3); //文件的读取
void welcome(); //欢迎界面
void null_error(); //图书库为空的报错信息
void list_borrow(Pborrow head); //打印已借图书信息
void addbook(struct books *head); //添加书籍信息
void list(Pbook head); //打印所有书籍信息
int search(Pbook head); //搜寻书籍信息
int modify(Pbook p); //搜寻结束后可进行查找
int del(Pbook before, Pbook will_be_del); //删除该图书信息
int borrow(Pbook head, Pborrow borrowed); //借书功能
void return_book_list(Pborrow head, Pbook origin); //还书的列表(便于控制函数的调用)
int return_book(Pborrow head_list, Pbook origin); //还书功能
int return_book_by_student_id(Pborrow head, Pbook origin); //通过学号还书
void add_borrow(Pbook d, Pborrow head, int a, int b, int c, char name[], char book_name[]); //已借的书的添加
void borrowor(Pbook head, Pborrow borrowed); //借书菜单
void del_user(Pusers head); //删除用户
int add_users(Pusers head); //增加用户
void user_list(Pusers head); //打印所有用户信息
int user_manage(Pusers head); //用户管理主列表
int save_books_information_to_file(Pbook head, Pborrow head2, Pusers head3); //文件的保存
/**************************以上为函数声明**********************************/
/***************************图书基础功能***********************************/
int read_books_information_to_file(Pbook head, Pborrow head2, Pusers head3)
{
FILE *p = fopen("books_information.dat", "r"), *q = fopen("borrowed_books.dat", "r");
FILE *u = fopen("users_information.dat", "r");
if (p == NULL || q == NULL || u == NULL)
{
cout << "文件不存在。。。" << endl
<< "已重建相关文件" << endl;
system("pause");
system("cls");
return 1;
}
Pbook books_head = head;
Pborrow borrowed_head = head2;
Pusers users_head = head3;
int a, b, k;
char name[50];
char author[50];
double price;
while (fscanf(p, "%d%s%s%d%lf%d", &a, name, author, &k, &price, &b) != EOF)
{
Pbook before = (Pbook)malloc(sizeof(BOOK));
before->book_id = a;
strcpy(before->book_name, name);
strcpy(before->author, author);
before->count = b;
before->time = k;
before->price = price;
books_head->next = before;
before->next = NULL;
books_head = before;
}
int c, d, e;
char borrow_name[50];
char student_id[50];
while (fscanf(q, "%d%s%d%d%s", &c, borrow_name, &d, &e, &student_id) != EOF)
{
Pborrow after = (Pborrow)malloc(sizeof(BORROW));
after->book_id = c;
strcpy(after->book_name, borrow_name);
after->borrowed_book_id = d;
after->count = e;
strcpy(after->student_id, student_id);
borrowed_head->next = after;
after->next = NULL;
borrowed_head = after;
}
long long user_id;
char user_name[50];
char passwd[50];
int book_limit;
int job;
while (fscanf(u, "%lld%s%s%d%d", &user_id, user_name, passwd, &book_limit,&job) != EOF)
{
Pusers english = (Pusers)malloc(sizeof(USERS));
english->user_id = user_id;
strcpy(english->user_name, user_name);
strcpy(english->passwd, passwd);
english->book_limit = book_limit;
english->job=job;
users_head->next = english;
english->next = NULL;
users_head = english;
}
fclose(p);
fclose(q);
fclose(u);
return 0;
}
int save_books_information_to_file(Pbook head, Pborrow head2, Pusers head3)
{
system("cls");
FILE *p = fopen("books_information.dat", "w");
FILE *bore = fopen("borrowed_books.dat", "w");
FILE *u = fopen("users_information.dat", "w");
if (p == NULL )
{
cout << "打开文件失败!!!,请重试。。。" << endl;
return 1;
}
if ( bore == NULL)
{
cout << "打开文件失败!!!,请重试。。。" << endl;
return 1;
}
if ( u == NULL)
{
cout << "打开文件失败!!!,请重试。。。" << endl;
return 1;
}
Pbook q = head->next;
Pborrow w = head2->next;
Pusers eng = head3->next;
cout << "正在写入文件,请稍后。。。" << endl;
Sleep(1500);
while (q != NULL)
{
fprintf(p, "%d %s %s %d %f %d\n", q->book_id, q->book_name, q->author, q->time, q->price, q->count);
q = q->next;
}
while (w != NULL)
{
fprintf(bore, "%d %s %d %d %s\n", w->book_id, w->book_name, w->borrowed_book_id, w->count, w->student_id);
w = w->next;
}
while (eng != NULL)
{
fprintf(u, "%lld %s %s %d %d\n", eng->user_id, eng->user_name, eng->passwd, eng->book_limit,eng->job);
eng = eng->next;
}
system("cls");
cout << "写入完成。请稍后。。。" << endl;
fclose(p);
fclose(bore);
fclose(u);
return 0;
}
void list_borrow(Pborrow head)
{
if (head->next == NULL)
{
sys