IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> C++知识库 -> C++自编图书借阅系统 -> 正文阅读

[C++知识库]C++自编图书借阅系统

C++自编图书借阅系统

小编用 C++编写了一个简单的图书借阅系统,一起来看看吧 ~~~
代码十分冗长,功能演示视频见个人B站:

https://www.bilibili.com/video/BV1ZB4y1N7ET/

主要功能简介

此系统主要面向读者用户、管理员、主管三种使用者,通过账号识别使用者身份(用户账号以2开头,管理员以1开头,主管以A开头),具有如下图所示的功能,并且能根据使用者的操作,实时地修改系统的.csv文件,记录书库中书籍信息的变化或者人员信息的变化,具体的功能展现请见功能演示视频。

程序代码

代码简介

Class.h ———— 类的声明与定义
FunctionList.h ———— 类外函数的声明
FunctionRealization.h ———— 类外函数的实现
ClassFunctionRealization.h ———— 类函数的实现
LibraryManagementSystem.cpp ———— 主程序

源代码

// Class.h

#pragma once
#include<string.h>
#include"FunctionList.h"
#ifndef __CLASS_H__
#define __CLASS_H__
const int lend_maxn = 3;             //单个用户最大借阅数量为3册
const int news_maxn = 1000;          //收件箱最大存储量为1000条消息

class Person {
public:
	Person() {                               //构造函数
		password = "12345678";               //所有账户初始密码
	}                            
	string name;                             //姓名
	string ID;                               //账号(用户以2开头,管理员以1开头,主管以A开头)
	
	virtual void find() = 0;                 //查询书籍信息纯虚函数
	virtual void querying() = 0;             //查询用户信息纯虚函数
	virtual void start_menu() = 0;           //主页纯虚函数
	virtual void end() = 0;                  //结束操作纯虚函数
	string get_password();                   //系统取密码函数
	friend void set_password(Person* ptr);   //设置密码友元函数
	friend void reset_password(Person* ptr); //重置密码友元函数
protected:
	string password;                         //账户密码
};

class User :public Person {
public:
	User() {                      //构造函数
		book_number = 0;          //初始借阅数目为0
		news_number = 0;          //初始消息数目为0
	}
	string campus;                //校区
	string institute;             //学院
	string news[news_maxn];       //账户收件箱数组
	string book[lend_maxn];       //所借书籍总信息数组
	string book_name[lend_maxn];  //所借书籍名称数组
	string book_id[lend_maxn];    //所借书籍编号数组
	int book_number;              //借阅图书数目
	int news_number;              //消息数目
	void find();                  //子类书籍信息查询函数
	void querying();              //子类查询用户信息函数
	void appointing();            //预约函数
	void borrowing();             //借书函数
	void returning();             //还书函数
	void reborrowing();           //续借函数
	void read_news();             //查看收件箱函数
	void clear_news();            //清空收件箱函数
	void start_menu();            //用户主页函数
	void end();                   //用户结束操作函数
};

class Administrator :public Person {
public:
	Administrator() {             //构造函数
		to_do_num = 0;            //初始待办事项数目为0
		news_number = 0;          //初始消息数目为0
	}
	Administrator(const Administrator& a) {
		this->name = a.name;      //深度复制构造函数
		this->ID = a.ID;
		this->news_number = a.news_number;
		this->password = a.password;
		this->to_do_num = a.to_do_num;
		this->to_process_book = new string[100];
		this->to_process_user = new string[100];
		for (int i = 0; i < this->to_do_num; i++) {
			this->to_process_book[i] = a.to_process_book[i];
			this->to_process_user[i] = a.to_process_user[i];
		}
	}
	int to_do_num;                //待办事项数目  
	int news_number;              //消息数目
	string news[news_maxn];       //账户收件箱数组
	string* to_process_book = new string[100];
	                              //待处理预约书籍动态数组
	string* to_process_user = new string[100];  
	                              //待处理预约用户动态数组
	void add_book();              //新增书籍函数
	void read_news();             //查看收件箱函数
	void clear_news();            //清空收件箱函数
	void find();                  //子类书籍信息查询函数
	void querying();              //子类查询用户信息函数
    void start_menu();            //主页函数
	void process_appoingting();   //处理预约函数
	void end();                   //结束操作函数
	void operator<<(const User& u);//运算符重载函数用于输出用户信息
	~Administrator() {             //析构函数
		delete[] to_process_book;
		delete[] to_process_user;
	}
};

class Manager :public Administrator {
public:
	Manager() {};                 //构造函数
	Manager(const Manager& m) {
		this->name = m.name;      //深度复制构造函数
		this->ID = m.ID;
		this->news_number = m.news_number;
		this->password = m.password;
		this->to_do_num = m.to_do_num;
		this->to_process_book = new string[100];
		this->to_process_user = new string[100];
		for (int i = 0; i < this->to_do_num; i++) {
			this->to_process_book[i] = m.to_process_book[i];
			this->to_process_user[i] = m.to_process_user[i];
		}
	}
	void add_admin();             //新增管理员函数
	void find_admin();            //查找管理员函数
	void find();                  //子类书籍信息查询函数
	void querying();              //子类查询用户信息函数
	void start_menu();            //主页函数
	void end();                   //结束操作函数
};

class Book {
public: 
	Book() {                      //构造函数
		lended_time = 0;          //初始化为未被借阅状态
		islended = false;
		user_name = " - ";        //借阅者信息均初始为空
		user_ID = " - ";
		user_campus = " - ";
	}
	string book_name;             //书名
	string book_number;           //编号
	string campus;                //所在校区
	string press;                 //出版社
	string classification;        //类别
	int lended_time;              //借阅次数
	bool islended;                //是否处于被借状态
	string user_name;             //借阅者姓名
	string user_ID;               //借阅者账号
	string user_campus;           //借阅者所在校区
};

#endif

// FunctionList.h

#pragma once
#ifndef __FUNCTIONLIST_H__
#define __FUNCTIONLIST_H__
#include<vector>
#include"Class.h"
#define book_maxn 5000000                      //最大图书数量为5000000册
#define user_maxn 100000                       //最大用户数量为100000人
#define day_maxn 30                            //单册书单次借阅最长时间为30天


#define USER_FILE "user.csv"                   //添加全局文件记录用户信息
#define ADMINISTRATOR_FILE "administrator.csv" //添加全局文件记录管理员信息
#define MANAGER_FILE "manager.csv"             //添加全局文件记录主管信息
#define BOOK_FILE "book.csv"                   //添加全局文件记录书籍信息

static int book_num = 15;             //系统初始图书数量为15
static int administrator_num = 3;     //系统初始管理员数目为3
static int user_num = 5;              //系统初始用户数目为5
static int manager_num = 1;           //系统初始总管数目为1


vector<User>user_information;         //全局数组用于记录所有用户的信息
vector<Administrator>ad_information;  //全局数组用于记录所有管理员的信息
vector<Manager>manager_information;   //全局数组用于记录所有主管的信息
vector<Book>book_information;         //全局数组用于记录所有书籍的信息

//设置初始对象的目的是为了便于测试系统功能

void book_file_process();        //书籍文件写入函数
void user_file_process();        //用户文件写入函数
void admin_file_process();       //管理员文件写入函数
void manager_file_process();     //主管文件写入函数
void welcome();                  //打印欢迎界面函数
void initialize();               //系统数据初始函数
void find(Person* ptr);          //查询书籍信息函数
void querying(Person* ptr);      //查询用户信息函数
void start_menu(Person* ptr);    //主页函数
void end(Person* ptr);           //结束操作函数
string get_time();               //获取当前时间函数
void load();                     //登陆界面函数

#endif

// FunctionRealization.h

#pragma once
#ifndef __FUNCYIONREALIZATION_H__
#define __FUNCTIONREALIZATION_H__
#include<time.h>
#include<fstream>
#include<iomanip>
#include<string>
#include<Windows.h>
#include"FunctionList.h"
#include"ClassFunctionRealization.h"

//FunctionList.h中的函数实现
void welcome() {                                           //打印欢迎界面函数实现
	std::cout << "=====================================================================" << endl;
	std::cout << "=================== 欢迎使用中山大学图书借阅系统!===================" << endl;
	std::cout << "=====================================================================" << endl;
	std::cout << "=== WELCOME TO THE BOOK LENDING SYSTEM OF SUN-YAT-SEN UNIVERSITY!===" << endl;
	std::cout << "=====================================================================" << endl;
	std::cout << endl;
}

string get_time() {                                        //获取当前时间函数实现
	SYSTEMTIME time;
	GetLocalTime(&time);
	string Time;
	Time = to_string(time.wYear) + "/";
	if (time.wMonth < 10)
		Time = Time + "0" + to_string(time.wMonth) + "/";
	else Time = Time + to_string(time.wMonth) + "/";
	if (time.wDay < 10)
		Time = Time + "0" + to_string(time.wDay) + " ";
	else Time = Time + to_string(time.wDay) + " ";
	if (time.wHour < 10)
		Time = Time + "0" + to_string(time.wHour) + ":";
	else Time = Time + to_string(time.wHour) + ":";
	if (time.wMinute < 10)
		Time = Time + "0" + to_string(time.wMinute) + ":";
	else Time = Time + to_string(time.wMinute) + ":";
	if (time.wSecond < 10)
		Time = Time + "0" + to_string(time.wSecond);
	else Time = Time + to_string(time.wSecond);
	return Time;
}

void book_file_process() {                                 //书籍写入文件函数
	ofstream out_book;
	out_book.open(BOOK_FILE, ios::out);
	out_book << "\"书籍名称\"" << "," << "\"书籍编号\"" << "," << "\"书籍类别\"" << "," <<
		"\"所在校区\"" << "," << "\"出版社\"" << "," << "\"历史借阅次数\"" << "," << "\"是否外借\"" << "," <<
		"\"借阅者姓名\"" << "," << "\"借阅者学号\"" << "," << "\"借阅者所在校区\"" << endl;
	for (int i = 0; i < book_num; i++) {
		out_book << book_information[i].book_name << "," << book_information[i].book_number << ","
			<< book_information[i].classification << "," << book_information[i].campus << ","
			<< book_information[i].press <<","<< book_information[i].lended_time << ",";
		if (book_information[i].islended) {
			out_book << "\"是\"" << "," << book_information[i].user_name << "," <<
				book_information[i].user_ID << "," << book_information[i].user_campus << endl;
		}
		else {
			out_book << "\"否\"" << "," << book_information[i].user_name << "," <<
				book_information[i].user_ID << "," << book_information[i].user_campus << endl;
		}
	}
	out_book.close();
}

void user_file_process() {                                 //用户文件写入函数
	ofstream out_user;
	out_user.open(USER_FILE, ios::out);
	out_user << "\"姓名\"" << "," << "\"学号\"" << "," << "\"所在校区\"" << ","
		<< "\"学院\"" << "," << "\"在借书籍\"" << endl;
	for (int i = 0; i < user_num; i++) {
		out_user << user_information[i].name << "," << user_information[i].ID << ","
			<< user_information[i].campus << "," << user_information[i].institute << ",";
		if (!user_information[i].book_number) {
			out_user << "\" - \"" << endl;
		}
		else {
			for (int j = 0; j < user_information[i].book_number; j++) {
				out_user << user_information[i].book_id[j] << " ";
			}
			out_user << endl;
		}
	}
	out_user.close();
}

void admin_file_process() {                                //管理员文件写入函数
	ofstream out_admin;
	out_admin.open(ADMINISTRATOR_FILE, ios::out);
	out_admin << "\"姓名\"" << "," << "\"工号\"" << endl;
	for (int i = 0; i < administrator_num; i++) {
		out_admin << ad_information[i].name << "," << ad_information[i].ID << endl;
	}
	out_admin.close();
}

void manager_file_process() {                              //主管文件写入函数
	ofstream out_manager;
	out_manager.open(MANAGER_FILE, ios::out);
	out_manager << "\"姓名\"" << "," << "\"工号\"" << endl;
	for (int i = 0; i < manager_num; i++) {
		out_manager << manager_information[i].name << "," << "\t"<<manager_information[i].ID << endl;
	}
	out_manager.close();
}

void initialize() {                                        //系统数据初始函数实现
	Book b1;
	b1.book_name = "C++语言程序设计(第4版)";
	b1.book_number = "19-01-SC";
	b1.campus = "广州南校园";
	b1.press = "清华大学出版社";
	b1.classification = "科学";
	b1.lended_time = 50;
	book_information.push_back(b1);

	Book b2;
	b2.book_name = "C Primer Plus";
	b2.book_number = "18-04-SC";
	b2.campus = "广州南校园";
	b2.press = "人民邮电出版社";
	b2.classification = "科学";
	b2.lended_time = 60;
	book_information.push_back(b2);

	Book b3;
	b3.book_name = "思想道德修养与法律基础";
	b3.book_number = "16-03-ED";
	b3.campus = "广州南校园";
	b3.press = "高等教育出版社";
	b3.classification = "教育";
	b3.lended_time = 98;
	book_information.push_back(b3);

	Book b4;
	b4.book_name = "老人与海";
	b4.book_number = "14-07-FL";
	b4.campus = "广州东校园";
	b4.press = "上海译文出版社";
	b4.classification = "外国文学";
	b4.lended_time = 46;
	book_information.push_back(b4);

	Book b5;
	b5.book_name = "毛泽东选集";
	b5.book_number = "12-00-PT";
	b5.campus = "广州东校园";
	b5.press = "人民出版社";
	b5.classification = "党政思想";
	b5.lended_time = 37;
	book_information.push_back(b5);

	Book b6;
	b6.book_name = "大学体育健康理论与实践";
	b6.book_number = "15-10-PY";
	b6.campus = "广州东校园";
	b6.press = "北京体育大学出版社";
	b6.classification = "体育";
	b6.lended_time = 9;
	book_information.push_back(b6);

	Book b7;
	b7.book_name = "奥林匹克数学中的组合问题";
	b7.book_number = "18-12-SC";
	b7.campus = "广州北校园";
	b7.press = "湖南师范大学出版社";
	b7.classification = "科学";
	b7.lended_time = 113;
	book_information.push_back(b7);

	Book b8;
	b8.book_name = "C Primer PLUS";
	b8.book_number = "17-04-SC";
	b8.campus = "广州北校园";
	b8.press = "人民邮电出版社";
	b8.classification = "科学";
	b8.lended_time = 60;
	book_information.push_back(b8);

	Book b9;
	b9.book_name = "邓小平理论";
	b9.book_number = "08-00-PT";
	b9.campus = "广州北校园";
	b9.press = "人民出版社";
	b9.classification = "党政思想";
	b9.lended_time = 16;
	book_information.push_back(b9);

	Book b10;
	b10.book_name = "C Primer Plus";
	b10.book_number = "15-04-SC";
	b10.campus = "珠海校区";
	b10.press = "人民邮电出版社";
	b10.classification = "科学";
	b10.lended_time = 62;
	book_information.push_back(b10);

	Book b11;
	b11.book_name = "奥林匹克数学中的数论问题";
	b11.book_number = "16-12-SC";
	b11.campus = "珠海校区";
	b11.press = "湖南师范大学出版社";
	b11.classification = "科学";
	b11.lended_time = 108;
	book_information.push_back(b11);

	Book b12;
	b12.book_name = "莎士比亚选集";
	b12.book_number = "07-07-FL";
	b12.campus = "深圳校区";
	b12.press = "上海译文出版社";
	b12.classification = "外国文学";
	b12.lended_time = 56;
	book_information.push_back(b12);

	Book b13;
	b13.book_name = "C++语言程序设计(第4版)";
	b13.book_number = "12-01-SC";
	b13.campus = "深圳校区";
	b13.press = "清华大学出版社";
	b13.classification = "科学";
	b13.lended_time = 59;
	book_information.push_back(b13);

	Book b14;
	b14.book_name = "奥林匹克数学中的代数问题";
	b14.book_number = "08-12-SC";
	b14.campus = "深圳校区";
	b14.press = "湖南师范大学出版社";
	b14.classification = "科学";
	b14.lended_time = 104;
	book_information.push_back(b14);

	Book b15;
	b15.book_name = "世界近代史";
	b15.book_number = "14-07-HT";
	b15.campus = "深圳校区";
	b15.press = "上海译文出版社";
	b15.classification = "历史";
	b15.lended_time = 32;
	book_information.push_back(b15);
	book_file_process();


	User u1;
	u1.name = "张华";
	u1.ID = "20000001";
	u1.campus = "深圳校区";
	u1.institute = "智能工程学院";
	user_information.push_back(u1);
	
	User u2;
	u2.name = "李明";
	u2.ID = "20000002";
	u2.campus = "广州南校园";
	u2.institute = "岭南学院";
	user_information.push_back(u2);

	User u3;
	u3.name = "罗俊";
	u3.ID = "20000003";
	u3.campus = "珠海校区";
	u3.institute = "海洋学院";
	user_information.push_back(u3);

	User u4;
	u4.name = "陈风";
	u4.ID = "20000004";
	u4.campus = "广州东校区";
	u4.institute = "计算机学院";
	user_information.push_back(u4);

	User u5;
	u5.name = "朱灿";
	u5.ID = "20000005";
	u5.campus = "珠海校区";
	u5.institute = "旅游学院";
	user_information.push_back(u5);
	user_file_process();


	Administrator a1;
	a1.name = "钱枫";
	a1.ID = "10000001";
	ad_information.push_back(a1);

	Administrator a2;
	a2.name = "李想";
	a2.ID = "10000002";
	ad_information.push_back(a2);

	Administrator a3;
	a3.name = "冯天";
	a3.ID = "10000003";
	ad_information.push_back(a3);
	admin_file_process();


	Manager m1;
	m1.name = "周舟";
	m1.ID = "A0000001";
	manager_information.push_back(m1);
	manager_file_process();
}

void find(Person* ptr) {                                   //查询书籍信息函数实现
	ptr->find();
}

void querying(Person* ptr) {                               //查询用户信息函数实现
	ptr->querying();
}

void start_menu(Person* ptr) {                             //主页函数实现
	ptr->start_menu();
}

void end(Person* ptr) {                                    //结束操作函数实现
	ptr->end();
}

void load() {                                              //登录界面函数实现
	welcome();
	string id, password;
	cout << "    $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$    " << endl;
	cout << "    $$                                                          $$    " << endl;
	cout << "    $$                     登       录    1                     $$    " << endl;
	cout << "    $$                                                          $$    " << endl;
	cout << "    $$                     注       册    2                     $$    " << endl;
	cout << "    $$                                                          $$    " << endl;
	cout << "    $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$    " << endl;
	cout << endl;
	cout << "    请选择操作类型,或按0退出:";
	int type4;
	cin >> type4;
	if (type4 == 2) {                             //若选择注册
		cout << "    欢迎注册!" << endl;
		cout << "    请输入您的学号:";
		cin >> id;
		while (id[0] != '2') {
			cout << "    请输入正确的学号!" << endl;
			cout << "    请输入您的学号:";
			cin >> id;
		}
		User user_temp;
		bool isexisted = false;
		for (int i = 0; i < user_num; i++) {     //查看申请注册用户是否已存在
			if (user_information[i].ID == id) {  //若已存在
				cout << "    账户已存在!即将返回首页......" << endl;
				Sleep(1500);
				system("cls");
				isexisted = true;
				load();
				break;
			}
		}
		if (isexisted == false) {                //若用户不存在
			user_temp.ID = id;
			cout << "    请输入您的姓名:";
			cin >> user_temp.name;
			cout << "    $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$    " << endl;
			cout << "    $$                                                          $$    " << endl;
			cout << "    $$                   广 州 南 校 园     1                   $$    " << endl;
			cout << "    $$                                                          $$    " << endl;
			cout << "    $$                   广 州 东 校 园     2                   $$    " << endl;
			cout << "    $$                                                          $$    " << endl;
			cout << "    $$                   广 州 北 校 园     3                   $$    " << endl;
			cout << "    $$                                                          $$    " << endl;
			cout << "    $$                   珠  海  校  区     4                   $$    " << endl;
			cout << "    $$                                                          $$    " << endl;
			cout << "    $$                   深  圳  校  区     5                   $$    " << endl;
			cout << "    $$                                                          $$    " << endl;
			cout << "    $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$    " << endl;
			cout << "    请选择您所在的校区:";
			cin >> type4;
			switch (type4) {
			case 1:
				user_temp.campus = "广州南校区"; break;
			case 2:
				user_temp.campus = "广州东校园"; break;
			case 3:
				user_temp.campus = "广州北校园"; break;
			case 4:
				user_temp.campus = "珠海校区"; break;
			case 5:
				user_temp.campus = "深圳校区";
			}
			cout << "    请输入您的学院名称:";
			cin >> user_temp.institute;
			set_password(&user_temp);
			user_information.push_back(user_temp);
			user_num++;
			user_information[user_num - 1].news[user_information[user_num - 1].news_number] =
				get_time() + "  您已成功注册成为中山大学图书借阅系统用户,欢迎成为阅读者!";
			user_information[user_num - 1].news_number++;
			user_file_process();                 //修改csv文件  

			cout << "    注册成功!您已成为第" << user_num << "位阅读者!" << endl;
			cout << endl;
			cout << "    即将返回首页......";
			Sleep(1500);
			system("cls");
			load();
		}
	}

	    else if (type4 == 1) {                    //若选择登录
		cout << "    请输入您的账号:";
		cin >> id;
		cout << "    请输入您的密码:";
		cin >> password;
		bool isexisted = false;
		if (id[0] == '2') {                      //如果账号以2开头,则为用户
			int temp;
			for (int i = 0; i < user_num; i++) { //查找用户
				if (user_information[i].ID == id) {
					temp = i;
					isexisted = true;
					break;
				}
			}
			if (!isexisted) {                    //如果查找不到此用户
				cout << "    用户不存在!请检查账号是否输入有误或先注册!" << endl;
				cout << "    即将退出程序......" << endl;
				Sleep(1500);
				system("cls");
				load();
			}
			else {
				while (password != user_information[temp].get_password()) {
					cout << "    密码错误,请重新输入!若需重置密码请按 # :";
					cin >> password;
					if (password == "#") {
						reset_password(&user_information[temp]);
						break;
					}
				}
				cout << "    登录成功!即将进入用户主页......" << endl;
				Sleep(1500);                         //停顿1.5秒
				system("cls");
				start_menu(&user_information[temp]); //进入用户主页
			}
		}

		if (id[0] == '1') {                                     //若账号以1开头,则为管理员
			int temp;
			for (int i = 0; i < administrator_num; i++) {       //查找管理员
				if (ad_information[i].ID == id) {
					temp = i;
					isexisted = true;
					break;
				}
			}
			if (!isexisted) {                                   //如果查找不到此管理员
				cout << "    管理员不存在!请检查账号是否输入有误!如遇问题请联系主管!" << endl;
				cout << "    即将返回主页......" << endl;
				Sleep(1500);                                    //停顿1.5秒
				system("cls");                                  //清空屏幕
				load();                                         //返回登陆界面
			}
			else {
				while (password != ad_information[temp].get_password()) {
					cout << "    密码错误,请重新输入!若需重置密码请按 # :";
					cin >> password;
					if (password == "#") {
						reset_password(&ad_information[temp]);
						break;
					}
				}
				cout << "    登录成功!即将进入管理员主页......" << endl;
				Sleep(1500);                                    //停顿1.5秒
				system("cls");                                  //清空屏幕
				start_menu(&ad_information[temp]);              //进入管理员主页
			}
			
		}

		if (id[0] == 'A') {                                     //若账号以A开头,则为主管
			int temp;
			for (int i = 0; i < manager_num; i++) {             //查找主管
				if (manager_information[i].ID == id) {
					temp = i;
					isexisted = true;
					break;
				}
			}
			if (!isexisted) {                                   //如果查找不到此主管
				cout << "    主管不存在!请检查账号是否输入有误!" << endl;
				cout << "    即将返回主页......" << endl;
				Sleep(1500);
				system("cls");
				load();
			}
			else {
				while (password != manager_information[temp].get_password()) {
					cout << "    密码错误,请重新输入!若需重置密码请按 # :";
					cin >> password;
					if (password == "#") {
						reset_password(&manager_information[temp]);
						break;
					}
				}
				cout << "    登录成功!即将进入主管主页......" << endl;
				Sleep(1500);                     //停顿1.5秒
				system("cls");                   //清空屏幕
				start_menu(&manager_information[temp]);//进入主管主页
			}
		}
	}
		else if (type4 == 0) {
		cout << endl;
		cout << "=====================================================================" << endl;
		cout << "=================== 感谢使用中山大学图书借阅系统!===================" << endl;
		cout << "=====================================================================" << endl;
	}
}

#endif

// ClassFunctionRealization.h

#pragma once
#ifndef __CLASSFUNCTIONREALIZATION_H__
#define __CLASSFUNCTIONREALIZATION_H__
#include"Class.h"
#include"FunctionRealization.h"

//类函数实现

//Person类
string Person::get_password() {                            //系统取密码函数实现
	return password;
}

void reset_password(Person* ptr) {                         //重置密码友元函数实现
	string p1, p2;
	std::cout << "    请设置您的新密码:";
	std::cin >> p1;
	std::cout << "    请确认您的新密码:";
	std::cin >> p2;
	while (p1 != p2) {
		std::cout << "    两次输入密码不一致!请重新操作!" << endl;
		std::cout << "    请设置您的新密码:";
		std::cin >> p1;
		std::cout << "    请确认您的新密码:";
		std::cin >> p2;
	}
	std::cout << "    重置密码成功!" << endl;
	ptr->password = p1;
}

void set_password(Person* ptr) {                           //设置密码友元函数实现
	string p1, p2;
	std::cout << "    请设置您的密码:";
	std::cin >> p1;
	std::cout << "    请确认您的密码:";
	std::cin >> p2;
	while (p1 != p2) {
		std::cout << "    两次输入密码不一致!" << endl;
		std::cout << "    请确认您的密码:";
		std::cin >> p2;
	}
	ptr->password = p1;
}

//User类
void User::find() {                                        //用户查询书籍信息函数实现
	welcome();
	std::cout << "               ------******* 书籍信息查询 *******------           " << endl;
	std::cout << "    ---------------********************************---------------" << endl;
	std::cout << endl;
	std::cout << "    $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$    " << endl;
	std::cout << "    $$                                                          $$    " << endl;
	std::cout << "    $$               按  书  名  查  找         1               $$    " << endl;
	std::cout << "    $$                                                          $$    " << endl;
	std::cout << "    $$               按  编  号  查  找         2               $$    " << endl;
	std::cout << "    $$                                                          $$    " << endl;
	std::cout << "    $$               按  类  别  查  找         3               $$    " << endl;
	std::cout << "    $$                                                          $$    " << endl;
	std::cout << "    $$               热  榜   T O P  3          4               $$    " << endl;
	std::cout << "    $$                                                          $$    " << endl;
	std::cout << "    $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$    " << endl;
	int type2;
	std::cout << endl;
	std::cout << "请选择操作类型:";
	std::cin >> type2;
	switch (type2) {
	case 1: {
		string name1;
		std::cout << "    请输入书籍名称:";
		std::cin >> name1;
		std::cout << endl;
		bool isexisted = false;
		for (int i = 0; i < book_num; i++) {
			if (book_information[i].book_name == name1) {
				isexisted = true;
				std::cout << "    " << left << setw(25) << "书籍名称" << left << setw(15) << "书籍编号" << left << setw(15) << "所在校区"
					<< left << setw(15) << "书籍类别" << left << setw(25) << "出版社" << left << setw(10) << "是否外借" << endl;
				break;
			}
		}
		if (isexisted) {
			for (int i = 0; i < book_num; i++) {
				if (book_information[i].book_name == name1) {
					std::cout << "    " << left << setw(25) << book_information[i].book_name << left << setw(15)
						<< book_information[i].book_number << left << setw(15) << book_information[i].campus
						<< left << setw(15) << book_information[i].classification << left << setw(25) << book_information[i].press;
					if (book_information[i].islended)
						std::cout << left << setw(10) << "  是" << endl;
					else
						std::cout << left << setw(10) << "  否" << endl;
				}
			}
		}
		else {
			std::cout << "    " << "抱歉,未查询到此书籍!" << endl;
		}
		break;
	}
	case 2:
	{
		string id;
		std::cout << "    请输入书籍编号:";
		std::cin >> id;
		std::cout << endl;
		bool isexisted = false;
		for (int i = 0; i < book_num; i++) {
			if (book_information[i].book_number == id) {
				isexisted = true;
				std::cout << "    " << left << setw(25) << "书籍名称" << left << setw(15) << "书籍编号" << left << setw(15) << "所在校区"
					<< left << setw(15) << "书籍类别" << left << setw(25) << "出版社" << left << setw(10) << "是否外借" << endl;
				break;
			}
		}
		if (isexisted) {
			for (int i = 0; i < book_num; i++) {
				if (book_information[i].book_number == id) {
					std::cout << "    " << left << setw(25) << book_information[i].book_name << left << setw(15)
						<< book_information[i].book_number << left << setw(15) << book_information[i].campus
						<< left << setw(15) << book_information[i].classification << left << setw(25) << book_information[i].press;
					if (book_information[i].islended)
						std::cout << left << setw(10) << "  是" << endl;
					else
						std::cout << setw(10) << "  否" << endl;
				}
			}
		}
		else {
			std::cout << "    " << "抱歉,未查询到此书籍!" << endl;
		}
		break;
	}
	case 3: {
		string classification;
		std::cout << "    请输入书籍类别:";
		std::cin >> classification;
		std::cout << endl;
		bool isexisted = false;
		for (int i = 0; i < book_num; i++) {
			if (book_information[i].classification == classification) {
				isexisted = true;
				std::cout << "    " << left << setw(25) << "书籍名称" << left << setw(15) << "书籍编号" << left << setw(15) << "所在校区"
					<< left << setw(15) << "书籍类别" << left << setw(25) << "出版社" << left << setw(10) << "是否外借" << endl;
				break;
			}
		}
		if (isexisted) {
			for (int i = 0; i < book_num; i++) {
				if (book_information[i].classification == classification) {
					std::cout << "    " << left << setw(25) << book_information[i].book_name << left << setw(15)
						<< book_information[i].book_number << left << setw(15) << book_information[i].campus
						<< left << setw(15) << book_information[i].classification << left << setw(25) << book_information[i].press;
					if (book_information[i].islended)
						std::cout << left << setw(10) << "  是" << endl;
					else
						std::cout << left << setw(10) << "  否" << endl;
				}
			}
		}
		else {
			std::cout << "    " << "抱歉,未查询到此类书籍!" << endl;
		}
		break;
	}
	case 4: {
		int m1 = 0, m2 = 0, m3 = 0;
		string top1, top2, top3;
			for (int i = 0; i < book_num; i++) {
				if (book_information[i].lended_time > m1) {
					m1 = book_information[i].lended_time;
					top1 = book_information[i].book_name;
				}
			}
			for (int i = 0; i < book_num; i++) {
				if (book_information[i].lended_time > m2 && book_information[i].lended_time < m1) {
					m2 = book_information[i].lended_time;
					top2 = book_information[i].book_name;
				}
			}
			for (int i = 0; i < book_num; i++) {
				if (book_information[i].lended_time > m3 && book_information[i].lended_time < m2) {
					m3 = book_information[i].lended_time;
					top3 = book_information[i].book_name;
				}
			}
			std::cout << endl << "        T O P 3 数目如下:" << endl;
			std::cout << "        1." << top1 << endl;
			std::cout << "        2." << top2 << endl;
			std::cout << "        3." << top3 << endl;
	}
	}
	std::cout << "    ---------------********************************---------------" << endl;
	std::cout << "               --------************************--------           " << endl;
}

void User::querying() {
	//清屏操作!!!!!
	welcome();
	std::cout << "               -------****** 用户信息查询 ******-------           " << endl;
	std::cout << "    ---------------********************************---------------" << endl;
	std::cout << endl;
	std::cout << "        姓名:" << this->name << endl;
	std::cout << "        学号:" << this->ID << endl;
	std::cout << "        学院:" << this->institute << endl;
	std::cout << "        校区:" << this->campus << endl;
	std::cout << "        在借图书:";
	if (!book_number) {
		std::cout << "当前无在借图书!" << endl;
	}
	else {
		std::cout << endl;
		for (int i = 0; i < book_number; i++) {
			std::cout << "                " << i + 1 << "." << book[i] << endl;
		}
	}
	std::cout << "    ---------------********************************---------------" << endl;
	std::cout << "               --------************************--------           " << endl;
}

void User::appointing() {                                  //预约函数实现
	welcome();
	std::cout << "               ------********* 办理预约 *********------           " << endl;
	std::cout << "    ---------------********************************---------------" << endl;
	std::cout << endl;
	std::cout << "        请输入您要预约的书籍编号:";
	string id;
	int temp;
	bool isexisted = false;
	std::cin >> id;
	for (int i = 0; i < book_num; i++) {
		if (book_information[i].book_number == id) {
			temp = i;
			isexisted = true;
			break;
		}
	}
	if (isexisted) {                                       //判断查找书籍是否存在
		if (book_information[temp].islended) {             //判断查找书籍是否已经被外借
			std::cout << "        此书籍处于外借状态,不可被预约!" << endl;
		}                                                  //判断是否需要预约             
		else if (book_information[temp].campus == this->campus) {
			std::cout << "        此书籍与您在同一校区,无需预约,可直接借阅!" << endl;
		}
		else {
			std::cout << endl << "        书籍名称为:" << book_information[temp].book_name << endl;
			std::cout << "        是否确认预约? Y/N:";
			char choice;
			std::cin >> choice;
			if (choice == 'Y') {
				std::cout << "        已成功申请预约,请注意查收书籍到达信息,并及时取书!" << endl;
				srand(time(NULL));                         //产生随机数
				int random = rand() % administrator_num;   //给编号为random的管理员派发任务
				ad_information[random].to_process_book[ad_information[random].to_do_num] =
					book_information[temp].book_number;
				ad_information[random].to_process_user[ad_information[random].to_do_num] =
					this->ID;
				ad_information[random].to_do_num++;        //增加管理员待办事项
				ad_information[random].news[ad_information[random].news_number] =
					get_time() + "您有一条预约申请待处理,请在半个工作日以内处理!";
				ad_information[random].news_number++;      //给管理员发送消息
			}
			else if (choice == 'N') {
				std::cout << "        您已取消预约!" << endl;
			}
		}
	}
	if (!isexisted) {
		std::cout << "        抱歉,未查询到此书籍!" << endl;
	}
	std::cout << "    ---------------********************************---------------" << endl;
	std::cout << "               --------************************--------           " << endl;
}

void User::borrowing() {                                   //借书函数实现
	welcome();
	std::cout << "               ------********* 办理借阅 *********------           " << endl;
	std::cout << "    ---------------********************************---------------" << endl;
	std::cout << endl;
	if (this->book_number >= lend_maxn) {
		std::cout << "        抱歉,您的借阅本数已超过最大限额,请先还书后再借阅!谢谢配合!" << endl;
	}
	else {
		std::cout << "        请输入书籍编号:";
		string id;
		cin >> id;
		bool isexisted = false;
		int temp;
		for (int i = 0; i < book_num; i++) {
			if (book_information[i].book_number == id) {
				temp = i;
				isexisted = true;
				break;
			}
		}
		if (isexisted) {                                   //判断查找书籍是否存在
			std::cout << endl << "        书籍名称:" << book_information[temp].book_name << endl;
			if (book_information[temp].islended)           //判断查找书籍是否已经外借
				std::cout << "        抱歉,此书已经外借!" << endl;
			else {                                         //判断是否需要预约
				if (book_information[temp].campus != this->campus)
					std::cout << "        此书不在您所在的校区,请先预约!" << endl;
				else {
					std::cout << "        是否确定借阅此书籍? Y/N :";
					char choice;
					std::cin >> choice;
					if (choice == 'Y') {
						std::cout << "        办理借阅成功!" << endl;
						book_information[temp].islended = true;
						book_information[temp].user_name = this->name;
						book_information[temp].user_ID = this->ID;
						book_information[temp].user_campus = this->campus;
						book_information[temp].lended_time++;

						this->book_name[book_number] = book_information[temp].book_name;
						this->book_id[book_number] = book_information[temp].book_number;
						this->book[book_number] =
							book_information[temp].book_name + "  "
							+ book_information[temp].book_number;
						this->book_number++;
						this->news[news_number] =
							get_time() + "  您已成功借阅书籍 " + book[book_number - 1]
							+ " ,请注意及时还书,谢谢!";
						this->news_number++;
						user_file_process();
						book_file_process();
					}
				}
			}
		}
		else {
			std::cout << "    抱歉,未查询到此书籍!" << endl;
		}
	}
	std::cout << endl;
	std::cout << "    ---------------********************************---------------" << endl;
	std::cout << "               ------****************************------           " << endl;
}

void User::returning() {                                   //还书函数实现
	welcome();
	std::cout << "               ------********* 办理还书 *********------           " << endl;
	std::cout << "    ---------------********************************---------------" << endl;
	std::cout << endl;
	std::cout << "        请输入书籍编号:";
	string id;
	std::cin >> id;
	int temp;
	bool islended = false;
	for (int i = 0; i < this->book_number; i++) {
		if (this->book_id[i] == id) {
			temp = i;
			islended = true;
			break;
		}
	}
	if (islended) {
		std::cout << "        还书成功!" << endl;
		this->news[this->news_number] = get_time() + "  您已交还书籍 " + this->book[temp] + "!";
		this->news_number++;
		for (int i = 0; i < book_num; i++) {
			if (book_information[i].book_number == this->book_id[temp]) {
				book_information[i].user_campus = book_information[i].user_ID
					= book_information[i].user_name = " - ";
				book_information[i].islended = false;
			}
		}
		for (int i = temp; i < this->book_number - 1; i++) {
			this->book[i] = this->book[i + 1];
			this->book_id[i] = this->book_id[i + 1];
			this->book_name[i] = this->book_name[i + 1];
		}
		this->book_number -= 1;
		user_file_process();
		book_file_process();
	}
	else {
		std::cout << "        您未借阅此书籍!" << endl;
	}
	std::cout << "    ---------------********************************---------------" << endl;
	std::cout << "               ------****************************------           " << endl;
}

void User::read_news() {                                   //查看收件箱函数实现
	welcome();
	std::cout << "               -------******* 查看收件箱 *******-------           " << endl;
	std::cout << "    ---------------********************************---------------" << endl;
	if (!news_number)
		std::cout << "        当前收件箱为空!" << endl;
	else {
		for (int i = 0; i < news_number; i++) {
			std::cout << "    " << i + 1 << "." << news[i] << endl;
		}
	}
	std::cout << "    ---------------********************************---------------" << endl;
	std::cout << "               --------************************--------           " << endl;
}

void User::clear_news() {                                  //清空收件箱函数实现
	welcome();
	std::cout << "               -------******* 清空收件箱 *******-------           " << endl;
	std::cout << "    ---------------********************************---------------" << endl;
	std::cout << "        清空后不可恢复,是否确定清空? Y/N:";
	char choice;
	std::cin >> choice;
	if (choice == 'Y') {
		std::cout << "        清空完毕!" << endl;
		news_number = 0;
	}
	else if (choice == 'N') {
		std::cout << "        取消清空!" << endl;
	}
	std::cout << "    ---------------********************************---------------" << endl;
	std::cout << "               --------************************--------           " << endl;
}

void User::end() {
	std::cout <<endl<< "    请按0返回用户主页,或按1返回登陆页面:";
	int type1;
	std::cin >> type1;
	if (type1 == 0) {
		cout << "    即将返回主页......" << endl;
		Sleep(1500);
		system("cls");
		this->start_menu();
	}
	else if(type1 == 1){
		cout << "    即将返回登陆页面......" << endl;
		Sleep(1500);
		system("cls");
		load();
	}
}

void User::reborrowing() {                                 //续借函数实现
	welcome();
	std::cout << "               ------********* 办理续借 *********------           " << endl;
	std::cout << "    ---------------********************************---------------" << endl;
	std::cout << endl;
	string id;
	bool islended = false;
	std::cout << "        请输入续借书籍编号:";
	std::cin >> id;
	for (int i = 0; i < book_number; i++) {
		if (book_id[i] == id) {
			islended = true;
			char choice;
			std::cout << "        是否确定续借此书籍? Y/N:";
			std::cin >> choice;
			if (choice == 'Y') {
				std::cout << "        办理续借成功!" << endl;
				this->news[news_number] =
					get_time() + "  您已成功续借书籍 " + book[book_number - 1]
					+ " ,请注意及时还书,谢谢!";
				this->news_number++;
			}
		}
	}
	if (!islended) {
		cout << "        您未借阅此书籍,无法续借!" << endl;
	}
	std::cout << "    ---------------********************************---------------" << endl;
	std::cout << "               ------****************************------           " << endl;
}

void User::start_menu() {                                  //用户主页函数实现
	//此处考虑清屏衔接!!!!!!!
	welcome();
	std::cout << "             ------******* 用户 " << this->name << ",您好!*******------" << endl << endl;
	std::cout << "    $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$    " << endl;
	std::cout << "    $$                                                          $$    " << endl;
	std::cout << "    $$                 借         书           1                $$    " << endl;
	std::cout << "    $$                                                          $$    " << endl;
	std::cout << "    $$                 还         书           2                $$    " << endl;
	std::cout << "    $$                                                          $$    " << endl;
	std::cout << "    $$                 续         借           3                $$    " << endl;
	std::cout << "    $$                                                          $$    " << endl;
	std::cout << "    $$                 预         约           4                $$    " << endl;
	std::cout << "    $$                                                          $$    " << endl;
	std::cout << "    $$               查 询 书 籍 信 息         5                $$    " << endl;
	std::cout << "    $$                                                          $$    " << endl;
	std::cout << "    $$               查 询 用 户 信 息         6                $$    " << endl;
	std::cout << "    $$                                                          $$    " << endl;
	std::cout << "    $$                查 看 收 件 箱           7                $$    " << endl;
	std::cout << "    $$                                                          $$    " << endl;
	std::cout << "    $$                清 空 收 件 箱           8                $$    " << endl;
	std::cout << "    $$                                                          $$    " << endl;
	std::cout << "    $$                 退         出           9                $$    " << endl;
	std::cout << "    $$                                                          $$    " << endl;
	std::cout << "    $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$    " << endl;
	std::cout << endl;
	int type3;
	std::cout << "    请选择操作类型:";
	std::cin >> type3;
	switch (type3) {
	case 1: {
		std::cout << "    请稍候......" << endl;
		Sleep(1500);
		system("cls");
		this->borrowing();
		this->end();
		break;
	}
	case 2: {
		std::cout << "    请稍候......" << endl;
		Sleep(1500);
		system("cls");
		this->returning();
		this->end();
		break;
	}
	case 3: {
		std::cout << "    请稍候......" << endl;
		Sleep(1500);
		system("cls");
		this->reborrowing();
		this->end();
		break;
	}
	case 4: {
		std::cout << "    请稍候......" << endl;
		Sleep(1500);
		system("cls");
		this->appointing();
		this->end();
		break;
	}
	case 5: {
		std::cout << "    请稍候......" << endl;
		Sleep(1500);
		system("cls");
		this->find();
		this->end();
		break;
	}
	case 6: {
		std::cout << "    请稍候......" << endl;
		Sleep(1500);
		system("cls");
		this->querying();
		this->end();
		break;
	}
	case 7: {
		std::cout << "    请稍候......" << endl;
		Sleep(1500);
		system("cls");
		this->read_news();
		this->end();
		break;
	}
	case 8: {
		std::cout << "    请稍候......" << endl;
		Sleep(1500);
		system("cls");
		this->clear_news();
		this->end();
	}
	case 9: {
		std::cout << "        即将返回主页......";
		Sleep(1500);
		system("cls");
		load();
	}
	}
}


//Administrator类
void Administrator::add_book() {                           //新增书籍函数实现
	welcome();
	std::cout << "               -------****** 新增书籍入库 ******-------           " << endl;
	std::cout << "    ---------------********************************---------------" << endl;
	std::cout << endl;
	Book b;
	std::cout << "        请输入以下书籍信息:" << endl << endl;
	std::cout << "        书籍名称:";
	std::cin >> b.book_name;
	std::cout << "        书籍编号:";
	std::cin >> b.book_number;
	std::cout << "        所在校区:";
	std::cin >> b.campus;
	std::cout << "        书籍类别:";
	std::cin >> b.classification;
	std::cout << "        出版社:";
	std::cin >> b.press;
	book_information.push_back(b);
	book_num++;
	std::cout << "        新增书籍入库成功!" << endl;
	std::cout << "    ---------------********************************---------------" << endl;
	std::cout << "               ------****************************------           " << endl;
	book_file_process();
}

void Administrator::read_news() {                          //查看收件箱函数实现
	welcome();
	std::cout << "               -------******* 查看收件箱 *******-------           " << endl;
	std::cout << "    ---------------********************************---------------" << endl;
	std::cout << endl;
	if (!news_number)
		std::cout << "        当前收件箱为空!" << endl;
	else {
		for (int i = 0; i < news_number; i++) {
			std::cout << "    " << i + 1 << "." << news[i] << endl;
		}
	}
	std::cout << "    ---------------********************************---------------" << endl;
	std::cout << "               --------************************--------           " << endl;
}

void Administrator::clear_news() {                         //清空收件箱函数实现
	welcome();
	std::cout << "               -------******* 清空收件箱 *******-------           " << endl;
	std::cout << "    ---------------********************************---------------" << endl;
	std::cout << endl;
	std::cout << "        清空后不可恢复,是否确定清空? Y/N:";
	char choice;
	std::cin >> choice;
	if (choice == 'Y') {
		std::cout << "        清空完毕!" << endl;
		news_number = 0;
	}
	else if (choice == 'N') {
		std::cout << "        取消清空!" << endl;
	}
	std::cout << "    ---------------********************************---------------" << endl;
	std::cout << "               --------************************--------           " << endl;
}

void Administrator::find() {                               //书籍信息查询函数实现
	welcome();
	std::cout << "               -------****** 查找书籍信息 ******-------           " << endl;
	std::cout << "    ---------------********************************---------------" << endl;
	std::cout << endl;
	std::cout << "        请输入书籍编号:";
	string id;
	std::cin >> id;
	bool isexisted = false;
	for (int i = 0; i < book_num; i++) {
		if (book_information[i].book_number == id) {
			isexisted = true;
			std::cout << "    " << left << setw(25) << "书籍名称" << left << setw(15) << "书籍编号" << left << setw(15) << "所在校区"
				<< left << setw(15) << "书籍类别" << left << setw(25) << "出版社" << left << setw(10) << "是否外借"
				<< left << setw(20) << "借阅者姓名" << left << setw(20) << "借阅者学号" << left << setw(20) << "借阅者所在校区" << endl;
			break;
		}
	}
	if (isexisted) {
		for (int i = 0; i < book_num; i++) {
			if (book_information[i].book_number == id) {
				std::cout << "    " << left << setw(25) << book_information[i].book_name << left << setw(15)
					<< book_information[i].book_number << left << setw(15) << book_information[i].campus
					<< left << setw(15) << book_information[i].classification << left << setw(25) << book_information[i].press;
				if (book_information[i].islended) {
					std::cout << left << setw(10) << "  是";
				}
				else {
					std::cout << left << setw(10) << "  否";
				}
				std::cout << left << setw(20) << book_information[i].user_name << left << setw(20) << book_information[i].user_ID
					<< left << setw(20) << book_information[i].user_campus << endl;
			}
		}
	}
	else {
		std::cout << "    " << "抱歉,未查询到此书籍!" << endl;
	}
	std::cout << "    ---------------********************************---------------" << endl;
	std::cout << "               ------****************************------           " << endl;
}

void Administrator::querying() {                           //查询用户信息函数实现
	welcome();
	std::cout << "               -------****** 查找用户信息 ******-------           " << endl;
	std::cout << "    ---------------********************************---------------" << endl;
	std::cout << endl;
	std::cout << "        请输入用户学号:";
	string id;
	std::cin >> id;
	int temp;
	bool isexisted = false;
	for (int i = 0; i < user_num; i++) {
		if (user_information[i].ID == id) {
			temp = i;
			isexisted = true;
			break;
		}
	}
	if (isexisted) {
		this->operator<<(user_information[temp]);          //调用运算符重载函数
	}
	else {
		std::cout << "        查无此人!" << endl;
	}
	std::cout << "    ---------------********************************---------------" << endl;
	std::cout << "               --------************************--------           " << endl;
}

void Administrator::process_appoingting() {                //处理预约函数实现
	welcome();
	std::cout << "               -------****** 处理预约事项 ******-------           " << endl;
	std::cout << "    ---------------********************************---------------" << endl;
	std::cout << endl;
	if (!this->to_do_num) {
		std::cout << "        当前暂无待处理事项!" << endl;
	}
	else {
		std::cout << "        当前有" << to_do_num << "件待处理事项:" << endl;
		std::cout << "        " << setw(15) << "书籍编号" << setw(15) << "用户学号" << endl;
		for (int i = 0; i < this->to_do_num; i++) {
			std::cout << "     " << i + 1 << ". " << setw(15) << this->to_process_book[i] <<
				setw(15) << this->to_process_user[i] << endl;
		}
		std::cout << "        请审核并确认无误后批准申请!" << endl;
		std::cout << endl << "        是否全部批准? Y/N:";
		char choice;
		std::cin >> choice;
		if (choice == 'Y') {
			std::cout << endl << "        您已完成待办事项!" << endl;
			for (int i = 0; i < this->to_do_num; i++) {
				int temp1, temp2;
				for (int j = 0; j < user_num; j++) {
					if (user_information[j].ID == this->to_process_user[i])
						temp1 = j;
				}
				for (int k = 0; k < book_num; k++) {
					if (book_information[k].book_number == to_process_book[i])
						temp2 = k;
				}                                          //修改预约书籍和申请者的部分信息
				book_information[temp2].campus = user_information[temp1].campus;
				book_information[temp2].user_campus = user_information[temp1].campus;
				book_information[temp2].user_ID = user_information[temp1].ID;
				book_information[temp2].user_name = user_information[temp1].name;
				book_information[temp2].islended = true;
				book_information[temp2].lended_time++;
				user_information[temp1].book_id[user_information[temp1].book_number] =
					book_information[temp2].book_number;
				user_information[temp1].book_name[user_information[temp1].book_number] =
					book_information[temp2].book_name;

				user_information[temp1].book[user_information[temp1].book_number] =
					book_information[temp2].book_name + "  " + book_information[temp2].book_number;
				user_information[temp1].book_number++;
				user_information[temp1].news[user_information[temp1].news_number] =
					get_time() + "  您预约的书籍 " + book_information[temp2].book_name
					+ " 已经到达您所在校区,请及时取书!";
				user_information[temp1].news_number++;

				user_file_process();
				book_file_process();
			}
		}
		else if (choice == 'N') {
			std::cout << "        未完成待处理事项!" << endl;
		}
	}
	std::cout << "    ---------------********************************---------------" << endl;
	std::cout << "               --------************************--------           " << endl;
}

void Administrator::operator<<(const User& u) {            //运算符重载函数实现
	std::cout << endl;
	std::cout << "        姓名:" << u.name << endl;
	std::cout << "        学号:" << u.ID << endl;
	std::cout << "        学院:" << u.institute << endl;
	std::cout << "        校区:" << u.campus << endl;
	std::cout << "        在借图书:";
	if (!u.book_number) {
		std::cout << "当前无在借图书!" << endl;
	}
	else {
		std::cout << endl;
		for (int i = 0; i < u.book_number; i++) {
			std::cout << "                " << i + 1 << "." << u.book[i] << endl;
		}
	}
}

void Administrator::start_menu() {                         //管理员主页函数实现
	//此处考虑清屏衔接!!!!!!!
	welcome();
	std::cout << "             ------****** 管理员 " << this->name << ",您好!******------" << endl << endl;
	std::cout << "    $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$    " << endl;
	std::cout << "    $$                                                          $$    " << endl;
	std::cout << "    $$               新 增 书 籍 入 库         1                $$    " << endl;
	std::cout << "    $$                                                          $$    " << endl;
	std::cout << "    $$               处 理 预 约 事 项         2                $$    " << endl;
	std::cout << "    $$                                                          $$    " << endl;
	std::cout << "    $$               查 询 书 籍 信 息         3                $$    " << endl;
	std::cout << "    $$                                                          $$    " << endl;
	std::cout << "    $$               查 询 用 户 信 息         4                $$    " << endl;
	std::cout << "    $$                                                          $$    " << endl;
	std::cout << "    $$                查 看 收 件 箱           5                $$    " << endl;
	std::cout << "    $$                                                          $$    " << endl;
	std::cout << "    $$                清 空 收 件 箱           6                $$    " << endl;
	std::cout << "    $$                                                          $$    " << endl;
	std::cout << "    $$                退          出           7                $$    " << endl;
	std::cout << "    $$                                                          $$    " << endl;
	std::cout << "    $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$    " << endl;
	std::cout << endl;
	int type;
	std::cout << "    请选择操作类型:";
	std::cin >> type;
	switch (type) {
	case 1: {
		std::cout << "    请稍候......" << endl;
		Sleep(1500);
		system("cls");
		this->add_book();
		this->end();
		break;
	}
	case 2: {
		std::cout << "    请稍候......" << endl;
		Sleep(1500);
		system("cls");
		this->process_appoingting();
		this->end();
		break;
	}
	case 3: {
		std::cout << "    请稍候......" << endl;
		Sleep(1500);
		system("cls");
		this->find();
		this->end();
		break;
	}
	case 4: {
		std::cout << "    请稍候......" << endl;
		Sleep(1500);
		system("cls");
		this->querying();
		this->end();
		break;
	}
	case 5: {
		std::cout << "    请稍候......" << endl;
		Sleep(1500);
		system("cls");
		this->read_news();
		this->end();
		break;
	}
	case 6: {
		std::cout << "    请稍候......" << endl;
		Sleep(1500);
		system("cls");
		this->clear_news();
		this->end();
		break;
	}
	case 7: {
		std::cout << "        即将返回主页......";
		Sleep(1500);
		system("cls");
		load();
	}
	}
}

void Administrator::end() {
	std::cout << "    请按0返回管理员主页,或按1返回登录界面:";
	int type1;
	std::cin >> type1;
	if (type1 == 0) {
		cout << "    即将返回主页......" << endl;
		Sleep(1500);
		system("cls");
		this->start_menu();
	}
	else if(type1 == 1){
		cout << "    即将返回登陆页面......" << endl;
		Sleep(1500);
		system("cls");
		load();
	}
}

//Manager类

void Manager::querying() {                                 //查询用户信息函数实现
	welcome();
	std::cout << "               -------****** 查找用户信息 ******-------           " << endl;
	std::cout << "    ---------------********************************---------------" << endl;
	std::cout << endl;
	std::cout << "        请输入用户学号:";
	string id;
	std::cin >> id;
	int temp;
	bool isexisted = false;
	for (int i = 0; i < user_num; i++) {
		if (user_information[i].ID == id) {
			temp = i;
			isexisted = true;
			break;
		}
	}
	if (isexisted) {
		std::cout << endl;
		std::cout << "        姓名:" << user_information[temp].name << endl;
		std::cout << "        学号:" << user_information[temp].ID << endl;
		std::cout << "        学院:" << user_information[temp].institute << endl;
		std::cout << "        校区:" << user_information[temp].campus << endl;
		std::cout << "        在借图书:";
		if (!user_information[temp].book_number) {
			std::cout << "当前无在借图书!" << endl;
		}
		else {
			std::cout << endl;
			for (int i = 0; i < user_information[temp].book_number; i++) {
				std::cout << "                " << i + 1 << "." << user_information[temp].book[i] << endl;
			}
		}
	}
	else {
		std::cout << "        查无此人!" << endl;
	}
	std::cout << "    ---------------********************************---------------" << endl;
	std::cout << "               --------************************--------           " << endl;
}

void Manager::add_admin() {                                //新增管理员函数实现
	welcome();
	std::cout << "               --------****** 新增管理员 ******--------           " << endl;
	std::cout << "    ---------------********************************---------------" << endl;
	std::cout << endl;
	Administrator a;
	std::cout << "        请输入管理员姓名:";
	std::cin >> a.name;
	std::cout << "        请输入管理员工号:";
	std::cin >> a.ID;
	std::cout << "        确定新增该管理员? Y/N:";
	char choice;
	cin >> choice;
	if (choice == 'Y') {
		std::cout << "        新增管理员成功!" << endl;
		ad_information.push_back(a);
		ad_information[administrator_num].news[ad_information[administrator_num].news_number] =
			get_time() + "  您已成为中山大学图书借阅系统管理员!欢迎您的加入!";
		ad_information[administrator_num].news_number++;
		administrator_num++;
		admin_file_process();
	}
	else if (choice == 'N') {
		std::cout << "        已取消新增管理员!" << endl;
	}
	std::cout << "    ---------------********************************---------------" << endl;
	std::cout << "               --------************************--------           " << endl;
}

void Manager::find() {                                     //书籍信息查询函数实现
	welcome();
	std::cout << "               -------****** 查找书籍信息 ******-------           " << endl;
	std::cout << "    ---------------********************************---------------" << endl;
	std::cout << endl;
	std::cout << "        请输入书籍编号:";
	string id;
	std::cin >> id;
	bool isexisted = false;
	for (int i = 0; i < book_num; i++) {
		if (book_information[i].book_number == id) {
			isexisted = true;
			std::cout << "    " << setw(25) << "书籍名称" << setw(15) << "书籍编号" << setw(15) << "所在校区"
				<< setw(15) << "书籍类别" << setw(25) << "出版社" << setw(10) << "是否外借" << setw(20)
				<< "借阅者姓名" << setw(20) << "借阅者学号" << setw(20) << "借阅者所在校区" << endl;
			break;
		}
	}
	if (isexisted) {
		for (int i = 0; i < book_num; i++) {
			if (book_information[i].book_number == id) {
				std::cout << "    " << setw(25) << book_information[i].book_name << setw(15)
					<< book_information[i].book_number << setw(15) << book_information[i].campus
					<< setw(15) << book_information[i].classification << setw(25) << book_information[i].press;
				if (book_information[i].islended)
					std::cout << setw(10) << "  是" << endl;
				else
					std::cout << setw(10) << "  否" << endl;
			}
		}
	}
	else {
		std::cout << "    " << "抱歉,未查询到此书籍!" << endl;
	}
	std::cout << "    ---------------********************************---------------" << endl;
	std::cout << "               --------************************--------           " << endl;
}

void Manager::find_admin() {                               //查找管理员函数实现
	welcome();
	std::cout << "               -------***** 查找管理员信息 *****-------           " << endl;
	std::cout << "    ---------------********************************---------------" << endl;
	std::cout << endl;
	std::cout << "        请输入管理员工号:";
	string id;
	cin >> id;
	int temp;
	bool isexisted = false;
	for (int i = 0; i < administrator_num; i++) {
		if (ad_information[i].ID == id) {
			temp = i;
			isexisted = true;
			break;
		}
	}
	if (isexisted) {
		std::cout << "        " << setw(15) << "工号" << setw(15) << "姓名" << endl;
		std::cout << "        " << setw(15) << ad_information[temp].ID << setw(15)
			<< ad_information[temp].name << endl;
	}
	else {
		std::cout << "        查无此人!" << endl;
	}
	std::cout << "    ---------------********************************---------------" << endl;
	std::cout << "               --------************************--------           " << endl;
}

void Manager::start_menu() {                               //主管主页函数实现
	//此处考虑清屏衔接!!!!!!!
	welcome();
	std::cout << "             ------******* 主管 " << this->name << ",您好!*******------" << endl << endl;
	std::cout << "    $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$    " << endl;
	std::cout << "    $$                                                          $$    " << endl;
	std::cout << "    $$               新 增 书 籍 入 库         1                $$    " << endl;
	std::cout << "    $$                                                          $$    " << endl;
	std::cout << "    $$               查 询 书 籍 信 息         2                $$    " << endl;
	std::cout << "    $$                                                          $$    " << endl;
	std::cout << "    $$               查 询 用 户 信 息         3                $$    " << endl;
	std::cout << "    $$                                                          $$    " << endl;
	std::cout << "    $$              查 询 管 理 员 信 息       4                $$    " << endl;
	std::cout << "    $$                                                          $$    " << endl;
	std::cout << "    $$                新 增 管 理 员           5                $$    " << endl;
	std::cout << "    $$                                                          $$    " << endl;
	std::cout << "    $$                退          出           6                $$    " << endl;
	std::cout << "    $$                                                          $$    " << endl;
	std::cout << "    $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$    " << endl;
	std::cout << endl;

	int type2;
	std::cout << "    请选择操作类型:";
	std::cin >> type2;
	switch (type2) {
	case 1: {
		std::cout << "    请稍候......" << endl;
		Sleep(1500);
		system("cls");
		this->add_book();
		this->end();
		break;
	}
	case 2: {
		std::cout << "    请稍候......" << endl;
		Sleep(1500);
		system("cls");
		this->find();
		this->end();
		break;
	}
	case 3: {
		std::cout << "    请稍候......" << endl;
		Sleep(1500);
		system("cls");
		this->querying();
		this->end();
		break;
	}
	case 4: {
		std::cout << "    请稍候......" << endl;
		Sleep(1500);
		system("cls");
		this->find_admin();
		this->end();
		break;
	}
	case 5: {
		system("cls");
		this->add_admin();
		this->end();
		break;
	}
	case 6: {
		std::cout << "    请稍候......" << endl;
		Sleep(1500);
		std::cout << "        即将返回主页......";
		Sleep(1500);
		system("cls");
		load();
	}
	}
}

void Manager::end() {                                      //主管结束操作函数实现
	std::cout << "    请按0返回主管主页,或按1返回登录界面:";
	int type1;
	std::cin >> type1;
	if (type1 == 0) {
		cout << "    即将返回主页......" << endl;
		Sleep(1500);
		system("cls");
		this->start_menu();
	}
	else if (type1 == 1) {
		cout << "    即将返回登陆界面......";
		Sleep(1500);
		system("cls");
		load();
	}
}

#endif

// LibraryManagement.cpp

#include<iostream>
using namespace std;
#include"FunctionRealization.h"
#include"ClassFunctionRealization.h"

int main() {
	initialize();
	load();
	return 0;
}

程序评价

本程序实现了图书借阅系统的基本功能,但仍然有很多可以改进的地方,以下是作者认为程序仍存的缺陷,今后有机会的话会继续完善:

  • 程序无记忆性,一旦打开就不能关闭,否则所有操作记录均会被清空,系统回到初始状态
  • 需要手动输入图书或用户信息进行借阅、还书、预约等操作,无法做到自动化识别
  • 账户一旦注册不可注销,导致用户数量只增不减
  • 没能实现到期提醒功能
  • 续借次数不限
  • 不能识别应还日期

总结

学有所得,甚为欢喜 ~~
😀😆

  C++知识库 最新文章
【C++】友元、嵌套类、异常、RTTI、类型转换
通讯录的思路与实现(C语言)
C++PrimerPlus 第七章 函数-C++的编程模块(
Problem C: 算法9-9~9-12:平衡二叉树的基本
MSVC C++ UTF-8编程
C++进阶 多态原理
简单string类c++实现
我的年度总结
【C语言】以深厚地基筑伟岸高楼-基础篇(六
c语言常见错误合集
上一篇文章      下一篇文章      查看所有文章
加:2021-07-23 10:32:07  更:2021-07-23 10:33:42 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年4日历 -2024/4/28 5:04:06-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码