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;
const int news_maxn = 1000;
class Person {
public:
Person() {
password = "12345678";
}
string name;
string ID;
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;
news_number = 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;
news_number = 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
#define user_maxn 100000
#define day_maxn 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;
static int administrator_num = 3;
static int user_num = 5;
static int manager_num = 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"
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();
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') {
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);
system("cls");
start_menu(&user_information[temp]);
}
}
if (id[0] == '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);
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);
system("cls");
start_menu(&ad_information[temp]);
}
}
if (id[0] == '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);
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"
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;
}
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;
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();
}
}
}
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();
}
}
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;
}
程序评价
本程序实现了图书借阅系统的基本功能,但仍然有很多可以改进的地方,以下是作者认为程序仍存的缺陷,今后有机会的话会继续完善:
- 程序无记忆性,一旦打开就不能关闭,否则所有操作记录均会被清空,系统回到初始状态
- 需要手动输入图书或用户信息进行借阅、还书、预约等操作,无法做到自动化识别
- 账户一旦注册不可注销,导致用户数量只增不减
- 没能实现到期提醒功能
- 续借次数不限
- 不能识别应还日期
总结
学有所得,甚为欢喜 ~~ 😀😆
|