C++自编图书借阅系统

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

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

  • C++自编图书借阅系统
    • 主要功能简介
    • 程序代码
      • 代码简介
      • 源代码
      • 程序评价
    • 总结

主要功能简介

此系统主要面向读者用户、管理员、主管三种使用者,通过账号识别使用者身份(用户账号以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;          //初始借阅数目为0news_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;            //初始待办事项数目为0news_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;           //系统初始总管数目为1vector<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;elsestd::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;elsestd::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;elsestd::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;elsestd::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++自编图书借阅系统相关推荐

  1. [内附完整源码和文档] 基于ThinkPhp框架的高校图书馆藏书借阅系统

    二.功能设计 2.1 数据库设计 2.1.1 需求分析 (1)系统任务 我们所要做的是一个高校图书馆藏书借阅系统,用于读者对图书的检索.浏览.借阅.因此,需要的功能包括对图书的检索查询.借阅.预约.续 ...

  2. 4.2 图书借阅系统数据库设计 --MySQL

    本文目录 前言 一.背景和需求分析 1.1 背景 1.2 信息需求 1.3 功能需求 管理员 学生 1.4 数据流图 二.概念结构设计 1. 抽象出系统实体 2. 局部E-R图 2.1 学生 E-R图 ...

  3. C网络编程项目 图书借阅系统(一)

    1.项目名称 图书借阅系统 2.项目需求 对于图书馆中的书籍信息的管理,可以增.删.改.查书籍的信息,完成借阅.归还书籍的要求. 3.项目功能 1.采用并发服务器,可以同时处理多个客户端的请求. 2. ...

  4. 图书借阅java设计报告_JAVA课程设计报告图书借阅系统.pdf

    课 程 设 计 课程设计名称: java课程设计 专 业 班 级 : 计科10 级4 班 学 生 姓 名 : 学 号 : 指 导 教 师 : 课程设计时间: 2012.6.18-2012.6.30 计 ...

  5. 数据库课程设计:图书借阅系统(Java+MySQL)

    应粉丝要求,出个借阅系统swing版的,时间有些赶,可能还存在一些bug,不过不要紧,发现bug提给我,我逐个去修复与完善程序. 问题描述 实现简易版图书借阅管理系统,学生(读者)在系统里可以检索图书 ...

  6. C++通过ODBC方式连接数据库SQLServer及增删查改操作【图书借阅系统为例】

    C++通过ODBC方式连接数据库SQLServer及增删查改操作[图书借阅系统为例] 文章目录 前言 一.ODBC如何配置 二.SQL Server如何设置账号密码 三.C++连接数据库以及增删查改操 ...

  7. 微信小程序之图书借阅系统(含源码+论文+答辩PPT等)

    项目功能简介: 该项目含有源码.论文等资料.配套开发软件.软件安装教程.项目发布教程等 本系统包含微信小程序做的图书借阅系统和Java做的后台管理系统: 微信小程序--图书借阅系统前台涉及技术:WXM ...

  8. C语言数据结构应用(图书借阅系统)

    C语言数据结构应用(图书借阅系统) /****************************************************@title: 数据结构实验@name: <实验2- ...

  9. Java——图书借阅系统

    ** 项目需求: ** 为图书阅览室开发一个图书借阅系统,最多可存50本书,实现图书的管理.图书借阅系统具备以下功能: 1.查看图书信息 菜单选择查看功能,展示当前所有图书的相关信息,效果如下. ca ...

  10. 计算机毕业设计Android图书馆借阅系统app(源码+系统+mysql数据库+Lw文档)

    项目介绍 目前,大多数基于Android平台的移动图书馆的主要功能集成了传统的馆藏图书查询.图书预约.图书续借等功能,较好地满足了人们随时随地访问图书馆的需要.但是,整个图书系统仍处在初期阶段,仍存在 ...

最新文章

  1. DevExpress控件使用系列--ASPxUploadControl(图片上传及预览)
  2. tensorflow实践
  3. Apache shutdown unexpectedly启动错误解决方法
  4. idea导入java项目类上面显示红色的J符号解决办法
  5. android弹窗设计,想印:UI设计中弹窗设计的五条基本原则
  6. 新工作上班九天心得(附 bootstrap分页写法)
  7. [Python] Request module
  8. C语言 牛顿法 解方程,如何用科学计算器求方程的解(牛顿法解方程具体步骤)...
  9. 红外解码--基于1838红外接收头
  10. 海康大华等录像机、摄像头无法通过GB28181注册到LiveGBS国标平台问题排查方法
  11. 产品经理如何写好一份简历
  12. python、变量命名中字母不区分大小写_python变量名不区分大小写吗
  13. HDU-1556题解
  14. win10 自带卸载流氓软件工具
  15. Tomcat配置HTPPS访问
  16. oracle awr 里的socket,AWR 报告中CPUs Cores 和 Sockets 说明
  17. 戴尔笔记本电脑怎下载c语言,戴尔笔记本电脑如何下载驱动
  18. SpringCloud Tencent 全套解决方案
  19. 教你如何学习思维导图
  20. 编程编辑器推荐(编程常用编辑器的横向对比)

热门文章

  1. 模拟电子技术基础笔记(2)——半导体基础知识
  2. 28款数据恢复软件对比测试
  3. 获取窗口句柄 c语言,VC++编程获取窗口句柄的方法小结分享
  4. php smarty安装,smarty安装(PHP)
  5. html 自动执行vbs代码,vbs脚本教程 怎样在bat脚本中调用vbs脚本
  6. 思科最模拟器Cisco Packet Tracer 7.3.0安装配置
  7. Weblogic 部署两个应用
  8. 计算机王码简历,王码五笔字型发明人王永民回首汉字输入这30年
  9. python爬取豆瓣书籍_Python爬取豆瓣读书
  10. js JavaScript实战练习——小球碰撞反弹(详细)