图书管理系统C++
不知道有学程序设计的小伙伴们有遇到过“图书管理系统”这个期末大作业,这里我将奉上我自己的写的
水平太差写的不好,希望能给大家作为参考,也希望能给那些没有思路和感到害怕的小伙伴一点点的灵感
我这里用的是vscode,个人感觉vscode比较好用,如果有关于vscode多文件编程有问题的小伙伴,我有写过教程的哟,最简单的方法
pass_in.h
#pragma once
#include <algorithm>
#include <conio.h>
#include <cstring>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <time.h>
#include <vector>
#include <map>
#include <windows.h>
#define int long long
using namespace std;
void pass_in(string &password) //密码输入函数
{
int index = 0;
while (1)
{
char ch;
ch = getch();//录入键盘输入的字符但不显示在屏幕上<conio.h>
if (ch == 8) //退格键
{
if (index != 0)
{
cout << char(8) << " " << char(8);//将最后一个字符替换为空在退格,直接退格会出错
password.pop_back();
index--;
}
}
else if (ch == '\r') //回车键
{
cout << endl;
break;
}
else
{
cout << "*";//返回掩码
password.push_back(ch);
index++;
}
}
// cout << "password:" << password << endl;
}
这个头文件主要是实现了密码输入时返回掩码的一个操作
Book.h
#pragma once
#include <algorithm>
#include <conio.h>
#include <cstring>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <time.h>
#include <vector>
#include <map>
#include <windows.h>
#include "pass_in.h"
#define int long long
using namespace std;
class Book
{
protected:
int Sernum; //编号
string BookName; //书名
string ISBN; //ISBM码
string Author; //作者
string NO; //编号 为实现三级查找
string NO1;
string NO2;
string NO3;
int NUM; //数量
public:
Book(); //初始化图书
Book(int, string, string, string, string, string, string, string, int); //初始化
Book ©(int, string, string, string, string, string, string, string, int);
int getNUM() const; //返回NUM的接口
string getBookName() const; //返回名字
string getISBN() const; //返回ISBN
string getAuthor() const; //返回作者
string getNO1() const; //返回一级分类号
string getNO2() const; //返回二级分类号
string getNO3() const; //返回三级分类号
string getNO() const; //返回剩余分类号
int getSernum() const; //返回图书数目
void NUMreduce(); //NUM--
void NUMplus(); //NUM++
void NUMpplus(int); //NUM+n
Book &book_change(const Book &); //改变信息
friend void Read_Book(map<string, map<string, map<string, map<string, Book>>>> &, const string);
//书本信息录入 采用map效率更高,小伙伴们也可以尝试map嵌套vector哦,或者multimap也是不错的选择
friend void Write_Book(map<string, map<string, map<string, map<string, Book>>>> &, const string); //书本排序并输出
friend void FindBookName(string, map<string, map<string, map<string, map<string, Book>>>> &); //名字搜索图书
friend void FindBookISBN(string, map<string, map<string, map<string, map<string, Book>>>> &); //ISBN码值搜索图书
friend void FindBookAuthor(string, map<string, map<string, map<string, map<string, Book>>>> &); //作者搜索图书
friend void FindBookNO1(string, map<string, map<string, map<string, map<string, Book>>>> &); //一级分类搜索图书
friend void FindBookNO2(string, string, map<string, map<string, map<string, map<string, Book>>>> &); //二级分类搜索图书
friend void FindBookNO3(string, string, string, map<string, map<string, map<string, map<string, Book>>>> &); //三级分类搜索图书
Book(const Book &); //复制函数
friend istream &operator>>(istream &, Book &); //输入函数
friend ostream &operator<<(ostream &, const Book &); //输出函数
};
Book::Book() //初始化图书为(0)
{
Sernum = 0;
BookName = "0";
ISBN = "0";
Author = "0";
NO1 = "0";
NO2 = "0";
NO3 = "0";
NO = "0";
NUM = 0;
}
Book::Book(int S, string n, string I, string a, string no1, string no2, string no3, string no, int num)//复制构造函数
{
Sernum = S;
BookName = n;
ISBN = I;
Author = a;
NO = no;
NO1 = no1;
NO2 = no2;
NO3 = no3;
NUM = num;
}
Book &Book::copy(int S, string n, string I, string a, string no1, string no2, string no3, string no, int num)//嗯。。这个忘了有没有用了,没有调用的话可以删掉
{
this->Sernum = S;
this->BookName = n;
this->ISBN = I;
this->Author = a;
this->NO1 = no1;
this->NO2 = no2;
this->NO3 = no3;
this->NO = no;
this->NUM = num;
return *this;
}
int Book::getNUM() const //返回NUM的接口
{
return NUM;
}
string Book::getBookName() const
{
return BookName;
}
string Book::getAuthor() const
{
return Author;
}
string Book::getISBN() const
{
return ISBN;
}
string Book::getNO1() const
{
return NO1;
}
string Book::getNO2() const
{
return NO2;
}
string Book::getNO3() const
{
return NO3;
}
string Book::getNO() const
{
return NO;
}
int Book::getSernum() const
{
return Sernum;
}
void Book::NUMreduce() //NUM-- 用于借书
{
this->NUM = this->NUM - 1;
}
void Book::NUMplus() //NUM++ 用于还书
{
this->NUM = this->NUM + 1;
}
void Book::NUMpplus(int n) //NUM+n 用于管理员添加书籍
{
this->NUM = this->NUM + n;
}
Book &Book::book_change(const Book &B) //改变信息
{
this->BookName = B.BookName;
this->ISBN = B.ISBN;
this->Author = B.Author;
this->NO1 = B.NO1;
this->NO2 = B.NO2;
this->NO3 = B.NO3;
this->NO = B.NO;
this->NUM = B.NUM;
return *this;
}
void Read_Book(map<string, map<string, map<string, map<string, Book>>>> &B, const string file) //录入图书信息
{
Book tb;
ifstream fin(file);
if (!fin)
{
cout << "图书录入错误!" << endl;
return;
}
while (!fin.eof())
{
fin >> tb.Sernum >> tb.BookName >> tb.ISBN >> tb.Author >> tb.NO1 >> tb.NO2 >> tb.NO3 >> tb.NO >> tb.NUM;
B[tb.NO1][tb.NO2][tb.NO3][tb.NO] = tb;
}
fin.close();
}
void Write_Book(map<string, map<string, map<string, map<string, Book>>>> &B, const string file) //将vector中的图书排序并输出
{
ofstream fout(file);
int index = 0;
for (map<string, map<string, map<string, map<string, Book>>>>::iterator i = B.begin(); i != B.end(); i++)
{
for (map<string, map<string, map<string, Book>>>::iterator i1 = i->second.begin(); i1 != i->second.end(); i1++)
{
for (map<string, map<string, Book>>::iterator i2 = i1->second.begin(); i2 != i1->second.end(); i2++)
{
for (map<string, Book>::iterator i3 = i2->second.begin(); i3 != i2->second.end(); i3++)
{
fout << ++index << " " << i3->second << endl;
}
}
}
}
fout.close();
}
void FindBookName(string key, map<string, map<string, map<string, map<string, Book>>>> &Books) //名字搜索图书
{
for (map<string, map<string, map<string, map<string, Book>>>>::iterator i = Books.begin(); i != Books.end(); i++)
{
for (map<string, map<string, map<string, Book>>>::iterator i1 = i->second.begin(); i1 != i->second.end(); i1++)
{
for (map<string, map<string, Book>>::iterator i2 = i1->second.begin(); i2 != i1->second.end(); i2++)
{
for (map<string, Book>::iterator i3 = i2->second.begin(); i3 != i2->second.end(); i3++)
{
if (i3->second.getBookName() == key)
{
cout << i3->second.getSernum() << " " << i3->second << endl;
}
}
}
}
}
}
void FindBookISBN(string key, map<string, map<string, map<string, map<string, Book>>>> &Books) //ISBN码值搜索图书
{
for (map<string, map<string, map<string, map<string, Book>>>>::iterator i = Books.begin(); i != Books.end(); i++)
{
for (map<string, map<string, map<string, Book>>>::iterator i1 = i->second.begin(); i1 != i->second.end(); i1++)
{
for (map<string, map<string, Book>>::iterator i2 = i1->second.begin(); i2 != i1->second.end(); i2++)
{
for (map<string, Book>::iterator i3 = i2->second.begin(); i3 != i2->second.end(); i3++)
{
if (i3->second.getISBN() == key)
{
cout << i3->second.getSernum() << " " << i3->second << endl;
}
}
}
}
}
}
void FindBookAuthor(string key, map<string, map<string, map<string, map<string, Book>>>> &Books) //作者搜索图书
{
for (map<string, map<string, map<string, map<string, Book>>>>::iterator i = Books.begin(); i != Books.end(); i++)
{
for (map<string, map<string, map<string, Book>>>::iterator i1 = i->second.begin(); i1 != i->second.end(); i1++)
{
for (map<string, map<string, Book>>::iterator i2 = i1->second.begin(); i2 != i1->second.end(); i2++)
{
for (map<string, Book>::iterator i3 = i2->second.begin(); i3 != i2->second.end(); i3++)
{
if (i3->second.getAuthor() == key)
{
cout << i3->second.getSernum() << " " << i3->second << endl;
}
}
}
}
}
}
void FindBookNO1(string key1, map<string, map<string, map<string, map<string, Book>>>> &Books) //编号搜索图书
{
int bn1 = 0, bn2 = 0, k = 0, page = 1, num = 0, t_page = 0; //目标书下标,页码,查找结束数目,。。。.
char key_back; //确认是否要退出
const int control_num = 25; //每页结果最大数目
Book find_book[20][25]; //存储结果
map<string, map<string, map<string, map<string, Book>>>>::iterator iter1 = Books.find(key1);
if (iter1 != Books.end())
{
for (map<string, map<string, map<string, Book>>>::iterator it1 = Books[key1].begin(); it1 != Books[key1].end(); it1++)
{
for (map<string, map<string, Book>>::iterator it2 = it1->second.begin(); it2 != it1->second.end(); it2++)
{
for (map<string, Book>::iterator it3 = it2->second.begin(); it3 != it2->second.end(); it3++)
{
if (num >= 500)
{
cout << "----------------------------------------------搜索结果过多,请重新搜索!---------------------------------------------" << endl;
return;
}
find_book[bn1][bn2] = it3->second;
if (bn2 < 24)
{
bn2++;
}
else
{
bn1++;
bn2 = 0;
}
num++;
}
}
}
}
else
{
cout << "无该分类号!" << endl;
return;
}
if (num % control_num != 0) //计算页数
{
t_page = num / control_num + 1;
}
else
{
t_page = num / control_num;
}
const int totalpage = t_page; //确定总页数
while (1) //输出结果及相关操作界面
{
system("cls");
for (int i = 0; i < 25 && 25 * (page - 1) + i < num; i++) //输出结果
{
cout << find_book[page - 1][i].getSernum() << " " << find_book[page - 1][i] << endl;
}
cout << "------------------------------------------------------第 " << page << " 页------------------------------------------------------" << endl;
while (1) //选择页码及退出操作
{
cout << "请选择页码。如果想退出,请输入\"0\" ";
for (int i = 0; i < totalpage; i++)
{
cout << i + 1 << " ";
}
cout << endl;
cin >> page;
if (page == 0)
{
cout << "请确认是否退出 (y or n)" << endl; //确认是否退出
cin >> key_back;
if (key_back == 'y')
{
return; //确认则退出函数
}
else
{
; //否则,啥也不干
}
}
else
{
break; //选择页码后退出操作循环,输出目标结果,并进入下次操作循环
}
}
}
}
void FindBookNO2(string key1, string key2, map<string, map<string, map<string, map<string, Book>>>> &Books) //编号搜索图书
{
int bn1 = 0, bn2 = 0, k = 0, page = 1, num = 0, t_page = 0; //目标书下标,页码,查找结束数目,。。。.
char key_back; //确认是否要退出
const int control_num = 25; //每页结果最大数目
Book find_book[20][25]; //存储结果
map<string, map<string, map<string, map<string, Book>>>>::iterator iter1 = Books.find(key1);
if (iter1 != Books.end())
{
map<string, map<string, map<string, Book>>>::iterator iter2 = Books[key1].find(key2);
if (iter2 != Books[key1].end())
{
for (map<string, map<string, Book>>::iterator it2 = Books[key1][key2].begin(); it2 != Books[key1][key2].end(); it2++)
{
for (map<string, Book>::iterator it3 = it2->second.begin(); it3 != it2->second.end(); it3++)
{
if (num >= 500)
{
cout << "----------------------------------------------搜索结果过多,请重新搜索!---------------------------------------------" << endl;
return;
}
find_book[bn1][bn2] = it3->second;
if (bn2 < 24)
{
bn2++;
}
else
{
bn1++;
bn2 = 0;
}
num++;
}
}
}
else
{
cout << "无该分类号!" << endl;
return;
}
}
else
{
cout << "无该分类号!" << endl;
return;
}
if (num % control_num != 0) //计算页数
{
t_page = num / control_num + 1;
}
else
{
t_page = num / control_num;
}
const int totalpage = t_page; //确定总页数
while (1) //输出结果及相关操作界面
{
system("cls");
for (int i = 0; i < 25 && 25 * (page - 1) + i < num; i++) //输出结果
{
cout << find_book[page - 1][i].getSernum() << " " << find_book[page - 1][i] << endl;
}
cout << "------------------------------------------------------第 " << page << " 页------------------------------------------------------" << endl;
while (1) //选择页码及退出操作
{
cout << "请选择页码。如果想退出,请输入\"0\" ";
for (int i = 0; i < totalpage; i++)
{
cout << i + 1 << " ";
}
cout << endl;
cin >> page;
if (page == 0)
{
cout << "请确认是否退出 (y or n)" << endl; //确认是否退出
cin >> key_back;
if (key_back == 'y')
{
return; //确认则退出函数
}
else
{
; //否则,啥也不干
}
}
else
{
break; //选择页码后退出操作循环,输出目标结果,并进入下次操作循环
}
}
}
}
void FindBookNO3(string key1, string key2, string key3, map<string, map<string, map<string, map<string, Book>>>> &Books) //编号搜索图书
{
int bn1 = 0, bn2 = 0, k = 0, page = 1, num = 0, t_page = 0; //目标书下标,页码,查找结束数目,。。。.
char key_back; //确认是否要退出
const int control_num = 25; //每页结果最大数目
Book find_book[20][25]; //存储结果
map<string, map<string, map<string, map<string, Book>>>>::iterator iter1 = Books.find(key1);
if (iter1 != Books.end())
{
map<string, map<string, map<string, Book>>>::iterator iter2 = Books[key1].find(key2);
if (iter2 != Books[key1].end())
{
map<string, map<string, Book>>::iterator iter3 = Books[key1][key2].find(key3);
if (iter3 != Books[key1][key2].end())
{
for (map<string, Book>::iterator it3 = Books[key1][key2][key3].begin(); it3 != Books[key1][key2][key3].end(); it3++)
{
if (num >= 500)
{
cout << "----------------------------------------------搜索结果过多,请重新搜索!---------------------------------------------" << endl;
return;
}
find_book[bn1][bn2] = it3->second;
if (bn2 < 24)
{
bn2++;
}
else
{
bn1++;
bn2 = 0;
}
num++;
}
}
else
{
cout << "无该分类号!" << endl;
return;
}
}
else
{
cout << "无该分类号!" << endl;
return;
}
}
else
{
cout << "无该分类号!" << endl;
return;
}
if (num % control_num != 0) //计算页数
{
t_page = num / control_num + 1;
}
else
{
t_page = num / control_num;
}
const int totalpage = t_page; //确定总页数
while (1) //输出结果及相关操作界面
{
system("cls");
for (int i = 0; i < 25 && 25 * (page - 1) + i < num; i++) //输出结果
{
cout << find_book[page - 1][i].getSernum() << " " << find_book[page - 1][i] << endl;
}
cout << "------------------------------------------------------第 " << page << " 页------------------------------------------------------" << endl;
while (1) //选择页码及退出操作
{
cout << "请选择页码。如果想退出,请输入\"0\" ";
for (int i = 0; i < totalpage; i++)
{
cout << i + 1 << " ";
}
cout << endl;
cin >> page;
if (page == 0)
{
cout << "请确认是否退出 (y or n)" << endl; //确认是否退出
cin >> key_back;
if (key_back == 'y')
{
return; //确认则退出函数
}
else
{
; //否则,啥也不干
}
}
else
{
break; //选择页码后退出操作循环,输出目标结果,并进入下次操作循环
}
}
}
}
Book::Book(const Book &x) //复制函数,重载输入输出时必须要有
{
Sernum = x.Sernum;
BookName = x.BookName;
ISBN = x.ISBN;
Author = x.Author;
NO1 = x.NO1;
NO2 = x.NO2;
NO3 = x.NO3;
NO = x.NO;
NUM = x.NUM;
}
istream &operator>>(istream &input, Book &x) //图书的输入
{
input >> x.BookName >> x.ISBN >> x.Author >> x.NO1 >> x.NO2 >> x.NO3 >> x.NO >> x.NUM;
return input;
}
ostream &operator<<(ostream &output, const Book &x) //图书的输出
{
output << left << setw(35) << x.BookName << left << setw(20) << x.ISBN << left << setw(35) << x.Author << " " << x.NO1 << " " << x.NO2 << " " << x.NO3 << " " << x.NO << " " << x.NUM;
return output;
}
由于我太菜了,当时写的时候写了好多函数貌似没什么用,大家看看就好,如果没用可以删掉,
对于map ,vector , multimap不懂得小伙伴可以在STL教程中进行学习,冲鸭!!!
这里是图书格式
User.h
#pragma once
#include <algorithm>
#include <conio.h>
#include <cstring>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <time.h>
#include <vector>
#include <map>
#include <windows.h>
#include "Book.h"
#include "LendRecord.h"
#define int long long
using namespace std;
class User
{
protected:
int accountnum; //账号
string password; //密码
vector<LendRecord> LR;//用vector储存用户的借阅记录
public:
User(); //初始化
User(const User &U); //复制
friend void Read_User(vector<User> &, vector<LendRecord> &, const string); //录入
friend void Write_User(vector<User> &, const string); //输出
int getaccnum() const; //返回账号的接口
void accnum_change(int); //改变账号
vector<LendRecord> get_LR() const;
void passw_return(); //重置密码
friend int Login(vector<User> &); //登录
friend void Signin(vector<User> &); //注册
void password_change(); //修改密码
void LendBook(map<string, map<string, map<string, map<string, Book>>>> &, vector<LendRecord> &); //借书
void ReturnBook(map<string, map<string, map<string, map<string, Book>>>> &); //还书
void LookUpRecord(); //查阅借阅记录
};
User::User() //初始化账号密码借阅记录
{
accountnum = 0;
password = "123456";
}
User::User(const User &U)
{
accountnum = U.accountnum;
password = U.password;
LR = U.LR;
}
void Read_User(vector<User> &U, vector<LendRecord> &TLR, const string file)
{
User tu;
LendRecord tlr;
int y, m, d, S;
string N, A, I, NO1, NO2, NO3, NO, ST;
ifstream fin(file);
if (!fin)
{
cout << "用户录入错误!" << endl;
return;
}
while (!fin.eof())
{
int i = 0;
fin >> tu.accountnum >> tu.password;
while (!fin.eof())
{
fin >> y >> m >> d >> S >> N >> I >> A >> NO1 >> NO2 >> NO3 >> NO >> ST;
if (y || m || d)
{
tlr.Read_LR(y, m, d, S, N, I, A, NO1, NO2, NO3, NO, ST);
tu.LR.push_back(tlr);
TLR.push_back(tlr);
}
else
{
break;
}
}
U.push_back(tu);
tu.LR.clear();
}
fin.close();
U.pop_back();
//这是解决一个录入时的BUG,由于每次输出完成后,txt文件会多出一行空行,会引起错误
}
void Write_User(vector<User> &U, const string file)
{
ofstream fout(file);
if (U.size() == 1)
{
return;
}
for (int i = 1; i < U.size(); i++)
{
if (U[i].accountnum == 0)
{
continue;
}
fout << U[i].accountnum << " " << U[i].password << endl;
// cout<<U[i].accountnum<<" "<<U[i].password<<endl;
for (int j = 0; j < U[i].LR.size(); j++)
{
fout << U[i].LR[j] << endl;
// cout<<U[i].LR[j]<<endl;
}
fout << 0 << " " << 0 << " " << 0 << " " << 0 << " "//这里是借阅记录的一个格式操作,后面会讲
<< "0"
<< " "
<< "0"
<< " "
<< "0"
<< " "
<< "0"
<< " "
<< "0"
<< " "
<< "0"
<< " "
<< "0"
<< " "
<< "0" << endl;
// cout<<0<<" "<<0<<" "<<0<<" "<<0<<" "<<"0"<<" "<<"0"<<" "<<"0"<<" "<<"0"<<" "<<"0"<<endl;
}
fout.close();
}
int User::getaccnum() const
{
return this->accountnum;
}
void User::accnum_change(int accnum)
{
this->accountnum = accnum;
}
vector<LendRecord> User::get_LR() const
{
return LR;
}
void User::passw_return()
{
this->password = "123456";
}
int Login(vector<User> &p) //登录页面
{
string passw; //输入的密码
int accnum; //输入的账号
cout << "-----------------------------------------------------读者 登录-----------------------------------------------------" << endl;
cout << "请输入账号:" << endl;
cin >> accnum;
cout << "请输入密码:" << endl;
// cin >> passw;
pass_in(passw);
for (int i = 1; i < p.size(); i++)
{
if (p[i].accountnum == accnum && p[i].password == passw) //如果密码账号正确,停止搜索
{
cout << "-----------------------------------------------------登录成功!----------------------------------------------------" << endl;
cout << "-----------------------------------------尊敬的读者,欢迎使用图书管理系统!----------------------------------------" << endl;
return i;
}
}
cout << "---------------------------------------------账号或密码错误,请重新登录!------------------------------------------" << endl;
return 0;
}
void Signin(vector<User> &p) //注册页面
{
string passw1, passw2; //输入的密码(两次输入),
char key_pass, key_reset = 'y'; //判断是否设置密码,是否重新设置密码
char key_abandon; //判断是否放弃注册
int accnum; //输入的账号
bool key = false; //判断账号是否注册
User *U = new User;
cout << "-------------------------------------------------------注 册-------------------------------------------------------" << endl;
cout << "请输入账号(学号/教师编号):" << endl;
cin >> accnum;
for (int i = 1; i < p.size(); i++)
{
if (accnum == p[i].accountnum) //如果找到与输入账号一样的账号,退出函数
{
cout << "-----------------------------------------------该账号已注册,请登录!----------------------------------------------" << endl;
return;
}
}
U->accountnum = accnum;
cout << "是否设置密码(y or n)(默认密码:123456)" << endl;
cin >> key_pass;
if (key_pass == 'y') //设置密码
{
while (key_reset == 'y')
{
cout << "请设置密码:" << endl; //两次输入,避免密码设置错误
// cin >> passw1;
pass_in(passw1);
cout << "请再次输入密码:" << endl;
// cin >> passw2;
pass_in(passw2);
if (passw1 == passw2) //若两次输入一致,密码设置成功
{
cout << "---------------------------------------------------密码设置成功!--------------------------------------------------" << endl;
U->password = passw1;
p.push_back(*U); //将账号密码存入,并退出函数
delete U;
cout << "-----------------------------------------------------注册成功!-----------------------------------------------------" << endl;
return;
}
else
{
cout << "两次输入不一致,是否重新设置(y or n)!" << endl;
cin >> key_reset; //是否重新输入的判断因子
}
}
if (key_reset == 'n') //若不重新输入,则密码为默认密码
{
cout << "是否放弃注册(y or n)" << endl;
cin >> key_abandon;
if (key_abandon == 'n')
{
cout << "密码为123456" << endl;
U->password = "123456";
p.push_back(*U); //将账号密码存入,并退出函数
delete U;
cout << "-----------------------------------------------------注册成功!-----------------------------------------------------" << endl;
return;
}
else
{
delete U;
cout << "-----------------------------------------------------注册失败!-----------------------------------------------------" << endl;
return;
}
}
}
else
{
cout << "密码为123456" << endl; //若不设置密码,则密码为默认密码
U->password = "123456";
p.push_back(*U); //将账号密码存入,并退出函数
delete U;
cout << "-----------------------------------------------------注册成功!-----------------------------------------------------" << endl;
return;
}
}
void User::password_change() //修改密码
{
cout << "-----------------------------------------------------修改 密码-----------------------------------------------------" << endl;
int accnum; //输入的账号
string passw, passw1, passw2; //原密码,新密码(两次输入)
char key_pass = 'y', key_reset = 'y'; //判断原密码是否输入正确,判断是否重新输入
cout << "请输入账号:" << endl;
cin >> accnum;
if (accnum == this->accountnum && accnum != 0) //账号输入正确,进入密码修改
{
while (key_pass == 'y')
{
cout << "请输入原密码:" << endl;
// cin >> passw;
pass_in(passw);
if (passw == this->password) //原密码输入正确
{
while (key_reset == 'y')
{
cout << "请输入新密码:" << endl; //两次输入新密码,防止密码设置错误
// cin >> passw1;
pass_in(passw1);
cout << "请再次输入新密码:" << endl;
// cin >> passw2;
pass_in(passw2);
if (passw1 == passw2)
{
cout << "---------------------------------------------------密码设置成功!--------------------------------------------------" << endl;
this->password = passw1;
return;
}
else
{
cout << "两次输入不一致,是否仍要修改?(y or n)" << endl; //判断是否重新输入
cin >> key_reset;
}
}
if (key_reset == 'n')
{
cout << "--------------------------------------------------密码仍为原密码!-------------------------------------------------" << endl;
return;
}
}
else
{
cout << "密码输入错误,是否重新输入(y or n)" << endl;
cin >> key_pass;
}
}
if (key_pass == 'n')
{
cout << "--------------------------------------------------密码仍为原密码!-------------------------------------------------" << endl;
return;
}
}
else
{
cout << "---------------------------------------------------账号输入错误!--------------------------------------------------" << endl;
return;
}
}
void User::LendBook(map<string, map<string, map<string, map<string, Book>>>> &B, vector<LendRecord> &TLR) //借书页面
{
LendRecord tlr; //本次借书信息
string book_1, book_2, book_3, book_4;
char key_lend, key_re = 'y';
cout << "-------------------------------------------------------借 书-------------------------------------------------------" << endl;
while (key_re == 'y')
{
cout << "请输入图书分类号:" << endl;
cin >> book_1 >> book_2 >> book_3 >> book_4;
if (B.find(book_1) != B.end())
{
if (B[book_1].find(book_2) != B[book_1].end())
{
if (B[book_1][book_2].find(book_3) != B[book_1][book_2].end())
{
if (B[book_1][book_2][book_3].find(book_4) != B[book_1][book_2][book_3].end())
{
if (B[book_1][book_2][book_3][book_4].getNUM() == 0) //图书借完,退出函数
{
cout << "--------------------------------------------该书已借完,请借阅其他书籍!-------------------------------------------" << endl;
return;
}
else if (B[book_1][book_2][book_3][book_4].getNUM() > 0)
{
cout << "是否借阅该书(y or n)" << endl;
cout << B[book_1][book_2][book_3][book_4] << endl;
cin >> key_lend;
if (key_lend == 'y')
{
B[book_1][book_2][book_3][book_4].NUMreduce();
tlr.TIME();
tlr.Record(B[book_1][book_2][book_3][book_4]);
this->LR.push_back(tlr);
TLR.push_back(tlr);
cout << "----------------------------------------------借书成功!祝您阅读愉快!---------------------------------------------" << endl;
return;
}
else
{
cout << "是否重新借书(y or n)" << endl;
cin >> key_re;
}
}
else
{
cout << "没有该分类号!" << endl;
return;
}
}
else
{
cout << "没有该分类号!" << endl;
return;
}
}
else
{
cout << "没有该分类号!" << endl;
return;
}
}
else
{
cout << "没有该分类号!" << endl;
return;
}
}
else
{
cout << "没有该分类号!" << endl;
return;
}
}
cout << "借书失败!" << endl;
return;
}
void User::ReturnBook(map<string, map<string, map<string, map<string, Book>>>> &B) //还书页面
{
string book_1, book_2, book_3, book_4;
char key; //判断图书信息是否正确
cout << "-------------------------------------------------------还 书-------------------------------------------------------" << endl;
cout << "请输入书本分类号:" << endl;
cin >> book_1 >> book_2 >> book_3 >> book_4;
if (B.find(book_1) != B.end())
{
if (B[book_1].find(book_2) != B[book_1].end())
{
if (B[book_1][book_2].find(book_3) != B[book_1][book_2].end())
{
if (B[book_1][book_2][book_3].find(book_4) != B[book_1][book_2][book_3].end())
{
cout << B[book_1][book_2][book_3][book_4] << endl;
cout << "请确认书本信息是否正确(y or n)" << endl;
cin >> key;
if (key == 'y') //判断图书信息是否正确
{
for (int i = 0; i < this->LR.size(); i++)
{
if (this->LR[i].get_NO1() == book_1 && this->LR[i].get_NO2() == book_2 && this->LR[i].get_NO3() == book_3 && this->LR[i].get_NO() == book_4)
{
B[book_1][book_2][book_3][book_4].NUMplus();
this->LR[i].Return();
cout << "--------------------------------------------感谢您的阅读,欢迎下次借阅!-------------------------------------------" << endl;
return;
}
}
cout << "---------------------------------------未找到借书记录,请找工作人员寻求帮助!--------------------------------------" << endl;
return;
}
else
{
cout << "------------------------------------------数据错误!请找工作人员寻求帮助!-----------------------------------------" << endl;
return;
}
}
else
{
cout << "没有该分类号!" << endl;
return;
}
}
else
{
cout << "没有该分类号!" << endl;
return;
}
}
else
{
cout << "没有该分类号!" << endl;
return;
}
}
else
{
cout << "没有该分类号!" << endl;
return;
}
}
void User::LookUpRecord() //查阅借阅记录
{
cout << "----------------------------------------------------查阅借阅记录---------------------------------------------------" << endl;
cout << "您的借阅记录如下:" << endl;
for (int i = 0; i < LR.size(); i++)
{
cout << this->LR[i] << endl;
}
}
这里是读者的格式
LendRecord.h
#pragma once
#include <algorithm>
#include <conio.h>
#include <cstring>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <time.h>
#include <vector>
#include <map>
#include <windows.h>
#include "Book.h"
#define int long long
using namespace std;
class LendRecord
{
protected:
int year; //日期
int month;
int day;
string BookName; //书名
string author; //作者
string ISBN; //ISBN码
string NO1; //编号
string NO2;
string NO3;
string NO;
int Sernum; //序号
string state; //归还状态
public:
LendRecord(); //初始化
int getSernum() const;
string get_state() const;
int get_time() const;
string get_NO1() const;
string get_NO2() const;
string get_NO3() const;
string get_NO() const;
LendRecord &Read_LR(int, int, int, int, string, string, string, string, string, string, string, string);
void Record(Book &); //记录借阅信息
void Return(); //记录还书
friend ostream &operator<<(ostream &, const LendRecord &); //输出
friend istream &operator>>(istream &, LendRecord &);
void TIME(); //获取系统时间
};
LendRecord::LendRecord() //初始化时间为0
{
year = 0;
month = 0;
day = 0;
BookName = "0";
ISBN = "0";
NO = "0";
author = "0";
Sernum = 0;
state = "0";
}
int LendRecord::getSernum() const
{
return Sernum;
}
string LendRecord::get_state() const
{
return state;
}
int LendRecord::get_time() const
{
return year * 500 + month * 40 + day;
}
string LendRecord::get_NO1() const
{
return NO1;
}
string LendRecord::get_NO2() const
{
return NO2;
}
string LendRecord::get_NO3() const
{
return NO3;
}
string LendRecord::get_NO() const
{
return NO;
}
LendRecord &LendRecord::Read_LR(int y, int m, int d, int S, string N, string I, string A, string NO1, string NO2, string NO3, string NO, string ST)
{
this->year = y;
this->month = m;
this->day = d;
this->BookName = N;
this->ISBN = I;
this->author = A;
this->NO1 = NO1;
this->NO2 = NO2;
this->NO3 = NO3;
this->NO = NO;
this->Sernum = S;
this->state = ST;
return *this;
}
void LendRecord::Record(Book &B) //记录借阅信息
{
this->Sernum = B.getSernum();
this->BookName = B.getBookName();
this->author = B.getAuthor();
this->ISBN = B.getISBN();
this->NO1 = B.getNO1();
this->NO2 = B.getNO2();
this->NO3 = B.getNO3();
this->NO = B.getNO();
this->state = "未归还";
}
void LendRecord::Return() //记录还书
{
this->state = "已归还";
this->Sernum = 0;
}
ostream &operator<<(ostream &output, const LendRecord &x)
{
output << x.year << " " << x.month << " " << x.day << " " << x.Sernum << " " << x.BookName << " " << x.ISBN << " " << x.author << " " << x.NO1 << " " << x.NO2 << " " << x.NO3 << " " << x.NO << " " << x.state;
return output;
}
istream &operator>>(istream &input, LendRecord &x)
{
input >> x.year >> x.month >> x.day >> x.Sernum >> x.BookName >> x.ISBN >> x.author >> x.NO >> x.state;
return input;
}
void LendRecord::TIME() //获取系统时间
{
time_t timep;
struct tm *p;
time(&timep); //获取从1900至今过了多少秒,存入time_t类型的timep
p = localtime(&timep); //用localtime将秒数转化为struct tm结构体
this->year = 1900 + p->tm_year;
this->month = 1 + p->tm_mon;
this->day = p->tm_mday;
}
对时间操作不懂的小伙伴可以去菜鸟教程里寻找答案
Admin.h
#pragma once
#include <algorithm>
#include <conio.h>
#include <cstring>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <time.h>
#include <vector>
#include <map>
#include <windows.h>
#include "LendRecord.h"
#include "Book.h"
#include "User.h"
#define int long long
using namespace std;
class Admin
{
protected:
int Adminaccountnum; //账号
string Adminpassword; //密码
public:
Admin(); //初始化
Admin(const Admin &);
int getAdnum() const;
string getAdpas() const;
friend void Read_Admin(vector<Admin> &, const string);
friend void Write_Admin(vector<Admin> &, const string);
friend int AdminLogin(vector<Admin> &); //登录
friend bool LRcomp(LendRecord, LendRecord);
void User_Add(vector<User> &); //添加用户
void User_Delete(vector<User> &); //删除用户
void User_recover(vector<User> &); //恢复用户密码为默认密码
void User_show(vector<User> &); //展示所有用户
void Book_change(map<string, map<string, map<string, map<string, Book>>>> &); //修改图书信息
void Book_add(map<string, map<string, map<string, map<string, Book>>>> &); //添加图书
void Book_Delete(map<string, map<string, map<string, map<string, Book>>>> &); //删除图书
void Book_show(map<string, map<string, map<string, map<string, Book>>>> &); //展示所有图书
void LR_show(vector<LendRecord> &); //展示借阅记录
};
Admin::Admin() //默认账号和密码;
{
Adminaccountnum = 0;
Adminpassword = "0";
}
Admin::Admin(const Admin &A)
{
Adminaccountnum = A.Adminaccountnum;
Adminpassword = A.Adminpassword;
}
int Admin::getAdnum() const
{
return this->Adminaccountnum;
}
string Admin::getAdpas() const
{
return this->Adminpassword;
}
void Read_Admin(vector<Admin> &A, const string file)
{
Admin ta;
ifstream fin(file);
if (!fin)
{
cout << "管理员录入错误" << endl;
return;
}
while (!fin.eof())
{
fin >> ta.Adminaccountnum >> ta.Adminpassword;
A.push_back(ta);
}
fin.close();
A.pop_back();
}
void Write_Admin(vector<Admin> &A, const string file)
{
ofstream fout(file);
for (int i = 1; i < A.size(); i++)
{
fout << A[i].Adminaccountnum << " " << A[i].Adminpassword << endl;
// cout<<A[i].Adminaccountnum<<" "<<A[i].Adminpassword<<endl;
}
fout.close();
}
int AdminLogin(vector<Admin> &Ad) //登录
{
cout << "----------------------------------------------------管理员登录-----------------------------------------------------" << endl;
int Adaccnum, Ad_num = 0;
string Adpassw;
cout << "请输入管理员账号:" << endl;
cin >> Adaccnum;
cout << "请输入密码:" << endl;
// cin >> Adpassw;
pass_in(Adpassw);
for (int i = 0; i < Ad.size(); i++)
{
if (Ad[i].Adminaccountnum == Adaccnum && Adpassw == Ad[i].Adminpassword)
{
Ad_num = i;
cout << "-----------------------------------------------------登录成功!----------------------------------------------------" << endl;
cout << "----------------------------------------尊敬的管理员,欢迎使用图书管理系统!---------------------------------------" << endl;
return Ad_num;
}
}
cout << "---------------------------------------------账号或密码错误,请重新登录!------------------------------------------" << endl;
return 0;
}
bool LRcomp(LendRecord x, LendRecord y)
{
return x.get_time() < y.get_time();
}
void Admin::User_Add(vector<User> &U) //添加用户
{
int accnum_add;
char key_Racc = 'y', key_acc;
char key = 'y';
cout << "-----------------------------------------------------添加 用户-----------------------------------------------------" << endl;
while (key_Racc == 'y')
{
key = 'y';
cout << "请输入要添加的用户账号:" << endl;
cin >> accnum_add;
for (int i = 1; i < U.size(); i++)
{
if (accnum_add == U[i].getaccnum())
{
key = 'n';
cout << "该账号已注册,是否重新输入(y or n)" << endl;
cin >> key_Racc;
break;
}
}
if (key == 'y')
{
cout << "是否确认创建(y or n)" << endl;
cin >> key_acc;
if (key_acc == 'y')
{
User *user = new User;
user->accnum_change(accnum_add);
U.push_back(*user);
delete user;
cout << "--------------------------------------------------账号已添加成功!-------------------------------------------------" << endl;
return;
}
else
{
cout << "---------------------------------------------------账号添加失败!--------------------------------------------------" << endl;
return;
}
}
}
}
void Admin::User_Delete(vector<User> &U) //删除用户
{
cout << "-----------------------------------------------------删除 用户-----------------------------------------------------" << endl;
int accnum_del;
char key_del = 'y', key_realdel;
while (key_del == 'y')
{
cout << "请输入要删除的账号:" << endl;
cin >> accnum_del;
for (int i = 0; i < U.size(); i++)
{
if (U[i].getaccnum() == accnum_del)
{
cout << "是否确认删除(y or n)" << endl;
cin >> key_realdel;
if (key_realdel == 'y')
{
swap(U[i], U[U.size() - 1]);
U.pop_back();
cout << "---------------------------------------------------账号删除成功!--------------------------------------------------" << endl;
return;
}
else
{
cout << "---------------------------------------------------账号删除失败!--------------------------------------------------" << endl;
return;
}
}
}
cout << "未找到该账号,是否重输入(y or n)" << endl;
cin >> key_del;
}
cout << "---------------------------------------------------账号删除失败!--------------------------------------------------" << endl;
return;
}
void Admin::User_show(vector<User> &U)
{
for (vector<User>::iterator i = U.begin() + 1; i != U.end(); i++)
{
cout << i->getaccnum() << " "
<< "******" << endl;
}
}
void Admin::User_recover(vector<User> &U) //恢复用户密码为默认密码
{
cout << "-----------------------------------------------------重置 密码-----------------------------------------------------" << endl;
int accnum;
char key_reset = 'y', key_realreset;
while (key_reset = 'y')
{
cout << "请输入要重置的账号:" << endl;
cin >> accnum;
for (int i = 0; i < U.size(); i++)
{
if (accnum == U[i].getaccnum())
{
cout << "是否确定重置密码(y or n)" << endl;
cin >> key_realreset;
if (key_realreset == 'y')
{
U[i].passw_return();
cout << "---------------------------------------------------密码重置成功!--------------------------------------------------" << endl;
return;
}
else
{
cout << "---------------------------------------------------密码重置失败!--------------------------------------------------" << endl;
return;
}
}
}
cout << "未找到该账号,是否重新输入(y or n)" << endl;
cin >> key_reset;
}
cout << "---------------------------------------------------密码重置失败!--------------------------------------------------" << endl;
return;
}
void Admin::Book_show(map<string, map<string, map<string, map<string, Book>>>> &B)
{
for (map<string, map<string, map<string, map<string, Book>>>>::iterator i = B.begin(); i != B.end(); i++)
{
for (map<string, map<string, map<string, Book>>>::iterator i1 = i->second.begin(); i1 != i->second.end(); i1++)
{
for (map<string, map<string, Book>>::iterator i2 = i1->second.begin(); i2 != i1->second.end(); i2++)
{
for (map<string, Book>::iterator i3 = i2->second.begin(); i3 != i2->second.end(); i3++)
{
cout << i3->second.getSernum() << " " << i3->second << endl;
}
}
}
}
}
void Admin::Book_change(map<string, map<string, map<string, map<string, Book>>>> &B) //修改图书信息
{
cout << "-----------------------------------------------------修改图书信息-----------------------------------------------------" << endl;
Book rebo;
string book_1, book_2, book_3, book_4;
char key_chan = 'y';
char key, key_real, key_rechan = 'y';
while (key_chan == 'y')
{
cout << "请输入要修改的图书的分类号:" << endl;
cin >> book_1 >> book_2 >> book_3 >> book_4;
if (B.find(book_1) != B.end())
{
if (B[book_1].find(book_2) != B[book_1].end())
{
if (B[book_1][book_2].find(book_3) != B[book_1][book_2].end())
{
if (B[book_1][book_2][book_3].find(book_4) != B[book_1][book_2][book_3].end())
{
cout << B[book_1][book_2][book_3][book_4] << endl;
cout << "请确认是否为此书(y or n)" << endl;
cin >> key;
if (key == 'y')
{
while (key_rechan == 'y')
{
cout << "请输入正确信息:" << endl;
cin >> rebo;
cout << "请确认信息无误(y or n)" << endl;
cin >> key_real;
if (key_real == 'y')
{
B[book_1][book_2][book_3][book_4].book_change(rebo);
cout << "-------------------------------------------------图书信息修改成功!------------------------------------------------" << endl;
return;
}
else
{
cout << "是否重新输入(y or n)" << endl;
cin >> key_rechan;
}
}
cout << "-------------------------------------------------图书信息修改失败!------------------------------------------------" << endl;
return;
}
else
{
cout << "是否重新输入序号(y or n)" << endl;
cin >> key_chan;
}
}
else
{
cout << "没有该分类号!" << endl;
return;
}
}
else
{
cout << "没有该分类号!" << endl;
return;
}
}
else
{
cout << "没有该分类号!" << endl;
return;
}
}
else
{
cout << "没有该分类号!" << endl;
return;
}
}
cout << "-------------------------------------------------图书信息修改失败!------------------------------------------------" << endl;
return;
}
void Admin::Book_add(map<string, map<string, map<string, map<string, Book>>>> &B) //添加图书
{
cout << "-----------------------------------------------------添加 图书-----------------------------------------------------" << endl;
Book TB;
char key_real, key_realindex = 'y';
char key_reindex = 'y';
while (key_realindex == 'y')
{
cout << "请输入图书信息:" << endl;
cin >> TB;
cout << "请确认图书信息是否正确(y or n)" << endl;
cin >> key_real;
if (key_real == 'y')
{
cout << "是否确认添加(y or n)" << endl;
cin >> key_realindex;
if (key_realindex == 'y')
{
if (B.find(TB.getNO1()) != B.end())
{
if (B[TB.getNO1()].find(TB.getNO2()) != B[TB.getNO1()].end())
{
if (B[TB.getNO1()][TB.getNO2()].find(TB.getNO3()) != B[TB.getNO1()][TB.getNO2()].end())
{
map<string, Book>::iterator iter = B[TB.getNO1()][TB.getNO2()][TB.getNO3()].find(TB.getNO());
if (iter != B[TB.getNO1()][TB.getNO2()][TB.getNO3()].end())
{
iter->second.NUMpplus(TB.getNUM());
}
else
{
B[TB.getNO1()][TB.getNO2()][TB.getNO3()][TB.getNO()] = TB;
}
}
else
{
B[TB.getNO1()][TB.getNO2()][TB.getNO3()][TB.getNO()] = TB;
}
}
else
{
B[TB.getNO1()][TB.getNO2()][TB.getNO3()][TB.getNO()] = TB;
}
}
else
{
B[TB.getNO1()][TB.getNO2()][TB.getNO3()][TB.getNO()] = TB;
}
cout << "---------------------------------------------------图书添加成功!--------------------------------------------------" << endl;
return;
}
else
{
cout << "---------------------------------------------------图书添加失败!--------------------------------------------------" << endl;
return;
}
}
else
{
cout << "是否重新输入(y or n)" << endl;
cin >> key_realindex;
}
}
cout << "---------------------------------------------------图书添加失败!--------------------------------------------------" << endl;
return;
}
void Admin::Book_Delete(map<string, map<string, map<string, map<string, Book>>>> &B) //删除图书
{
cout << "-----------------------------------------------------删除 图书-----------------------------------------------------" << endl;
string book_1, book_2, book_3, book_4;
char key_del = 'y', key_realdel;
char key_real;
while (key_del == 'y')
{
cout << "请输入要修改的图书的分类号:" << endl;
cin >> book_1 >> book_2 >> book_3 >> book_4;
if (B.find(book_1) != B.end())
{
if (B[book_1].find(book_2) != B[book_1].end())
{
if (B[book_1][book_2].find(book_3) != B[book_1][book_2].end())
{
if (B[book_1][book_2][book_3].find(book_4) != B[book_1][book_2][book_3].end())
{
cout << B[book_1][book_2][book_3][book_4] << endl;
cout << "是否确定是本书(y or n)" << endl;
cin >> key_real;
if (key_real == 'y')
{
cout << "是否确定删除该书(y or n)" << endl;
cin >> key_realdel;
if (key_realdel == 'y')
{
B[book_1][book_2][book_3].erase(book_4);
cout << "---------------------------------------------------成功删除该书!--------------------------------------------------" << endl;
return;
}
else
{
cout << "-----------------------------------------------------删除失败!----------------------------------------------------" << endl;
return;
}
}
else
{
cout << "是否重新输入(y or n)" << endl;
cin >> key_del;
}
}
else
{
cout << "没有该分类号!" << endl;
return;
}
}
else
{
cout << "没有该分类号!" << endl;
return;
}
}
else
{
cout << "没有该分类号!" << endl;
return;
}
}
else
{
cout << "没有该分类号!" << endl;
return;
}
}
cout << "-----------------------------------------------------删除失败!----------------------------------------------------" << endl;
return;
}
void Admin::LR_show(vector<LendRecord> &L)
{
sort(L.begin(), L.end(), LRcomp);
for (vector<LendRecord>::iterator i = L.begin(); i != L.end(); i++)
{
cout << *i << endl;
}
}
管理员格式
main.cpp
#include <algorithm>
#include <conio.h>
#include <cstring>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <time.h>
#include <vector>
#include <map>
#include <windows.h>
#include "Admin.h"
#define int long long
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e7 + 1;
const int MAXM = 1e4 + 1;
const string book_file = "text.txt";//这里大家也可以采用宏定义的方式
const string book_Ffile = "text1.txt";
const string Admin_file = "Admin.txt";
// const string Admin_Ffile="Admin1.txt";
const string User_file = "User.txt";
// const string User_Ffile="User1.txt";
void maininetrface()
{
system("cls");
cout << "-----------------------------------------每次增添或修改图书,图书编号会改变!--------------------------------------" << endl;
cout << "--------------------------------------------------图书管理系统2.0--------------------------------------------------" << endl;
cout << "----------------------------------------------------1 登录---------------------------------------------------" << endl;
cout << "----------------------------------------------------2 注册---------------------------------------------------" << endl;
cout << "----------------------------------------------------3 退出---------------------------------------------------" << endl;
}
void readerinterface()
{
system("cls");
cout << "----------------------------------------------------尊敬的读者-----------------------------------------------------" << endl;
cout << "----------------------------------------------------1 搜索图书-----------------------------------------------" << endl;
cout << "----------------------------------------------------2 借书---------------------------------------------------" << endl;
cout << "----------------------------------------------------3 还书---------------------------------------------------" << endl;
cout << "----------------------------------------------------4 查询借阅记录-------------------------------------------" << endl;
cout << "----------------------------------------------------5 修改密码-----------------------------------------------" << endl;
cout << "----------------------------------------------------6 退出---------------------------------------------------" << endl;
}
void Admininterface()
{
system("cls");
cout << "---------------------------------------------------尊敬的 管理员---------------------------------------------------" << endl;
cout << "----------------------------------------------------1 增加图书-----------------------------------------------" << endl;
cout << "----------------------------------------------------2 修改图书-----------------------------------------------" << endl;
cout << "----------------------------------------------------3 删除图书-----------------------------------------------" << endl;
cout << "----------------------------------------------------4 查询图书-----------------------------------------------" << endl;
cout << "----------------------------------------------------5 增加读者-----------------------------------------------" << endl;
cout << "----------------------------------------------------6 删除读者-----------------------------------------------" << endl;
cout << "----------------------------------------------------7 读者密码重置-------------------------------------------" << endl;
cout << "----------------------------------------------------8 查看读者-----------------------------------------------" << endl;
cout << "----------------------------------------------------9 查看图书-----------------------------------------------" << endl;
cout << "----------------------------------------------------10 查看借阅记录-------------------------------------------" << endl;
cout << "----------------------------------------------------11 退出---------------------------------------------------" << endl;
}
map<string, map<string, map<string, map<string, Book>>>> Books;
vector<User> Users;
vector<Admin> Admins;
vector<LendRecord> TLR;
Admin A0;
// Book B0;
User U0;
signed main()
{
// Books.push_back(B0);
Users.push_back(U0);
Admins.push_back(A0);
Read_Book(Books, book_file);
Read_User(Users, TLR, User_file);
Read_Admin(Admins, Admin_file);
int key_loop1 = 1;
while (key_loop1)
{
int key_main;
maininetrface();
cin >> key_main;
switch (key_main)
{
case 1:
{
system("cls");
int key_loop2 = 1;
while (key_loop2)
{
system("cls");
int key_identity;
cout << "--------------------------------------------------请选择您的身份:-------------------------------------------------" << endl;
cout << "----------------------------------------------------1 读者(学生或老师)-------------------------------------" << endl;
cout << "----------------------------------------------------2 管理员-------------------------------------------------" << endl;
cout << "----------------------------------------------------3 退出---------------------------------------------------" << endl;
cin >> key_identity;
switch (key_identity)
{
case 1:
{
system("cls");
int accnum_no;
accnum_no = Login(Users);
if (accnum_no)
{
system("pause");
int key_loop3 = 1;
while (key_loop3)
{
system("cls");
int key;
readerinterface();
cin >> key;
switch (key)
{
case 1:
{
system("cls");
int key_loop4 = 1;
while (key_loop4)
{
system("cls");
int key_findway;
cout << "--------------------------------------------------请选择搜索方式:-------------------------------------------------" << endl;
cout << "----------------------------------------------------1 书名---------------------------------------------------" << endl;
cout << "----------------------------------------------------2 ISBN---------------------------------------------------" << endl;
cout << "----------------------------------------------------3 作者---------------------------------------------------" << endl;
cout << "----------------------------------------------------4 分类号-------------------------------------------------" << endl;
cout << "----------------------------------------------------5 退出---------------------------------------------------" << endl;
cin >> key_findway;
switch (key_findway)
{
case 1:
{
system("cls");
string book_name;
cout << "请输入书名:" << endl;
cin >> book_name;
FindBookName(book_name, Books);
system("pause");
break;
}
case 2:
{
system("cls");
string book_ISBN;
cout << "请输入ISBN:" << endl;
cin >> book_ISBN;
FindBookISBN(book_ISBN, Books);
system("pause");
break;
}
case 3:
{
system("cls");
string book_author;
cout << "请输入作者:" << endl;
cin >> book_author;
FindBookAuthor(book_author, Books);
system("pause");
break;
}
case 4:
{
system("cls");
int key_loop5 = 1;
while (key_loop5)
{
system("cls");
int find_level;
cout << "请输入搜索等级(1-3),退出请输入0" << endl;
cin >> find_level;
switch (find_level)
{
case 0:
{
key_loop5 = 0;
break;
}
case 1:
{
string key1;
cout << "请输入一级分类号:" << endl;
cin >> key1;
FindBookNO1(key1, Books);
break;
}
case 2:
{
string key1, key2;
cout << "请输入一,二级分类号:" << endl;
cin >> key1 >> key2;
FindBookNO2(key1, key2, Books);
break;
}
case 3:
{
string key1, key2, key3;
cout << "请输入一,二,三级分类号:" << endl;
cin >> key1 >> key2 >> key3;
FindBookNO3(key1, key2, key3, Books);
break;
}
default:
cout << "请输入1-3的数字!" << endl;
}
}
}
case 5:
{
key_loop4 = 0;
break;
}
default:
cout << "请输入1-5的数字!" << endl;
system("pause");
}
}
break;
}
case 2:
{
system("cls");
Users[accnum_no].LendBook(Books, TLR);
system("pause");
break;
}
case 3:
{
system("cls");
Users[accnum_no].ReturnBook(Books);
system("pause");
break;
}
case 4:
{
system("cls");
Users[accnum_no].LookUpRecord();
system("pause");
break;
}
case 5:
{
system("cls");
Users[accnum_no].password_change();
system("pause");
break;
}
case 6:
{
key_loop3 = 0;
break;
// return 0;
}
default:
cout << "请输入1-6的数字!" << endl;
system("pause");
}
}
}
break;
}
case 2:
{
system("cls");
int Admin_no;
Admin_no = AdminLogin(Admins);
if (Admin_no)
{
system("pause");
int key_loop3 = 1;
while (key_loop3)
{
system("cls");
int key;
Admininterface();
cin >> key;
switch (key)
{
case 1:
{
system("cls");
Admins[Admin_no].Book_add(Books);
system("pause");
break;
}
case 2:
{
system("cls");
Admins[Admin_no].Book_change(Books);
system("pause");
break;
}
case 3:
{
system("cls");
Admins[Admin_no].Book_Delete(Books);
system("pause");
break;
}
case 4:
{
int key_loop4 = 1;
while (key_loop4)
{
system("cls");
int key_findway;
cout << "--------------------------------------------------请选择搜索方式:-------------------------------------------------" << endl;
cout << "----------------------------------------------------1 书名---------------------------------------------------" << endl;
cout << "----------------------------------------------------2 ISBN---------------------------------------------------" << endl;
cout << "----------------------------------------------------3 作者---------------------------------------------------" << endl;
cout << "----------------------------------------------------4 分类号-------------------------------------------------" << endl;
cout << "----------------------------------------------------5 退出---------------------------------------------------" << endl;
cin >> key_findway;
switch (key_findway)
{
case 1:
{
system("cls");
string book_name;
cout << "请输入书名:" << endl;
cin >> book_name;
FindBookName(book_name, Books);
system("pause");
break;
}
case 2:
{
system("cls");
string book_ISBN;
cout << "请输入ISBN:" << endl;
cin >> book_ISBN;
FindBookISBN(book_ISBN, Books);
system("pause");
break;
}
case 3:
{
system("cls");
string book_author;
cout << "请输入作者:" << endl;
cin >> book_author;
FindBookAuthor(book_author, Books);
system("pause");
break;
}
case 4:
{
int key_loop5 = 1;
while (key_loop5)
{
system("cls");
int find_level;
cout << "请输入搜索等级(1-3),退出请输入0" << endl;
cin >> find_level;
switch (find_level)
{
case 0:
{
key_loop5 = 0;
break;
}
case 1:
{
string key1;
cout << "请输入一级分类号:" << endl;
cin >> key1;
FindBookNO1(key1, Books);
break;
}
case 2:
{
string key1, key2;
cout << "请输入一,二级分类号:" << endl;
cin >> key1 >> key2;
FindBookNO2(key1, key2, Books);
break;
}
case 3:
{
string key1, key2, key3;
cout << "请输入一,二,三级分类号:" << endl;
cin >> key1 >> key2 >> key3;
FindBookNO3(key1, key2, key3, Books);
break;
}
default:
cout << "请输入1-3的数字!" << endl;
}
}
}
case 5:
{
key_loop4 = 0;
break;
}
default:
cout << "请输入1-4的数字!" << endl;
system("pause");
}
}
break;
}
case 5:
{
system("cls");
Admins[Admin_no].User_Add(Users);
system("pause");
break;
}
case 6:
{
system("cls");
Admins[Admin_no].User_Delete(Users);
system("pause");
break;
}
case 7:
{
system("cls");
Admins[Admin_no].User_recover(Users);
system("pause");
break;
}
case 8:
{
system("cls");
Admins[Admin_no].User_show(Users);
system("pause");
break;
}
case 9:
{
system("cls");
Admins[Admin_no].Book_show(Books);
system("pause");
break;
}
case 10:
{
system("cls");
Admins[Admin_no].LR_show(TLR);
system("pause");
break;
}
case 11:
{
key_loop3 = 0;
break;
// return 0;
}
default:
cout << "请输入1-11的数字!" << endl;
system("pause");
}
}
}
break;
}
case 3:
{
key_loop2 = 0;
break;
}
default:
cout << "请输入1-3的数字!" << endl;
system("pause");
}
}
break;
}
case 2:
{
system("cls");
cout << "只能注册为读者!" << endl;
Signin(Users);
system("pause");
break;
}
case 3:
{
key_loop1 = 0;
break;
}
default:
cout << "请输入1-3的数字!" << endl;
system("pause");
}
}
Write_Book(Books, book_file);
Write_User(Users, User_file);
Write_Admin(Admins, Admin_file);
return 0;
}
主函数里用了很多的system(“cls”),和system(“pause”)用来清屏和捕捉屏幕
也是因为当时写的时候太菜了所以system(“cls”),和system(“pause”)就随便写了好多,可能有好多地方加的不是很好,大家可以想想更好的方法
当时写主程序的时候,我是一次写完各个头文件后,一次写完主程序的,幸亏我写的BUG不多,半天就该完了,但是大家在写的时候,一定不能学我,要一边写头文件,一边写主程序进行测试,不然后期该BUG可能会让你疯掉(我有好多同学都因为这个当时要疯)
对了大家在做这个的时候很有可能会遇到输出乱码的情况,这时只需要改变txt文件的编码格式就可以了
大家加油吧,这个是会查重的,一定不要全抄哦,相信你们一定写的比我好。
冲鸭!!!!