• C++实验3:图书管理系统3.0——容器文件流


    题目描述

    分析系统图书管理系统是对学生、教师信息和图书信息进行管理,学生基本信息包括学号,姓名,院系,最大借阅图书数量属性,教师基本信息包括工号,姓名,院系,最大借阅图书数量属性,图书基本信息中包括图书号,书名,作者,出版社,图书数量属性,要求输入、输出、修改、查询以上信息功能, 设计并实现功能。考虑借阅人、图书是否可以采用继承派生关系,使用多态等机制实现不同类型学生借阅不同类型的图书或资源。以下是一些基本功能,根据情况可以进行添加修改

    1. 添加借阅人信息;
    2. 修改借阅人信息;
    3. 处理借阅人借阅信息;
    4. 处理借阅人还书信息;
    5. 添加图书或资源信息;
    6. 修改图书或资源信息;
    7. 查看图书信息;
    8. 提供用户管理功能

    程序流程图

    在这里插入图片描述

    类图

    在这里插入图片描述

    参考代码

    头文件汇总类 All.h

    #pragma once
    #include <iostream>
    #include <string>
    #include <vector>
    #include <iterator>
    #include <algorithm>
    #include <Windows.h>
    #include <stdlib.h>
    using namespace std;
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    主函数 main.cpp

    #include "PeopleManager.h"
    /*
    * 说明:
    * 该程序主要有两个模块构成:<图书管理模块>,<人物账户信息、借书信息管理模块>
    * <图书管理模块>:
    *	1.内存中通过数组存书,相关操作后在写入文件中   "BookFile.txt"
    *	2.图书基本信息包括书名、出版社、特殊属性(一般图书ISBN号,杂志ISSN号,电子书格式)、价格、页数(电子书是字数)
    *	3.可对书籍(一般图书,电子书,杂志)进行增、删、查、存等操作(为什么没有修改操作?考虑到书本信息的整体性,固定性。真的输入错了直接删除在重新添加就好)
    *	特别说明:一般图书在添加时会进行ISBN号检测,如果ISBN号非法则重新输入图书信息,所以写了一个屏蔽检测的模块,
    *			CLIbraryManager.cpp-->124行模块一跳过ISBN号的检测,143行开启ISBN号的检测。两个模块只能同时用一个!!
    *	附上合法图书信息:①"C/C++程序设计教程——面向对象分册(第三版)", "中国工信出版集团,电子工业出版社", "978-7-121-33047-6", "47.00", "356"
    *					  ②"概率论与数理统计","中国工信出版集团,人民邮电出版社","978-7-115-53563-4","45","226"
    * <人物账户信息、借书信息管理模块>:
    *	包括学生,教师,管理员。内存中通过vector容器v_People存放人物信息,通过vector容器v_Book存放人物借书信息
    *	1.默认管理员账号:2003			密码:666666
    *	2.借阅相关操作需要登录个人账号
    *	3.学生权限:查看个人信息(包括基本信息、借书信息)、借书、还书、修改个人密码、查询图书馆中的书籍信息(包括全部查询、搜索)
    *	  教师权限:在学生的权限上增加对学生信息的查询权限(包括全部查询、搜索)
    *	  管理员权限:
    			1.人物相关操作:在教书的权限上增加对教师信息的查询权限(包括全部查询、搜索)、添加人物账户(学生账户、教师账户、管理员账户)、模糊搜索人物信息、重置人物密码、删除人物账户、清空人物账户文件 "PeopleFile.txt"
    			2.图书相关操作:直接接入图书管理模块中的全部功能
    */	
    int main()
    {
    	PeopleManager PEO;
    	int choice = 0;//接收用户的选择
    	while (true)
    	{
    		PEO.Show_Menu();//展示交互菜单
    		cout << "情输入您的选择:" << endl;
    		cin >> choice;//接收用户的选择
    		switch (choice)
    		{
    			case 0:
    				PEO.ExitSystem();//退出系统
    				break;
    			case 1:
    				PEO.student_Operation();//学生操作
    				break;
    			case 2:
    				PEO.teacher_Operation();//教书操作
    				break;
    			case 3:
    				PEO.manager_Operation();//管理员操作
    				break;
    		default:
    			cout << "输入的数据有误,请重新输入!" << endl;
    			system("pause");
    			system("cls");
    			break;
    		}
    	}
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53

    用户类 定义 Account.h

    #pragma once
    #include "All.h"
    class Account
    {
    private:
    	string password;//密码
    	int id;//判断身份,1:学生    2:老师   3:管理员
    public:
    	Account();
    	Account(string, int);
    	void chingePassword(string);
    	string getPassword();
    	int getId();
    	void display();
    	void setId(int id);
    };
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18

    账户类 实现 Account.cpp

    #include "Account.h"
    
    Account::Account()
    {
    	
    }
    
    Account::Account(string m_password, int m_id)
    {
    	this->password = m_password;
    	this->id = m_id;
    }
    
    void Account::chingePassword(string m_password)
    {
    	this->password = m_password;
    }
    
    string Account::getPassword()
    {
    	return this->password;
    	return string();
    }
    
    int Account::getId()
    {
    	return this->id;	return 0;}
    
    void Account::display()
    {
    	if (this->id == 1) {
    		cout << "该学生的密码是:" << this->password << endl;
    	}
    	else if (this->id == 2) {
    		cout << "该教师的密码是:" << this->password << endl;
    	}
    	else {
    		cout << "该管理员的密码是:" << this->password << endl;
    	}
    }
    
    void Account::setId(int id)
    {
    	this->id = id;
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46

    个人用户类 定义 People.h

    #pragma once
    #include "All.h"
    #include "Account.h"
    #include "CColective.h"
    #include "CLIbraryManager.h"
    class People
    {
    private:
    	int p_num;//学号或者工号
    	string p_name;//姓名
    	string p_faculty;//院系
    	int p_maxBookNum;//最大借书数量
    	Account account;
    	vector<CColective*> v_book;
    public:
    	People();
    	People(int m_id, string m_password, int m_num, string m_name, string m_faculty);
    	void setNum(int m_num);//设置或修改学号
    	void setName(string m_name);//设置或修改姓名
    	void setFaculty(string m_faculty);//设置或修改院系
    	void borrowBook();//借书
    	void return_Book();//还书
    	void display();//显示所有信息(包括学生信息,书本信息)
    	void dispaly_book();//仅显示书本信息
    	int getNum();
    	string getName();
    	string getFaculty();
    	int getMaxBookNum();
    	Account& getAccount();
    	vector<CColective*>& get_v_book();
    };
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33

    个人用户类 实现 People.cpp

    #include "People.h"
    
    People::People()
    {
    	this->p_num = -1;
    	this->p_name = "";
    	this->p_faculty = "";
    }
    
    People::People(int m_id, string m_password, int m_num, string m_name, string m_faculty)
    {
    	this->account.setId(m_id);
    	this->account.chingePassword(m_password);
    	this->p_num = m_num;
    	int i;
    	this->p_name = m_name;
    
    	this->p_faculty = m_faculty;
    
    	if (account.getId() == 1) {
    		this->p_maxBookNum = 3;
    	}
    	else if (account.getId() == 2) {
    		this->p_maxBookNum = 5;
    	}
    	
    }
    
    void People::setNum(int m_num)
    {
    	this->p_num = m_num;
    }
    
    void People::setName(string m_name)
    {
    	this->p_name = m_name;
    }
    
    void People::setFaculty(string m_faculty)
    {
    	this->p_faculty = m_faculty;
    }
    
    void People::borrowBook()
    {
    	CLIbraryManager LM;
    	int c;
    	while (true)
    	{
    		cout << "\t\t-----------------" << endl;
    		cout << "\t\t|1、查看所有书籍|" << endl;
    		cout << "\t\t-----------------" << endl;
    		cout << "\t\t|2、通过编号借书|" << endl;
    		cout << "\t\t-----------------" << endl;
    		cout << "\t\t|3、通过书名借书|" << endl;
    		cout << "\t\t-----------------" << endl;
    		cout << "\t\t|4、查找书籍    |" << endl;
    		cout << "\t\t-----------------" << endl;
    		cout << "\t\t|0、    返回    |" << endl;
    		cout << "\t\t-----------------" << endl;
    		cin >> c;
    		
    		switch (c)
    		{
    			if (this->v_book.size() < this->getMaxBookNum()){
    				case 2:
    				{
    					if (this->v_book.size() == this->getMaxBookNum()) {
    						cout << "已达到最大借书数量!"
    							<< "\t借书失败!" << endl;
    						system("pause");
    						system("cls");
    						break;
    					}
    					int m_Id;
    					cout << "请输入编号:";
    					cin >> m_Id;
    					if (LM.find_By_Num(m_Id) != nullptr)
    					{
    						this->v_book.push_back(LM.find_By_Num(m_Id));
    						cout << "借书成功!" << endl;
    					}
    					else {
    						cout << "未查询到该书信息!"
    							<< "\t借书失败!" << endl;
    					}
    					system("pause");
    					system("cls");
    					break;
    				}
    				case 3:
    				{
    					if (this->v_book.size() == this->getMaxBookNum()) {
    						cout << "已达到最大借书数量!"
    							<< "\t借书失败!" << endl;
    						system("pause");
    						system("cls");
    						break;
    					}
    					string m_name;
    					cout << "请输入书名:";
    					cin >> m_name;
    					if (LM.find_By_Name(m_name) != nullptr)
    					{
    						this->v_book.push_back(LM.find_By_Name(m_name));
    						cout << "借书成功!" << endl;
    					}
    					else {
    						cout << "未查询到该书信息!"
    							<< "\t借书失败!" << endl;
    					}
    					system("pause");
    					system("cls");
    					break;
    				}
    			}
    			else {
    				cout << "已达到最大借书数量!"
    					<< "\t借书失败!" << endl;
    				break;
    			}
    			case 1:
    			{
    				system("cls");
    				LM.show_BookArray();
    				break;
    			}
    			case 4:
    			{
    				system("cls");
    				LM.find_Book();
    				break;
    			}
    			case 0:
    			{
    				system("cls");
    				return;
    				break;
    			}
    			default:
    			{
    				cout << "输入的数据有误!" << endl;
    				break;
    			}
    		}
    	}
    }
    
    void People::return_Book()
    {
    	int c;
    	while (true)
    	{
    		cout << "\t\t-----------------" << endl;
    		cout << "\t\t|1、查看已借书籍|" << endl;
    		cout << "\t\t-----------------" << endl;
    		cout << "\t\t|2、通过编号还书|" << endl;
    		cout << "\t\t-----------------" << endl;
    		cout << "\t\t|3、通过书名还书|" << endl;
    		cout << "\t\t-----------------" << endl;
    		cout << "\t\t|0、    返回    |" << endl;
    		cout << "\t\t-----------------" << endl;
    		cin >> c;
    
    		switch (c)
    		{
    			
    			case 1:
    			{
    				cout << this->v_book.size() << endl;
    				this->dispaly_book();
    				system("pause");
    				system("cls");
    				break;
    			}
    			case 2:
    			{
    				int index = -1;
    				int m_Id;
    				cout << "请输入编号:";
    				cin >> m_Id;
    				for (vector<CColective*>::iterator iter = v_book.begin(); iter != v_book.end(); iter++) {
    					if ((*iter)->m_Id == m_Id) {
    						index = 1;
    						(*iter)->showInfo();
    						cout << endl;
    						int i = 1;
    						cout << "是否确认归还此书籍?" << endl;
    						cout << "1.是"
    							<< "\n2.否" << endl;
    						cin >> i;
    						switch (i)
    						{
    						case 1:
    						{
    							v_book.erase(iter);
    							cout << "还书成功!" << endl;
    							break;
    						}
    						case 2:
    						{
    							cout << "返回!" << endl;
    							break;
    						}
    						}
    						break;
    					}
    				}
    				if (index == -1) {
    					cout << "未查询到该书信息!" << endl;
    				}
    				system("pause");
    				system("cls");
    				break;
    			}
    			
    			case 3:
    			{
    				int index = -1;
    				string m_name;
    				cout << "请输入书名:";
    				cin >> m_name;
    				for (vector<CColective*>::iterator iter = v_book.begin(); iter != v_book.end(); iter++) {
    					if ((*iter)->m_Name == m_name) {
    						index = 1;
    						(*iter)->showInfo();
    						cout << endl;
    						int i = 1;
    						cout << "是否确认归还此书籍?" << endl;
    						cout << "1.是"
    							<< "\n2.否" << endl;
    						cin >> i;
    						switch (i)
    						{
    						case 1:
    						{
    							v_book.erase(iter);
    							cout << "还书成功!" << endl;
    							break;
    						}
    						case 2:
    						{
    							cout << "返回!" << endl;
    							break;
    						}
    						}
    						break;
    					}
    				}
    				if (index == -1) {
    					cout << "未查询到该书信息!" << endl;
    				}
    				system("pause");
    				system("cls");
    				break;
    			}
    			case 0:
    			{
    				system("cls");
    				return;
    				break;
    			}
    			default:
    			{
    				cout << "输入的数据有误!" << endl;
    				break;
    			}
    			
    		}
    		//如果还书过后已经没有书了,则返回上级菜单
    		if (v_book.empty()) {
    			return;
    		}
    	}
    }
    
    void People::display()
    {
    	if (this->account.getId() == 1) {
    		cout << "学生学号:" << this->p_num
    			<< "\t学生姓名:" << this->p_name
    			<< "\t学生院系:" << this->p_faculty
    			<< "\t最大借书数量为:" << this->p_maxBookNum
    			<< "\n------------------------------------------------借书信息------------------------------------------------"
    			<< "\n已借:" << this->v_book.size() << "本书"
    			<< "\t还可借:" << this->p_maxBookNum - v_book.size() << "本书" << endl;
    		if (!v_book.empty()) {
    			cout << "                                              已借书籍信息" << endl;
    			//vector<CBooks*>::iterator inter = v_book.begin();
    			int i = 0;
    			for (auto book : v_book) {
    				i++;
    				cout << "第 " << i << " 本书为:" << endl;
    				book->showInfo();
    				cout << endl << endl;
    			}
    		}
    	}
    	else if (this->account.getId() == 2) {
    		cout << "教师工号:" << this->p_num
    			<< "\t教师姓名:" << this->p_name
    			<< "\t教师院系:" << this->p_faculty
    			<< "\t最大借书数量为:" << this->p_maxBookNum
    			<< "\n------------------------------------------------借书信息------------------------------------------------"
    			<< "\n已借:" << this->v_book.size() << "本书"
    			<< "\t还可借:" << this->p_maxBookNum - v_book.size() << "本书" << endl;
    		if (!v_book.empty()) {
    			cout << "                                              已借书籍信息" << endl;
    			//vector<CBooks*>::iterator inter = v_book.begin();
    			int i = 0;
    			for (auto book : v_book) {
    				i++;
    				cout << "第 " << i << " 本书为:" << endl;
    				book->showInfo();
    				cout << endl << endl;
    			}
    		}
    	}
    	else if (this->account.getId() == 3) {
    		cout << "该管理员编号:" << this->p_num
    			<< "\t管理员姓名:" << this->p_name
    			<< "\t管理员级别:" << this->p_faculty
    			<< endl;
    	}
    	system("pause");
    	system("cls");
    }
    
    void People::dispaly_book()
    {
    	cout << "\t------------------------------------------------借书信息------------------------------------------------"
    		<< "\t已借:" << this->v_book.size() << "本书"
    		<< "\t还可借:" << this->p_maxBookNum - v_book.size() << "本书" << endl;
    	if (!v_book.empty()) {
    		cout << "                                              已借书籍信息" << endl;
    		//vector<CBooks*>::iterator inter = v_book.begin();
    		int i = 0;
    		for (auto book : v_book) {
    			i++;
    			cout << "第 " << i << " 本书为:" << endl;
    			book->showInfo();
    		}
    	}
    }
    
    int People::getNum()
    {
    	return this->p_num;
    	return 0;
    }
    
    string People::getName()
    {
    	return this->p_name;
    	return string();
    }
    
    string People::getFaculty()
    {
    	return this->p_faculty;
    	return string();
    }
    
    int People::getMaxBookNum()
    {
    	return this->p_maxBookNum;
    	return 0;
    }
    
    Account& People::getAccount()
    {
    	return this->account;
    }
    
    vector<CColective*>& People::get_v_book()
    {
    	return this->v_book;
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • 234
    • 235
    • 236
    • 237
    • 238
    • 239
    • 240
    • 241
    • 242
    • 243
    • 244
    • 245
    • 246
    • 247
    • 248
    • 249
    • 250
    • 251
    • 252
    • 253
    • 254
    • 255
    • 256
    • 257
    • 258
    • 259
    • 260
    • 261
    • 262
    • 263
    • 264
    • 265
    • 266
    • 267
    • 268
    • 269
    • 270
    • 271
    • 272
    • 273
    • 274
    • 275
    • 276
    • 277
    • 278
    • 279
    • 280
    • 281
    • 282
    • 283
    • 284
    • 285
    • 286
    • 287
    • 288
    • 289
    • 290
    • 291
    • 292
    • 293
    • 294
    • 295
    • 296
    • 297
    • 298
    • 299
    • 300
    • 301
    • 302
    • 303
    • 304
    • 305
    • 306
    • 307
    • 308
    • 309
    • 310
    • 311
    • 312
    • 313
    • 314
    • 315
    • 316
    • 317
    • 318
    • 319
    • 320
    • 321
    • 322
    • 323
    • 324
    • 325
    • 326
    • 327
    • 328
    • 329
    • 330
    • 331
    • 332
    • 333
    • 334
    • 335
    • 336
    • 337
    • 338
    • 339
    • 340
    • 341
    • 342
    • 343
    • 344
    • 345
    • 346
    • 347
    • 348
    • 349
    • 350
    • 351
    • 352
    • 353
    • 354
    • 355
    • 356
    • 357
    • 358
    • 359
    • 360
    • 361
    • 362
    • 363
    • 364
    • 365
    • 366
    • 367
    • 368
    • 369
    • 370
    • 371
    • 372
    • 373
    • 374
    • 375
    • 376
    • 377
    • 378
    • 379

    账户管理类 定义 PeopleManager.h

    #pragma once
    #include "People.h"
    #define PEOPLE "PeopleFile.txt"
    #include "CLIbraryManager.h"
    class PeopleManager
    {
    private:
    	const int m_Num = 2003;//初始账号
    	const string m_Possword = "666666";//初始密码
    	const string m_faculty = "默认管理员";//初始密码
    	const int m_id = 3;
    	const string m_name = "小明";
    	People* P = new People(m_id, m_Possword, m_Num, m_name, m_faculty);
    public:
    	void color(unsigned short color_index);//可局部颜色改变
    	
    	PeopleManager();//构造函数
    	int get_Rows_Number(string FILE_NAME);//获取文件有效行的数量
    
    	//显示菜单( 0.退出系统   1.学生操作   2.教师操作   3.管理员操作)
    	void Show_Menu();
    
    	//退出程序函数
    	void ExitSystem();
    
    	//添加人
    	vector <People*> v_People;
    	//int p_PeopleNum = v_People.size();//记录人的数量
    	void add_People();
    
    	//设置标志位判断最初文件是否存在
    	bool p_isPeople;
    
    	//保存人的信息
    	void save_Pepple();
    
    	//初始化文件中已存在的数据
    	void init_Person();
    
    	//显示所有人物(包括学生,教师,管理员)信息,管理员权限
    	void show_People();
    
    	//查找人物实现, 管理员,教师权限
    	void find_People();//管理员查找函数
    
    	People& search_People(People* people);//通过id和num唯一确定,并返回引用
    
    	//清空人物信息,管理员权限
    	void clear_People();
    
    	//通过查找删除学生信息,管理员权限
    	void delete_People();
    
    	//判断密码是否正确
    	People* judge_Possword(int Id, string possword);
    
    	//学生操作
    	void student_Operation();
    
    	//教师操作
    	void teacher_Operation();
    	People& find_People1();//教师查找学生的函数
    	void see_Student();//教师查看学生信息的函数(全部查看,单个查看)
    	void show_Student();//教师的查看所有学生信息
    
    	//管理员操作
    	void manager_Operation();
    	void people_Info_Manage(People& people);//人物信息管理
    	void see_Teacher(); //管理员查看教师信息的函数(全部查看,单个查看)
    	People& find_People2();//管理员查找教师
    	void show_Teacher();//管理员的查看所有教师信息
    	void reset_Password();//重置密码
    	CLIbraryManager LM;
    	void book_Info_Manage(CLIbraryManager &LM);//图书信息管理
    
    
    	~PeopleManager();//析构函数函数
    };
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80

    账户管理类 实现 PeopleManager.cpp

    #include "PeopleManager.h"
    
    void PeopleManager::color(unsigned short color_index)
    {
    	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color_index);
    }
    
    PeopleManager::PeopleManager()
    {
    	v_People.push_back(this->P);//添加默认管理员信息
    	ifstream ifs;
    	ifs.open(PEOPLE, ios::in);//打开文件
    
    	//文件不存在
    	if (!ifs.is_open())//ifs.is_open()返回值为bool类型,如果能打开返回true
    	{
    		this->p_isPeople = false;//文件不存在,将m_isFile赋值为false
    		ifs.close();
    		return;
    	}
    
    	//文件存在,但数据为空
    	char ch;
    	ifs >> ch;//传入空字符
    	if (ifs.eof())//如果文件是空,则返回true
    	{
    		this->p_isPeople = false;//文件存在,但无数据,将p_isPeople赋值为false
    		ifs.close();
    		return;
    	}
    
    	//文件存在且不为空
    	else if (!ifs.eof())
    	{
    		this->p_isPeople = true;//文件存在且有数据,将p_isPeople赋值为true
    		//将读取的数据存入数组中
    		this->init_Person();
    		
    	}
    }
    
    int PeopleManager::get_Rows_Number(string FILE_NAME)
    {
    	ifstream ifs(FILE_NAME.c_str());
    	int line_count = 0;     ///记录文件中行的数量
    	string tmp_content; ///临时保存行数据
    	while (!ifs.eof())
    	{
    		std::getline(ifs, tmp_content, '\n');
    		///过滤空行
    		line_count += !tmp_content.empty();
    	}
    	return line_count;
    }
    
    void PeopleManager::Show_Menu()
    {
    	color(3);
    	cout << "————————————————————————" << endl;
    	cout << "|——————  欢迎使用图书管理系统!—————|" << endl;
    	cout << "————————————————————————" << endl;
    	cout << "|————————   0.退出系统     ——————|" << endl;
    	cout << "————————————————————————" << endl;
    	cout << "|————————   1.学生登录     ——————|" << endl;
    	cout << "————————————————————————" << endl;
    	cout << "|————————   2.教师登录     ——————|" << endl;
    	cout << "————————————————————————" << endl;
    	cout << "|————————   3.管理员登录   ——————|" << endl;
    	cout << "————————————————————————" << endl;
    	cout << endl;
    }
    
    
    void PeopleManager::ExitSystem()
    {
    	cout << "欢迎下次使用!" << endl;
    	system("pause");
    	exit(0);
    }
    
    void PeopleManager::add_People()
    {
    	color(6);
    	cout << "请输入添加的人数:" << endl;
    	int add_number = 0;
    	cin >> add_number;//接收用户输入的大小
    	if (add_number > 0) 
    	{
    		color(6);
    		for (int i = 0; i < add_number; i++)
    		{
    			color(6);
    			int p_num;//学号或者工号/管理员编号
    			string p_name;//姓名
    			string p_faculty;//院系
    			string password;//密码
    			cout << "请选择添加的身份:" << endl;
    			cout << "1.学生"
    				<< "\n2.教师"
    				<< "\n3.管理员" << endl;
    			int index;
    			cin >> index;
    			switch (index)
    			{
    			case 1:
    			{
    				int m_index = -1;//条件判断标志位
    				do
    				{
    					color(6);
    					cout << "请输入第" << i + 1 << "个人信息:" << endl;
    					cout << "学生学号:" << endl;
    					cin >> p_num;
    					cout << endl;
    					cout << "学生姓名:" << endl;
    					cin >> p_name;
    					cout << "学生院系:" << endl;
    					cin >> p_faculty;
    					cout << "请设置学生登录密码:" << endl;
    					cin >> password;
    					m_index = -1;
    					for (auto iter : v_People) {
    						if (iter->getAccount().getId() == 1 && iter->getNum() == p_num) {
    							color(4);
    							m_index = 1;
    							cout << "该学生学号已存在,请重新输入信息!" << endl;
    							break;
    						}
    					}
    				} while (m_index == 1);
    				
    				while (password.length() > 13) {
    					color(4);
    					cout << "密码长度小于 13位 请重新设置密码:";
    					cin >> password;
    				}
    				People* people = new People(index, password, p_num, p_name, p_faculty);
    				people->getAccount().chingePassword(password);
    				v_People.push_back(people);
    
    				break;
    			}
    			case 2:
    			{
    				int m_index = -1;//条件判断标志位
    				do
    				{
    					color(6);
    					cout << "请输入第" << i + 1 << "个人信息:" << endl;
    					cout << "教师工号:" << endl;
    					cin >> p_num;
    					cout << endl;
    					cout << "教师姓名:" << endl;
    					cin >> p_name;
    					cout << "教师院系:" << endl;
    					cin >> p_faculty;
    					cout << "请设置教师登录密码:" << endl;
    					cin >> password;
    					m_index = -1;
    					for (auto iter : v_People) {
    						if (iter->getAccount().getId() == 2 && iter->getNum() == p_num) {
    							color(4);
    							m_index = 1;
    							cout << "该教师工号已存在,请重新输入信息!" << endl;
    							break;
    						}
    					}
    				} while (m_index == 1);
    				
    				while (password.length() > 13) {
    					color(4);
    					cout << "密码长度小于 13位 请重新设置密码:";
    					cin >> password;
    				}
    				People* people = new People(index, password, p_num, p_name, p_faculty);
    				people->getAccount().chingePassword(password);
    				v_People.push_back(people);
    				break;
    			}
    			case 3:
    			{
    				int m_index = -1;//条件判断标志位
    				do
    				{
    					color(6);
    					cout << "请输入第" << i + 1 << "个人信息:" << endl;
    					cout << "管理员编号:" << endl;
    					cin >> p_num;
    					cout << endl;
    					cout << "管理员姓名:" << endl;
    					cin >> p_name;
    					cout << "管理员级别:" << endl;
    					cout << "(超级管理员、普通管理员)" << endl;
    					cin >> p_faculty;
    					cout << "请设置管理员登录密码:" << endl;
    					cin >> password;
    					m_index = -1;
    					for (auto iter : v_People) {
    						if (iter->getAccount().getId() == 3 && iter->getNum() == p_num) {
    							color(4);
    							m_index = 1;
    							cout << "该管理员编号已存在,请重新输入信息!" << endl;
    							break;
    						}
    					}
    				} while (m_index == 1);
    				
    				while (password.length() > 13) {
    					color(4);
    					cout << "密码长度小于 13位 请重新设置密码:";
    					cin >> password;
    				}
    				People* people = new People(index, password, p_num, p_name, p_faculty);
    				people->getAccount().chingePassword(password);
    				v_People.push_back(people);
    				break;
    			}
    			default:
    
    				break;
    			}
    		}
    		this->save_Pepple();
    		cout << "成功添加 " << add_number << " 个人信息!" << endl;
    	}
    	else {
    		color(4);
    		cout << "输入的数据有误!" << endl;
    	}
    	system("pause");
    	system("cls");
    }
    
    void PeopleManager::save_Pepple()
    {
    	ofstream ofs;//定义
    	ofs.open(PEOPLE, ios::out);//用输出的方式文件——写文件
    	//将个人的数据写入到文件中 
    	//vector<People*>::iterator inter = v_People.begin(); inter != v_People.end(); inter++
    	
    	for (auto inter : v_People)
    	{
    		string index;
    		if (!inter->get_v_book().empty()) {
    			index = "true";
    			ofs << index << " ";
    		}
    		else {
    			index = "false";
    			ofs << index << " ";
    		}
    		ofs << inter->getAccount().getId() << " " //判断身份的Id
    			<< inter->getNum() << " " //用于登录的学生账户
    			<< inter->getAccount().getPassword() << " " //登录密码
    			<< inter->getName() << " " //姓名
    			<< inter->getFaculty() << " " << endl;//院系
    			//<< inter->getMaxBookNum() << " ";//最大借书数量
    		if (!inter->get_v_book().empty()) {
    			for (auto i : inter->get_v_book())
    			{
    				ofs << "book" << " "
    					<< i->m_Id << " "
    					<< i->m_Name << " "
    					<< i->m_Press << " "
    					<< i->m_Price << " "
    					<< i->m_Page << " "
    					<< i->GetOtherProperties() << endl;
    			}
    		}
    		else {
    			ofs << endl;
    		}
    	}
    	//关闭文件
    	ofs.close();
    }
    
    //--------------------------------------------------------------->  初始化  有可能有问题!!!<-------------已优化
    void PeopleManager::init_Person()
    {
    	int rows = get_Rows_Number(PEOPLE);
    	int num = 1;//判断当前行
    	ifstream ifs;
    	ifs.open(PEOPLE, ios::in);
    	string index;
    	int p_Id; //人的id
    	int p_Num; //人的账户
    	string p_password;//密码
    	string p_name;//人的名字
    	string p_faculty;//院系
    	//int p_MaxBookNum;//最大借书数量
    	int d_Id;//书本编号
    	string d_Name;  //书本名字
    	string d_Press; //出版社
    	string d_Price; //图书价格
    	string d_Page_Words;  //图书页数或字数
    	string d_OtherProperties;//书的其他属性(Isbn,Issn,Format)
    	//vector<CColective*>::iterator iter = people->get_v_book().begin();
    	People* people = NULL;
    	while (ifs >> index) 
    	{
    		if (index == "true") 
    		{
    			if (people != NULL)
    			{
    				v_People.push_back(people);
    				people = NULL;
    				if (ifs >> p_Id && ifs >> p_Num && ifs >> p_password && ifs >> p_name && ifs >> p_faculty)
    				{
    					people = new People(p_Id, p_password, p_Num, p_name, p_faculty);
    				}
    			}
    			else {
    				people = NULL;
    				if (ifs >> p_Id && ifs >> p_Num && ifs >> p_password && ifs >> p_name && ifs >> p_faculty)
    				{
    					people = new People(p_Id, p_password, p_Num, p_name, p_faculty);
    				}
    			}
    		}
    
    		else if (index == "book")
    		{
    			if (ifs >> d_Id && ifs >> d_Name && ifs >> d_Press && ifs >> d_Price && ifs >> d_Page_Words && ifs >> d_OtherProperties)
    			{
    				CColective* book = NULL;
    				//截取读取的其他属性的前4个字符串。如果为"ISBN",则说明这一行数据是一般图书
    				if (d_OtherProperties.substr(0, 4) == "ISBN")
    				{
    					book = new CBooks(d_Id, d_Name, d_Press, d_Price, d_Page_Words);
    					book->SetOtherProperties(d_OtherProperties.substr(5, d_OtherProperties.size() - 1));
    				}
    				//截取读取的其他属性的前4个字符串。如果为"ISSN",则说明这一行数据是杂志
    				else if (d_OtherProperties.substr(0, 4) == "ISSN")
    				{
    					book = new CMagazine(d_Id, d_Name, d_Press, d_Price, d_Page_Words);
    					book->SetOtherProperties(d_OtherProperties.substr(5, d_OtherProperties.size() - 1));
    				}
    				//否则就是电子书类
    				else
    				{
    					book = new CEBook(d_Id, d_Name, d_Press, d_Price, d_Page_Words);
    					book->SetOtherProperties(d_OtherProperties);
    				}
    				//将读取的书本信息存入书本数组中
    				people->get_v_book().push_back(book);
    			}
    		}
    
    		else if(index == "false"){
    			while (ifs >> p_Id && ifs >> p_Num && ifs >> p_password && ifs >> p_name && ifs >> p_faculty)
    			{
    				if (p_Id == this->m_id && p_Num == this->m_Num && p_password == this->m_Possword && p_name == this->m_name && p_faculty == this->m_faculty) {
    					break;
    				}
    				else {
    					People* people = new People(p_Id, p_password, p_Num, p_name, p_faculty);
    					v_People.push_back(people);
    					break;
    				}
    			}
    		}
    		if (num == rows && people!= NULL) {
    			v_People.push_back(people);
    		}
    		num++;
    	}
    	
    
    	ifs.close();//关闭文件
    }
    
    void PeopleManager::show_People()
    {
    	for (auto people : v_People) {
    		people->display();
    		cout << endl;
    	}
    	system("pause");
    	system("cls");
    }
    
    
    void PeopleManager::show_Student()
    {
    	int index = 0;
    	for (vector<People*>::iterator iter = v_People.begin(); iter != v_People.end(); iter++) {
    		if ((*iter)->getAccount().getId() == 1) {
    			index++;
    			(*iter)->display();
    			cout << endl << endl;
    		}
    	}
    	if (index == 0) {
    		color(4);
    		cout << "暂无学生信息!" << endl;
    		system("pause");
    		system("cls");
    	}
    }
    
    void PeopleManager::find_People()
    {
    	if (v_People.size() == 0) {
    		color(4);
    		cout << "无人物信息!" << endl;
    	}
    	else
    	{
    		color(6);
    		cout << "可通过以下查找:" << endl;
    		cout << "1.学号/工号/编号" << endl
    			<< "2.姓名" << endl;
    		int select;//用户查找选择
    		cin >> select;
    		int people_Id = 0;
    		string people_Name = "";
    		int index = -1;
    		switch (select)
    		{
    		case 1:
    		{
    			color(6);
    			cout << "请输入学号/工号/编号:" << endl;
    			cin >> people_Id;
    			for (auto people : v_People) {
    				if (people_Id == people->getNum()) {
    					people->display();
    					index = 1;
    				}
    			}
    			break;
    		}
    		case 2:
    		{
    			color(6);
    			cout << "请输入姓名:" << endl;
    			cin >> people_Name;
    			for (auto people : v_People) {
    				if (people_Name == people->getName()) {
    					people->display();
    					index = 1;
    				}
    			}
    			break;
    		}
    		default:
    			color(4);
    			cout << "输入的数据有误!" << endl;
    			break;
    		}
    		if (index == -1) {
    			color(4);
    			cout << "未查询到相关信息!" << endl;
    		}
    		system("cls");
    	}
    }
    
    People& PeopleManager::find_People1()
    {
    	color(6);
    	cout << "可通过以下查找:" << endl;
    	cout << "1.学生学号" << endl
    		<< "2.学生姓名" << endl;
    	int select;//用户查找选择
    	cin >> select;
    	int people_Id = 0;
    	string people_Name = "";
    	int index = -1;
    	switch (select)
    	{
    	case 1:
    	{
    		color(6);
    		cout << "请输入学生学号:" << endl;
    		cin >> people_Id;
    		for (auto people : v_People) {
    			if (people_Id == people->getNum() && people->getAccount().getId() == 1) {
    				return *people;
    				index = 1;
    				break;
    			}
    		}
    		break;
    	}
    	case 2:
    	{
    		color(6);
    		cout << "请输入学生姓名:" << endl;
    		cin >> people_Name;
    		for (auto people : v_People) {
    			if (people_Name == people->getName() && people->getAccount().getId() == 1) {
    				return *people;
    				index = 1;
    				break;
    			}
    		}
    		break;
    	}
    	default:
    		color(4);
    		cout << "输入的数据有误!" << endl;
    		break;
    	}
    	if (index == -1) {
    		color(4);
    		cout << "未查询到相关信息!" << endl;
    	}
    }
    
    void PeopleManager::see_Student()
    {
    	while (true)
    	{
    		color(3);
    		cout << "\t\t---------------------" << endl;
    		cout << "\t\t|1、查看所有学生信息|" << endl;
    		cout << "\t\t---------------------" << endl;
    		cout << "\t\t|2、查找单个学生信息|" << endl;
    		cout << "\t\t---------------------" << endl;
    		cout << "\t\t|0、返回            |" << endl;
    		cout << "\t\t---------------------" << endl;
    		int i;
    		cin >> i;
    		switch (i)
    		{
    		case 0:
    		{
    			system("cls");
    			return;
    			break;
    		}
    
    		case 1:
    		{
    			system("cls");
    			show_Student();
    
    			break;
    		}
    		case 2:
    		{
    			find_People1().display();
    			break;
    		}
    		default:
    			color(4);
    			cout << "输入的数据有误!" << endl;
    			system("pause");
    			system("cls");
    			break;
    		}
    	}
    }
    
    People& PeopleManager::search_People(People *people)
    {
    	for (auto iter : v_People) {
    		if (iter->getAccount().getId() == people->getAccount().getId() && iter->getNum() == people->getNum()) {
    			return *iter;
    		}
    	}
    	// TODO: 在此处插入 return 语句
    }
    
    void PeopleManager::clear_People()
    {
    	color(4);
    	cout << "是否确认清空所有人物信息?" << endl;
    	cout << "1.是"
    		<< "\n2.否" << endl;
    	int select = -1;
    	cin >> select;
    	switch (select)
    	{
    	case 1:
    	{
    		color(4);
    		v_People.clear();
    		this->p_isPeople = false;
    		cout << "清空所有人物信息成功!" << endl;
    		this->save_Pepple();
    		break;
    	}
    	case 2:
    	{
    		color(4);
    		cout << "退出清空所有人物信息!" << endl;
    		return;
    	}
    	default:
    		color(4);
    		cout << "输入的数据有误!" << endl;
    		break;
    	}
    	
    	system("pause");
    	system("cls");
    }
    
    void PeopleManager::delete_People()
    {
    	if (!this->p_isPeople) {
    		color(4);
    		cout << "文件不存在或记录为空!" << endl;
    	}
    	else {
    		color(6);
    		cout << "可通过以下删除:" << endl;
    		cout << "1.学号/工号/编号" << endl
    			<< "2.姓名" << endl;
    		int select;//用户查找选择
    		cin >> select;
    		int people_Id = 0;
    		string people_Name = "";
    		int index = -1;
    		switch (select)
    		{
    		case 1:
    		{
    			color(6);
    			cout << "请输入学号/工号/编号:" << endl;
    			cin >> people_Id;
    			//(*iter)  解引用
    			for (vector<People*>::iterator iter = v_People.begin(); iter != v_People.end(); iter++) {
    				if ((*iter)->getNum() == people_Id) 
    				{
    					color(4);
    					index = 1;
    					(*iter)->display();
    					int i = -1;
    					cout << "是否确认删除该人物信息?" << endl;
    					cout << "1.是"
    						<< "\n2.否" << endl;
    					cin >> i;
    					switch (i)
    					{
    					case 1:
    					{
    						color(4);
    						v_People.erase(iter);
    						cout << "删除成功!" << endl;
    						this->save_Pepple();
    						break;
    					}
    					case 2:
    					{
    						color(4);
    						cout << "退出删除!" << endl;
    						return;
    						break;
    					}
    					default:
    						break;
    					}
    					system("pause");
    					system("cls");
    					break;
    				}
    			}
    			break;
    		}
    		case 2:
    		{
    			color(6);
    			cout << "请输入姓名:" << endl;
    			cin >> people_Name;
    			//(*iter)  解引用
    			for (vector<People*>::iterator iter = v_People.begin(); iter != v_People.end(); iter++) {
    				if ((*iter)->getName() == people_Name) {
    					color(4);
    					index = 1;
    					(*iter)->display();
    					int i = -1;
    					cout << "是否确认删除该人物信息?" << endl;
    					cout << "1.是"
    						<< "\n2.否" << endl;
    					cin >> i;
    					switch (i)
    					{
    					case 1:
    					{
    						color(4);
    						v_People.erase(iter);
    						cout << "删除成功!" << endl;
    						this->save_Pepple();
    						break;
    					}
    					case 2:
    					{
    						color(4);
    						cout << "退出删除!" << endl;
    						return;
    						break;
    					}
    					default:
    						break;
    					}
    				}
    			}
    			break;
    		}
    		default:
    		{
    			color(4);
    			cout << "输入的数据有误!" << endl;
    			break;
    		}
    		if (index == -1) {
    			color(4);
    			cout << "未查询到相关信息!" << endl;
    		}
    		}
    	}
    	system("pause");
    	system("cls");
    }
    
    People* PeopleManager::judge_Possword(int m_Id, string m_possword)
    {
    	for (vector<People*>::iterator iter = v_People.begin(); iter != v_People.end(); iter++) {
    		if ((*iter)->getNum() == m_Id && (*iter)->getAccount().getPassword() == m_possword) {
    			return *iter;
    			break;
    		}
    	}
    	return NULL;
    }
    
    void PeopleManager::student_Operation()
    {
    	color(6);
    	int m_num;
    	string m_possword;
    	cout << "请输入账号(学号) :";
    	cin >> m_num;
    	cout << endl;
    	cout << "请输入密码 :";
    	cin >> m_possword;
    	People* people = this->judge_Possword(m_num, m_possword);
    	if (people != NULL && people->getAccount().getId() == 1) {
    		cout << "登录成功!欢迎您!" << endl;
    		system("pause");
    		system("cls");
    		int c;
    		while (true)
    		{
    			color(3);
    			cout << "\t\t-----------------" << endl;
    			cout << "\t\t|1、查看自身信息|" << endl;
    			cout << "\t\t-----------------" << endl;
    			cout << "\t\t|2、修改个人密码|" << endl;
    			cout << "\t\t-----------------" << endl;
    			cout << "\t\t|3、 借阅书籍   |" << endl;
    			cout << "\t\t-----------------" << endl;
    			cout << "\t\t|4、 归还书籍   |" << endl;
    			cout << "\t\t-----------------" << endl;
    			cout << "\t\t|0、退出学生操作|" << endl;
    			cout << "\t\t-----------------" << endl;
    			cin >> c;
    			switch (c)
    			{
    			case 1:
    			{
    				people->display();
    				break;
    			}
    
    			case 2:
    			{
    				color(6);
    				cout << "输入新密码:" << endl;
    				cin >> m_possword;
    				people->getAccount().chingePassword(m_possword);
    				search_People(people).getAccount().chingePassword(m_possword);
    				cout << "修改成功" << endl;
    				system("pause");
    				system("cls");
    				break;
    			}
    			case 3:
    			{
    				system("cls");
    				people->borrowBook();
    				break;
    			}
    			case 4:
    			{
    				system("cls");
    				color(6);
    				if (people->get_v_book().size()==0) {
    					cout << "您还未借书" << endl;
    					system("pause");
    					system("cls");
    					break;
    				}
    				else {
    					people->return_Book();
    					break;
    				}
    			}
    			case 0:
    				system("cls");
    				return;
    				break;
    			}
    			this->save_Pepple();
    		}
    		
    	}
    	else {
    		color(4);
    		cout << "账户或密码错误!请重新输入" << endl;
    		system("pause");
    		system("cls");
    	}
    }
    
    void PeopleManager::teacher_Operation()
    {
    	color(6);
    	int m_num;
    	string m_possword;
    	cout << "请输入账号(工号) :";
    	cin >> m_num;
    	cout << endl;
    	cout << "请输入密码 :";
    	cin >> m_possword;
    	People* people = this->judge_Possword(m_num, m_possword);
    	if (people != NULL && people->getAccount().getId() == 2) {
    		cout << "登录成功!欢迎您!" << endl;
    		system("pause");
    		system("cls");
    		int c;
    		while (true)
    		{
    			color(3);
    			cout << "\t\t-----------------" << endl;
    			cout << "\t\t|1、查看自身信息|" << endl;
    			cout << "\t\t-----------------" << endl;
    			cout << "\t\t|2、查看学生信息|" << endl;
    			cout << "\t\t-----------------" << endl;
    			cout << "\t\t|3、修改个人密码|" << endl;
    			cout << "\t\t-----------------" << endl;
    			cout << "\t\t|4、 借阅书籍   |" << endl;
    			cout << "\t\t-----------------" << endl;
    			cout << "\t\t|5、 归还书籍   |" << endl;
    			cout << "\t\t-----------------" << endl;
    			cout << "\t\t|0、退出教师操作|" << endl;
    			cout << "\t\t-----------------" << endl;
    			cin >> c;
    			switch (c)
    			{
    			case 1:
    			{
    				people->display();
    				break;
    			}
    			case 2:
    			{
    				system("cls");
    				see_Student();
    				break;
    			}
    			case 3:
    			{
    				color(6);
    				cout << "输入新密码:" << endl;
    				cin >> m_possword;
    				people->getAccount().chingePassword(m_possword);
    				search_People(people).getAccount().chingePassword(m_possword);
    				cout << "修改成功" << endl;
    				system("pause");
    				system("cls");
    				break;
    			}
    			case 4:
    			{
    				system("cls");
    				people->borrowBook();
    				break;
    			}
    			case 5:
    			{
    				system("cls");
    				color(6);
    				if (people->get_v_book().size() == 0) {
    					cout << "您还未借书" << endl;
    					system("pause");
    					system("cls");
    					break;
    				}
    				else {
    					people->return_Book();
    					break;
    				}
    			}
    			case 0:
    				system("cls");
    				return;
    				break;
    			}
    			this->save_Pepple();
    		}
    
    	}
    	else {
    		color(4);
    		cout << "账户或密码错误!请重新输入" << endl;
    		system("pause");
    		system("cls");
    	}
    }
    
    void PeopleManager::manager_Operation()
    {
    	color(6);
    	int m_num;
    	string m_possword;
    	cout << "请输入账号(编号) :";
    	cin >> m_num;
    	cout << endl;
    	cout << "请输入密码 :";
    	cin >> m_possword;
    	People* people = this->judge_Possword(m_num, m_possword);
    	if (people != NULL && people->getAccount().getId() == 3) {
    		cout << "登录成功!欢迎您!" << endl;
    		system("pause");
    		system("cls");
    		int c;
    		while (true)
    		{
    			color(3);
    			cout << "\t\t-------------------" << endl;
    			cout << "\t\t|1、人物信息管理  |" << endl;
    			cout << "\t\t-------------------" << endl;
    			cout << "\t\t|2、图书信息管理  |" << endl;
    			cout << "\t\t-------------------" << endl;
    			cout << "\t\t|0、退出管理员操作|" << endl;
    			cout << "\t\t-------------------" << endl;
    			cin >> c;
    			switch (c)
    			{
    			case 1:
    			{
    				system("cls");
    				people_Info_Manage(*people);
    				system("cls");
    				break;
    			}
    			case 2:
    			{
    				system("cls");
    				book_Info_Manage(LM);
    				break;
    			}
    			case 0:
    				system("cls");
    				return;
    				break;
    			}
    			this->save_Pepple();
    		}
    
    	}
    	else {
    		color(4);
    		cout << "账户或密码错误!请重新输入" << endl;
    		system("pause");
    		system("cls");
    	}
    }
    
    void PeopleManager::people_Info_Manage(People& people)
    {
    	while (true)
    	{
    		color(3);
    		cout << "\t\t-----------------" << endl;
    		cout << "\t\t|1、查看自身信息|" << endl;
    		cout << "\t\t-----------------" << endl;
    		cout << "\t\t|2、查看学生信息|" << endl;
    		cout << "\t\t-----------------" << endl;
    		cout << "\t\t|3、查看教师信息|" << endl;
    		cout << "\t\t-----------------" << endl;
    		cout << "\t\t|4、添加人物信息|" << endl;
    		cout << "\t\t-----------------" << endl;
    		cout << "\t\t|5、模糊搜索信息|" << endl;
    		cout << "\t\t-----------------" << endl;
    		cout << "\t\t|6、重置人物密码|" << endl;
    		cout << "\t\t-----------------" << endl;
    		cout << "\t\t|7、修改个人密码|" << endl;
    		cout << "\t\t-----------------" << endl;
    		cout << "\t\t|8、删除人物信息|" << endl;
    		cout << "\t\t-----------------" << endl;
    		cout << "\t\t|9、清空人物信息|" << endl;
    		cout << "\t\t-----------------" << endl;
    		cout << "\t\t|0、    返回    |" << endl;
    		cout << "\t\t-----------------" << endl;
    		int c;
    		cin >> c;
    		switch (c)
    		{
    		case 1:
    		{
    			people.display();
    			system("cls");
    			break;
    		}
    		case 2:
    		{
    			system("cls");
    			see_Student();
    			break;
    		}
    		case 3:
    		{
    			system("cls");
    			see_Teacher();
    			break;
    		}
    		case 4:
    		{
    			system("cls");
    			add_People();
    			break;
    		}
    		case 5:
    		{
    			system("cls");
    			find_People();
    			break;
    		}
    		case 6:
    		{
    			system("cls");
    			reset_Password();
    			break;
    		}
    		case 7:
    		{
    			color(6);
    			system("cls");
    			if (people.getNum() == 2003 && people.getFaculty() == "默认管理员") {
    				color(4);
    				cout << "默认管理员不支持修改自身密码!" << endl;
    				system("pause");
    				system("cls");
    				break;
    			}
    			string m_possword;
    			cout << "输入新密码:" << endl;
    			cin >> m_possword;
    			people.getAccount().chingePassword(m_possword);
    			search_People(&people).getAccount().chingePassword(m_possword);
    			cout << "修改成功" << endl;
    			system("pause");
    			system("cls");
    			break;
    		}
    		case 8:
    		{
    			system("cls");
    			delete_People();
    			system("pause");
    			system("cls");
    			break;
    		}
    		case 9:
    		{
    			system("cls");
    			clear_People();
    			break;
    		}
    		case 0:
    			//system("cls");
    			return;
    			break;
    		}
    		
    	}
    }
    
    void PeopleManager::see_Teacher()
    {
    	while (true)
    	{
    		color(3);
    		cout << "\t\t---------------------" << endl;
    		cout << "\t\t|1、查看所有教师信息|" << endl;
    		cout << "\t\t---------------------" << endl;
    		cout << "\t\t|2、查找单个教师信息|" << endl;
    		cout << "\t\t---------------------" << endl;
    		cout << "\t\t|0、返回            |" << endl;
    		cout << "\t\t---------------------" << endl;
    		int i;
    		cin >> i;
    		switch (i)
    		{
    		case 0:
    		{
    			system("cls");
    			return;
    			break;
    		}
    
    		case 1:
    		{
    			system("cls");
    			show_Teacher();
    			break;
    		}
    		case 2:
    		{
    			system("cls");
    			find_People2().display();
    			break;
    		}
    		default:
    			color(4);
    			cout << "输入的数据有误!" << endl;
    			break;
    		}
    	}
    }
    
    People& PeopleManager::find_People2()
    {
    	color(6);
    	cout << "可通过以下查找:" << endl;
    	cout << "1.教师工号" << endl
    		<< "2.教师姓名" << endl;
    	int select;//用户查找选择
    	cin >> select;
    	int people_Id = 0;
    	string people_Name = "";
    	int index = -1;
    	switch (select)
    	{
    	case 1:
    	{
    		color(6);
    		cout << "请输入教师工号:" << endl;
    		cin >> people_Id;
    		for (auto people : v_People) {
    			if (people_Id == people->getNum() && people->getAccount().getId() == 2) {
    				return *people;
    				index = 1;
    				break;
    			}
    		}
    		break;
    	}
    	case 2:
    	{
    		color(6);
    		cout << "请输入教师姓名:" << endl;
    		cin >> people_Name;
    		for (auto people : v_People) {
    			if (people_Name == people->getName() && people->getAccount().getId() == 2) {
    				return *people;
    				index = 1;
    				break;
    			}
    		}
    		break;
    	}
    	default:
    		color(4);
    		cout << "输入的数据有误!" << endl;
    		break;
    	}
    	if (index == -1) {
    		color(4);
    		cout << "未查询到相关信息!" << endl;
    	}
    }
    
    void PeopleManager::show_Teacher()
    {
    	int index = 0;
    	for (vector<People*>::iterator iter = v_People.begin(); iter != v_People.end(); iter++) {
    		if ((*iter)->getAccount().getId() == 2) {
    			index++;
    			(*iter)->display();
    			cout << endl;
    		}
    	}
    	if (!index) {
    		color(4);
    		cout << "暂无学教师信息!" << endl;
    		system("pause");
    		system("cls");
    	}
    }
    
    void PeopleManager::reset_Password()
    {
    	while (true)
    	{
    		color(3);
    		cout << "\t\t---------------------" << endl;
    		cout << "\t\t|1、  重置学生密码  |" << endl;
    		cout << "\t\t---------------------" << endl;
    		cout << "\t\t|2、  重置教师密码  |" << endl;
    		cout << "\t\t---------------------" << endl;
    		cout << "\t\t|0、     返回       |" << endl;
    		cout << "\t\t---------------------" << endl;
    		int i;
    		cin >> i;
    		switch (i)
    		{
    		case 0:
    		{
    			system("cls");
    			return;
    			break;
    		}
    
    		case 1:
    		{
    			color(6);
    			find_People1().getAccount().chingePassword("111111");
    			cout << "重置学生密码成功!" << endl;
    			cout << "默认密码:111111" << endl;
    			this->save_Pepple();
    			system("pause");
    			system("cls");
    			break;
    		}
    		case 2:
    		{
    			color(6);
    			find_People2().getAccount().chingePassword("222222");
    			cout << "重置学生密码成功!" << endl;
    			cout << "默认密码:222222" << endl;
    			system("pause");
    			system("cls");
    			this->save_Pepple();
    			break;
    		}
    		default:
    			color(4);
    			cout << "输入的数据有误!" << endl;
    			system("pause");
    			system("cls");
    			break;
    		}
    	}
    }
    
    void PeopleManager::book_Info_Manage(CLIbraryManager& LM)
    {
    	while (true)
    	{
    		color(3);
    		cout << "\t\t-----------------" << endl;
    		cout << "\t\t|1、  增加书本  |" << endl;
    		cout << "\t\t-----------------" << endl;
    		cout << "\t\t|2、  显示书本  |" << endl;
    		cout << "\t\t-----------------" << endl;
    		cout << "\t\t|3、  删除书本  |" << endl;
    		cout << "\t\t-----------------" << endl;
    		cout << "\t\t|4、  查找书本  |" << endl;
    		cout << "\t\t-----------------" << endl;
    		cout << "\t\t|5、  书本排序  |" << endl;
    		cout << "\t\t-----------------" << endl;
    		cout << "\t\t|6、  清空书本  |" << endl;
    		cout << "\t\t-----------------" << endl;
    		cout << "\t\t|0、    返回    |" << endl;
    		cout << "\t\t-----------------" << endl;
    		int c;
    		cin >> c;
    		switch (c)
    		{
    		case 0:
    		{
    			system("cls");
    			return;
    			break;
    		}
    		case 1:
    		{
    			LM.Add_Book();
    			break;
    		}
    		case 2:
    		{
    			LM.show_BookArray();
    			break;
    		}
    		case 3:
    		{
    			LM.delete_Book();
    			break;
    		}
    		case 4:
    		{
    			LM.find_Book();
    			break;
    		}
    		case 5:
    		{
    			LM.sort_BookArray();
    			break;
    		}
    		case 6:
    		{
    			LM.clear_Txt();
    			break;
    		}
    		default:
    		{
    			system("cls");
    			break;
    		}
    		}
    	}
    }
    
    PeopleManager::~PeopleManager()
    {
    	v_People.erase(v_People.begin());
    	//this->save_Pepple();
    	if (!v_People.empty()) {//释放内存
    		vector<People*> p;
    		v_People.swap(p);
    	}
    }
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • 234
    • 235
    • 236
    • 237
    • 238
    • 239
    • 240
    • 241
    • 242
    • 243
    • 244
    • 245
    • 246
    • 247
    • 248
    • 249
    • 250
    • 251
    • 252
    • 253
    • 254
    • 255
    • 256
    • 257
    • 258
    • 259
    • 260
    • 261
    • 262
    • 263
    • 264
    • 265
    • 266
    • 267
    • 268
    • 269
    • 270
    • 271
    • 272
    • 273
    • 274
    • 275
    • 276
    • 277
    • 278
    • 279
    • 280
    • 281
    • 282
    • 283
    • 284
    • 285
    • 286
    • 287
    • 288
    • 289
    • 290
    • 291
    • 292
    • 293
    • 294
    • 295
    • 296
    • 297
    • 298
    • 299
    • 300
    • 301
    • 302
    • 303
    • 304
    • 305
    • 306
    • 307
    • 308
    • 309
    • 310
    • 311
    • 312
    • 313
    • 314
    • 315
    • 316
    • 317
    • 318
    • 319
    • 320
    • 321
    • 322
    • 323
    • 324
    • 325
    • 326
    • 327
    • 328
    • 329
    • 330
    • 331
    • 332
    • 333
    • 334
    • 335
    • 336
    • 337
    • 338
    • 339
    • 340
    • 341
    • 342
    • 343
    • 344
    • 345
    • 346
    • 347
    • 348
    • 349
    • 350
    • 351
    • 352
    • 353
    • 354
    • 355
    • 356
    • 357
    • 358
    • 359
    • 360
    • 361
    • 362
    • 363
    • 364
    • 365
    • 366
    • 367
    • 368
    • 369
    • 370
    • 371
    • 372
    • 373
    • 374
    • 375
    • 376
    • 377
    • 378
    • 379
    • 380
    • 381
    • 382
    • 383
    • 384
    • 385
    • 386
    • 387
    • 388
    • 389
    • 390
    • 391
    • 392
    • 393
    • 394
    • 395
    • 396
    • 397
    • 398
    • 399
    • 400
    • 401
    • 402
    • 403
    • 404
    • 405
    • 406
    • 407
    • 408
    • 409
    • 410
    • 411
    • 412
    • 413
    • 414
    • 415
    • 416
    • 417
    • 418
    • 419
    • 420
    • 421
    • 422
    • 423
    • 424
    • 425
    • 426
    • 427
    • 428
    • 429
    • 430
    • 431
    • 432
    • 433
    • 434
    • 435
    • 436
    • 437
    • 438
    • 439
    • 440
    • 441
    • 442
    • 443
    • 444
    • 445
    • 446
    • 447
    • 448
    • 449
    • 450
    • 451
    • 452
    • 453
    • 454
    • 455
    • 456
    • 457
    • 458
    • 459
    • 460
    • 461
    • 462
    • 463
    • 464
    • 465
    • 466
    • 467
    • 468
    • 469
    • 470
    • 471
    • 472
    • 473
    • 474
    • 475
    • 476
    • 477
    • 478
    • 479
    • 480
    • 481
    • 482
    • 483
    • 484
    • 485
    • 486
    • 487
    • 488
    • 489
    • 490
    • 491
    • 492
    • 493
    • 494
    • 495
    • 496
    • 497
    • 498
    • 499
    • 500
    • 501
    • 502
    • 503
    • 504
    • 505
    • 506
    • 507
    • 508
    • 509
    • 510
    • 511
    • 512
    • 513
    • 514
    • 515
    • 516
    • 517
    • 518
    • 519
    • 520
    • 521
    • 522
    • 523
    • 524
    • 525
    • 526
    • 527
    • 528
    • 529
    • 530
    • 531
    • 532
    • 533
    • 534
    • 535
    • 536
    • 537
    • 538
    • 539
    • 540
    • 541
    • 542
    • 543
    • 544
    • 545
    • 546
    • 547
    • 548
    • 549
    • 550
    • 551
    • 552
    • 553
    • 554
    • 555
    • 556
    • 557
    • 558
    • 559
    • 560
    • 561
    • 562
    • 563
    • 564
    • 565
    • 566
    • 567
    • 568
    • 569
    • 570
    • 571
    • 572
    • 573
    • 574
    • 575
    • 576
    • 577
    • 578
    • 579
    • 580
    • 581
    • 582
    • 583
    • 584
    • 585
    • 586
    • 587
    • 588
    • 589
    • 590
    • 591
    • 592
    • 593
    • 594
    • 595
    • 596
    • 597
    • 598
    • 599
    • 600
    • 601
    • 602
    • 603
    • 604
    • 605
    • 606
    • 607
    • 608
    • 609
    • 610
    • 611
    • 612
    • 613
    • 614
    • 615
    • 616
    • 617
    • 618
    • 619
    • 620
    • 621
    • 622
    • 623
    • 624
    • 625
    • 626
    • 627
    • 628
    • 629
    • 630
    • 631
    • 632
    • 633
    • 634
    • 635
    • 636
    • 637
    • 638
    • 639
    • 640
    • 641
    • 642
    • 643
    • 644
    • 645
    • 646
    • 647
    • 648
    • 649
    • 650
    • 651
    • 652
    • 653
    • 654
    • 655
    • 656
    • 657
    • 658
    • 659
    • 660
    • 661
    • 662
    • 663
    • 664
    • 665
    • 666
    • 667
    • 668
    • 669
    • 670
    • 671
    • 672
    • 673
    • 674
    • 675
    • 676
    • 677
    • 678
    • 679
    • 680
    • 681
    • 682
    • 683
    • 684
    • 685
    • 686
    • 687
    • 688
    • 689
    • 690
    • 691
    • 692
    • 693
    • 694
    • 695
    • 696
    • 697
    • 698
    • 699
    • 700
    • 701
    • 702
    • 703
    • 704
    • 705
    • 706
    • 707
    • 708
    • 709
    • 710
    • 711
    • 712
    • 713
    • 714
    • 715
    • 716
    • 717
    • 718
    • 719
    • 720
    • 721
    • 722
    • 723
    • 724
    • 725
    • 726
    • 727
    • 728
    • 729
    • 730
    • 731
    • 732
    • 733
    • 734
    • 735
    • 736
    • 737
    • 738
    • 739
    • 740
    • 741
    • 742
    • 743
    • 744
    • 745
    • 746
    • 747
    • 748
    • 749
    • 750
    • 751
    • 752
    • 753
    • 754
    • 755
    • 756
    • 757
    • 758
    • 759
    • 760
    • 761
    • 762
    • 763
    • 764
    • 765
    • 766
    • 767
    • 768
    • 769
    • 770
    • 771
    • 772
    • 773
    • 774
    • 775
    • 776
    • 777
    • 778
    • 779
    • 780
    • 781
    • 782
    • 783
    • 784
    • 785
    • 786
    • 787
    • 788
    • 789
    • 790
    • 791
    • 792
    • 793
    • 794
    • 795
    • 796
    • 797
    • 798
    • 799
    • 800
    • 801
    • 802
    • 803
    • 804
    • 805
    • 806
    • 807
    • 808
    • 809
    • 810
    • 811
    • 812
    • 813
    • 814
    • 815
    • 816
    • 817
    • 818
    • 819
    • 820
    • 821
    • 822
    • 823
    • 824
    • 825
    • 826
    • 827
    • 828
    • 829
    • 830
    • 831
    • 832
    • 833
    • 834
    • 835
    • 836
    • 837
    • 838
    • 839
    • 840
    • 841
    • 842
    • 843
    • 844
    • 845
    • 846
    • 847
    • 848
    • 849
    • 850
    • 851
    • 852
    • 853
    • 854
    • 855
    • 856
    • 857
    • 858
    • 859
    • 860
    • 861
    • 862
    • 863
    • 864
    • 865
    • 866
    • 867
    • 868
    • 869
    • 870
    • 871
    • 872
    • 873
    • 874
    • 875
    • 876
    • 877
    • 878
    • 879
    • 880
    • 881
    • 882
    • 883
    • 884
    • 885
    • 886
    • 887
    • 888
    • 889
    • 890
    • 891
    • 892
    • 893
    • 894
    • 895
    • 896
    • 897
    • 898
    • 899
    • 900
    • 901
    • 902
    • 903
    • 904
    • 905
    • 906
    • 907
    • 908
    • 909
    • 910
    • 911
    • 912
    • 913
    • 914
    • 915
    • 916
    • 917
    • 918
    • 919
    • 920
    • 921
    • 922
    • 923
    • 924
    • 925
    • 926
    • 927
    • 928
    • 929
    • 930
    • 931
    • 932
    • 933
    • 934
    • 935
    • 936
    • 937
    • 938
    • 939
    • 940
    • 941
    • 942
    • 943
    • 944
    • 945
    • 946
    • 947
    • 948
    • 949
    • 950
    • 951
    • 952
    • 953
    • 954
    • 955
    • 956
    • 957
    • 958
    • 959
    • 960
    • 961
    • 962
    • 963
    • 964
    • 965
    • 966
    • 967
    • 968
    • 969
    • 970
    • 971
    • 972
    • 973
    • 974
    • 975
    • 976
    • 977
    • 978
    • 979
    • 980
    • 981
    • 982
    • 983
    • 984
    • 985
    • 986
    • 987
    • 988
    • 989
    • 990
    • 991
    • 992
    • 993
    • 994
    • 995
    • 996
    • 997
    • 998
    • 999
    • 1000
    • 1001
    • 1002
    • 1003
    • 1004
    • 1005
    • 1006
    • 1007
    • 1008
    • 1009
    • 1010
    • 1011
    • 1012
    • 1013
    • 1014
    • 1015
    • 1016
    • 1017
    • 1018
    • 1019
    • 1020
    • 1021
    • 1022
    • 1023
    • 1024
    • 1025
    • 1026
    • 1027
    • 1028
    • 1029
    • 1030
    • 1031
    • 1032
    • 1033
    • 1034
    • 1035
    • 1036
    • 1037
    • 1038
    • 1039
    • 1040
    • 1041
    • 1042
    • 1043
    • 1044
    • 1045
    • 1046
    • 1047
    • 1048
    • 1049
    • 1050
    • 1051
    • 1052
    • 1053
    • 1054
    • 1055
    • 1056
    • 1057
    • 1058
    • 1059
    • 1060
    • 1061
    • 1062
    • 1063
    • 1064
    • 1065
    • 1066
    • 1067
    • 1068
    • 1069
    • 1070
    • 1071
    • 1072
    • 1073
    • 1074
    • 1075
    • 1076
    • 1077
    • 1078
    • 1079
    • 1080
    • 1081
    • 1082
    • 1083
    • 1084
    • 1085
    • 1086
    • 1087
    • 1088
    • 1089
    • 1090
    • 1091
    • 1092
    • 1093
    • 1094
    • 1095
    • 1096
    • 1097
    • 1098
    • 1099
    • 1100
    • 1101
    • 1102
    • 1103
    • 1104
    • 1105
    • 1106
    • 1107
    • 1108
    • 1109
    • 1110
    • 1111
    • 1112
    • 1113
    • 1114
    • 1115
    • 1116
    • 1117
    • 1118
    • 1119
    • 1120
    • 1121
    • 1122
    • 1123
    • 1124
    • 1125
    • 1126
    • 1127
    • 1128
    • 1129
    • 1130
    • 1131
    • 1132
    • 1133
    • 1134
    • 1135
    • 1136
    • 1137
    • 1138
    • 1139
    • 1140
    • 1141
    • 1142
    • 1143
    • 1144
    • 1145
    • 1146
    • 1147
    • 1148
    • 1149
    • 1150
    • 1151
    • 1152
    • 1153
    • 1154
    • 1155
    • 1156
    • 1157
    • 1158
    • 1159
    • 1160
    • 1161
    • 1162
    • 1163
    • 1164
    • 1165
    • 1166
    • 1167
    • 1168
    • 1169
    • 1170
    • 1171
    • 1172
    • 1173
    • 1174
    • 1175
    • 1176
    • 1177
    • 1178
    • 1179
    • 1180
    • 1181
    • 1182
    • 1183
    • 1184
    • 1185
    • 1186
    • 1187
    • 1188
    • 1189
    • 1190
    • 1191
    • 1192
    • 1193
    • 1194
    • 1195
    • 1196
    • 1197
    • 1198
    • 1199
    • 1200
    • 1201
    • 1202
    • 1203
    • 1204
    • 1205
    • 1206
    • 1207
    • 1208
    • 1209
    • 1210
    • 1211
    • 1212
    • 1213
    • 1214
    • 1215
    • 1216
    • 1217
    • 1218
    • 1219
    • 1220
    • 1221
    • 1222
    • 1223
    • 1224
    • 1225
    • 1226
    • 1227
    • 1228
    • 1229
    • 1230
    • 1231
    • 1232
    • 1233
    • 1234
    • 1235
    • 1236
    • 1237
    • 1238
    • 1239
    • 1240
    • 1241
    • 1242
    • 1243
    • 1244
    • 1245
    • 1246
    • 1247
    • 1248
    • 1249
    • 1250
    • 1251
    • 1252
    • 1253
    • 1254
    • 1255
    • 1256
    • 1257
    • 1258
    • 1259
    • 1260
    • 1261
    • 1262
    • 1263
    • 1264
    • 1265
    • 1266
    • 1267
    • 1268
    • 1269
    • 1270
    • 1271
    • 1272
    • 1273
    • 1274
    • 1275
    • 1276
    • 1277
    • 1278
    • 1279
    • 1280
    • 1281
    • 1282
    • 1283
    • 1284
    • 1285
    • 1286
    • 1287
    • 1288
    • 1289
    • 1290
    • 1291
    • 1292
    • 1293
    • 1294
    • 1295
    • 1296
    • 1297
    • 1298
    • 1299
    • 1300
    • 1301
    • 1302
    • 1303
    • 1304
    • 1305
    • 1306
    • 1307
    • 1308
    • 1309
    • 1310
    • 1311
    • 1312
    • 1313
    • 1314
    • 1315
    • 1316
    • 1317
    • 1318
    • 1319
    • 1320
    • 1321
    • 1322
    • 1323
    • 1324
    • 1325
    • 1326
    • 1327
    • 1328
    • 1329
    • 1330
    • 1331
    • 1332

    //书本基类 CColective.h

    #pragma once
    //书本基类
    #include <iostream>
    #include <string>
    using namespace std;
    class CColective
    {
    public:
    	int m_Id;//书本编号
    	string m_Name;  //书本名字
    	string m_Press; //出版社
    	string m_Price; //图书价格
    	string m_Page;  //图书页数
    
    	virtual void showInfo() = 0;	//显示书本信息,多态
    	virtual string getClass() = 0;  //获取书本类型
    	virtual void SetOtherProperties(string Other_Properties) = 0;//设置其他属性
    	virtual string GetOtherProperties() = 0;//获得其他属性
    	virtual bool Judge(string OtherProperties) = 0;
    };
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22

    //一般图书类 定义 CBooks.h

    #pragma once
    //一般图书类
    #include "CColective.h"
    #include <iostream>
    #include <string>
    using namespace std;
    
    class CBooks : public CColective
    {
    private:
    	string m_Isbn = "ISBN-";  //书本Isbn码
    	int njudge;//判断Ibsn码合法性
    public:
    	CBooks();//无参构造函数
    	CBooks(int Id, string Name, string Press, string Price, string Page); //有参构造函数
    	~CBooks();
    	bool Judge(string OtherProperties);
    
    	//显示书本信息
    	virtual void showInfo();
    	//获取书本类型
    	virtual string getClass();
    	//设置其他属性
    	virtual void SetOtherProperties(string Isbn);
    	virtual string GetOtherProperties();//获得其他属性
    };
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28

    //一般图书类 实现 CBooks.cpp

    #include "CBooks.h"
    
    CBooks::CBooks()
    {
    	this->m_Id = 0;
    	this->m_Name = "";
    	this->m_Press = "";
    	this->m_Price = "";
    	this->m_Page = "";
    }
    
    CBooks::CBooks(int Id, string Name, string Press, string Price, string Page)
    {
    	this->m_Id = Id;
    	this->m_Name = Name;
    	this->m_Press = Press;
    	this->m_Price = Price;
    	this->m_Page = Page;
    }
    
    CBooks::~CBooks()
    {
    
    }
    
    bool CBooks::Judge(string OtherProperties)
    {
    	int tmp = 0;
    	int ss[20] = { 0 };
    	for (int i = 0, j = 0; i < OtherProperties.length(); i++) {
    		if (OtherProperties.substr(i, 1) >= "0" && OtherProperties.substr(i, 1) <= "9") {
    			ss[j] = atoi(OtherProperties.substr(i, 1).c_str());
    			j++;
    		}
    	}
    	for (int i = 0; i < 12; i++) {
    		if (i % 2 == 0)
    		{
    			tmp += ss[i] * 1;
    		}
    		else {
    			tmp += ss[i] * 3;
    		}
    	}
    	if (tmp % 10 == 0 && tmp % 10 == ss[12] || 10 - (tmp % 10) == ss[12])
    	{
    		return true;
    	}
    	else
    	{
    		return false;
    	}
    }
    
    void CBooks::showInfo()
    {
    	cout << "书本编号:" << this->m_Id
    		<< "\t书本类型:" << this->getClass()
    		<< "\t书本名称:" << this->m_Name
    		<< "\t书本出版社:" << this->m_Press
    		<< "\t书本价格:" << this->m_Price
    		<< "\t书本页数:" << this->m_Page
    		<< "\t其他属性——书本Ibsn号:" << this->m_Isbn;
    }
    string CBooks::getClass()
    {
    	return string("一般图书");
    }
    
    
    void CBooks::SetOtherProperties(string Isbn)
    {
    	this->m_Isbn.append(Isbn);//append(),追加函数,将两个string字符串拼接在一起
    }
    
    string CBooks::GetOtherProperties()
    {
    	return this->m_Isbn;
    	return string();
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81

    //电子书类 定义 CEBook.h

    #pragma once
    //电子书类
    #include "CColective.h"
    #include <iostream>
    #include <string>
    using namespace std;
    
    class CEBook : public CColective
    {
    private:
    	string m_Format; //电子书的格式(txt、pdf、epub、azw3、kindle)
    public:
    	CEBook();
    	CEBook(int Id, string Name, string Press, string Price, string Words);//Words电子书的字数
    	~CEBook();
    
    	//显示书本信息
    	virtual void showInfo();
    	//获取书本类型
    	virtual string getClass();
    	//设置其他属性
    	virtual void SetOtherProperties(string Format);
    	virtual string GetOtherProperties();//获得其他属性
    	bool Judge(string OtherProperties);
    };
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27

    //电子书类 实现 CEBook.cpp

    #include "CEBook.h"
    
    CEBook::CEBook()
    {
    	this->m_Id = 0;
    	this->m_Name = "";
    	this->m_Press = "";
    	this->m_Price = "";
    	this->m_Page = "";
    }
    
    CEBook::CEBook(int Id, string Name, string Press, string Price, string Words)
    {
    	this->m_Format = "";
    	this->m_Id = Id;
    	this->m_Name = Name;
    	this->m_Press = Press;
    	this->m_Price = Price;
    	this->m_Page = Words;
    }
    
    CEBook::~CEBook()
    {
    }
    
    void CEBook::showInfo()
    {
    	cout << "书本编号:" << this->m_Id
    		<< "\t书本类型:" << this->getClass()
    		<< "\t书本名称:" << this->m_Name
    		<< "\t书本出版社:" << this->m_Press
    		<< "\t书本价格:" << this->m_Price
    		<< "\t书本字数:" << this->m_Page
    		<< "\t其他属性——书本格式:格式为 . " << this->m_Format;
    }
    
    string CEBook::getClass()
    {
    	return string("电子书");
    }
    
    void CEBook::SetOtherProperties(string Format)
    {
    	this->m_Format.append(Format);
    }
    
    string CEBook::GetOtherProperties()
    {
    	return this->m_Format;
    	return string();
    }
    
    bool CEBook::Judge(string OtherProperties)
    {
    	return false;
    }
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58

    //杂志书籍类 定义 CMagazine.h

    #pragma once
    //杂志书籍类
    #include "CColective.h"
    #include <iostream>
    #include <string>
    
    using namespace std;
    class CMagazine : public CColective
    {
    private:
    	string m_Issn = "ISSN-";//杂志期刊号 格式:ISSN XXXX-XXXX
    public:
    	CMagazine();
    	CMagazine(int Id, string Name, string Press, string Price, string Page);
    	~CMagazine();
    
    	//显示书本信息
    	virtual void showInfo();
    	//获取书本类型
    	virtual string getClass();
    	//设置其他属性
    	virtual void SetOtherProperties(string Issn);
    	virtual string GetOtherProperties();//获得其他属性
    
    	bool Judge(string OtherProperties);
    };
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28

    //杂志书籍类 实现 CMagazine.cpp

    #include "CMagazine.h"
    
    CMagazine::CMagazine()
    {
    	this->m_Id = 0;
    	this->m_Name = "";
    	this->m_Press = "";
    	this->m_Price = "";	
    	this->m_Page = "";
    }
    
    CMagazine::CMagazine(int Id, string Name, string Press, string Price, string Page)
    {
    	this->m_Id = Id;
    	this->m_Name = Name;
    	this->m_Press = Press;
    	this->m_Price = Price;
    	this->m_Page = Page;
    }
    
    CMagazine::~CMagazine()
    {
    }
    
    void CMagazine::showInfo()
    {
    	cout << "书本编号:" << this->m_Id
    		<< "\t书本类型:" << this->getClass()
    		<< "\t书本名称:" << this->m_Name
    		<< "\t书本出版社:" << this->m_Press
    		<< "\t书本价格:" << this->m_Price
    		<< "\t书本页数:" << this->m_Page
    		<< "\t其他属性——书本Issn号:" << this->m_Issn;
    }
    
    string CMagazine::getClass()
    {
    
    	return string("杂志书籍");
    }
    
    void CMagazine::SetOtherProperties(string Issn)
    {
    	this->m_Issn.append(Issn);//append(),追加函数,将两个string字符串拼接在一起
    }
    
    string CMagazine::GetOtherProperties()
    {
    	return this->m_Issn;
    	return string();
    }
    
    bool CMagazine::Judge(string OtherProperties)
    {
    	return false;
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57

    图书管理类 定义 CLIbraryManager.h

    #pragma once //防止头文件重复包含
    //管理类
    //管理内容:
    //与用户的沟通菜单界面
    //对书本的增、删、查等操作
    //与文件的读写交互
    
    #include "CColective.h"
    #include "CBooks.h"		//一般图书
    #include "CEBook.h"		//电子书
    #include "CMagazine.h"	//杂志
    
    #include<cstdlib>		//system 不明确	
    #include <fstream>		//文件流头文件
    #define FILENAME "BookFile.txt"
    
    using namespace std;
    
    class CLIbraryManager
    {
    public:
    	CLIbraryManager();//构造函数
    
    	//菜单显示
    	void Show_Menu();
    
    	//0.退出系统
    	void ExitSystem();
    
    	//1.添加实现
    	int m_BookNum;//记录书本的数量
    	CColective** m_BookArray;//书本数组指针
    	void Add_Book();
    	
    	//保存文件
    	void Save();
    
    	//设置标志判断最开始文件是否存在
    	bool m_isFile;
    
    	//统计文件中已有书本数量
    	int Get_BookNum();
    
    	//初始化文件中已有书本数组、数量
    	void init_Book();
    
    	//2.显示书本
    	void show_BookArray();
    
    	//4.查找实现
    	void find_Book();//函数
    
    	//6.清空txt实现
    	void clear_Txt();
    
    	//3.删除书本信息实现
    	void delete_Book();//函数
    	int isBook(int Id);
    	int isBook(string name);
    	
    	//5.按照书本序号排序
    	void sort_BookArray();
    
    	//通过编号返回书本
    	CColective* find_By_Num(int Id);
    	//通过书名返回书本
    	CColective* find_By_Name(string name);
    
    	~CLIbraryManager();//析构函数
    };
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72

    图书管理类 实现 CLIbraryManager.h

    #include "CLIbraryManager.h"
    #include<cstdlib>
    using namespace std;
    CLIbraryManager::CLIbraryManager()
    {
    	ifstream ifs;
    	ifs.open(FILENAME, ios::in);//打开文件
    
    	//文件不存在
    	if (!ifs.is_open())//ifs.is_open()返回值为bool类型,如果能打开返回true
    	{
    		this->m_isFile = false;//文件不存在,将m_isFile赋值为false
    		this->m_BookNum = 0;//初始化书的本数
    		this->m_BookArray = NULL;//初始化书数组指针
    		ifs.close();
    		return;
    	}
    
    	//文件存在,但数据为空
    	char ch;
    	ifs >> ch;//传入空字符
    	if (ifs.eof())//如果文件是空,则返回true
    	{
    		this->m_isFile = false;//文件存在,但无数据,将m_isFile赋值为false
    		this->m_BookNum = 0;//初始化书的本数
    		this->m_BookArray = NULL;//初始化书数组指针
    		ifs.close();
    		return;
    	}
    
    	//文件存在且不为空
    	else if (!ifs.eof())
    	{
    		this->m_isFile = true;//文件存在且有数据,将m_isFile赋值为true
    		int num = this->Get_BookNum();
    		this->m_BookNum = num;
    		this->m_BookArray = new CColective* [this->m_BookNum];
    		//将读取的数据存入数组中
    		this->init_Book();
    	}
    }
    
    //显示菜单函数
    void CLIbraryManager::Show_Menu()
    {
    	cout << "————————————————————————" << endl;
    	cout << "——————  欢迎使用图书管理系统!——————" << endl;
    	cout << "———————— 0.退出管理程序 ————————" << endl;
    	cout << "———————— 1.增加书本信息 ————————" << endl;
    	cout << "———————— 2.显示书本信息 ————————" << endl;
    	cout << "———————— 3.删除书本信息 ————————" << endl;
    	cout << "———————— 4.查找书本信息 ————————" << endl;
    	cout << "———————— 5.按照编号排序 ————————" << endl;
    	cout << "———————— 6.清空所有文档 ————————" << endl;
    	cout << "————————————————————————" << endl;
    	cout << endl;
    
    }
    
    //退出程序函数
    void CLIbraryManager::ExitSystem()
    {
    	cout << "欢迎下次使用!" << endl;
    	system("pause");
    	exit(0);
    }
    
    //增加书函数
    void CLIbraryManager::Add_Book()
    {
    	cout << "请输入添加书本的数量:" << endl;
    	int add_number = 0;
    	cin >> add_number;//接收用户输入的大小
    	if (add_number > 0) //输入大于零才执行增加操作
    	{
    		//执行添加
    		int newSize = this->m_BookNum + add_number;//计算需要开辟的空间大小,新的数量 = 原来记录的 + 新输入的
    		CColective** newspace = new CColective * [newSize];//分配空间
    
    		//如果原来的数组不为空,则添加到新开辟的数组中
    		if (this->m_BookArray != NULL)
    		{
    			for (int i = 0; i < this->m_BookNum; i++)
    			{
    				newspace[i] = this->m_BookArray[i];
    			}
    		}
    
    		//添加新数据
    		for (int i = 0; i < add_number; i++)
    		{
    			int d_Id = 0;//书本编号
    			string d_Name;  //书本名字
    			string d_Press; //出版社
    			string d_Price; //图书价格
    			string d_Page_Words;  //图书页数或字数
    			string d_OtherProperties;//书的其他属性(Isbn,Issn,Format)
    
    			cout << "请选择要添加的类型:" << endl;
    			cout << "1.一般图书" << endl;
    			cout << "2.杂志" << endl;
    			cout << "3.电子书" << endl;
    			int select;//用户的选择
    			cin >> select;
    
    			CColective* book = NULL;//创建book形参
    			cout << "请输入第" << i + 1 << "本书编号:" << endl;
    			cin >> d_Id;
    			cout << endl;
    			cout << "请输入第" << i + 1 << "本书书名:" << endl;
    			cin >> d_Name;
    			cout << endl;
    			cout << "请输入第" << i + 1 << "本书出版社:" << endl;
    			cin >> d_Press;
    			cout << endl;
    			cout << "请输入第" << i + 1 << "本书价格:" << endl;
    			cin >> d_Price;
    			cout << endl;
    			
    			switch (select)
    			{
    			case 1:
    			{
    				//{开始  模块一:屏蔽一般图书ISBN号检测
    				//cout << "请输入第" << i + 1 << "本书页数:" << endl;//一般图书的页数
    				//cin >> d_Page_Words;
    				//cout << endl;
    				//book = new CBooks(d_Id, d_Name, d_Press, d_Price, d_Page_Words);
    				//cout << "请输入第" << i + 1 << "本书Ibsn号:" << endl;
    				//cin >> d_OtherProperties;
    				//结束}
    				
    	
    				//{开始  模块二:一般图书ISBN号检测
    				do
    				{
    					cout << "请输入第" << i + 1 << "本书页数:" << endl;//一般图书的页数
    					cin >> d_Page_Words;
    					cout << endl;
    					book = new CBooks(d_Id, d_Name, d_Press, d_Price, d_Page_Words);
    					cout << "请输入第" << i + 1 << "本书Ibsn号:" << endl;
    					cin >> d_OtherProperties;
    					if (!book->Judge(d_OtherProperties)) {
    						cout << "ISBN码不合法!" << endl
    							<< "请重新输入:" << endl << endl;
    						cout << "请输入第" << i + 1 << "本书编号:" << endl;
    						cin >> d_Id;
    						cout << endl;
    						cout << "请输入第" << i + 1 << "本书书名:" << endl;
    						cin >> d_Name;
    						cout << endl;
    						cout << "请输入第" << i + 1 << "本书出版社:" << endl;
    						cin >> d_Press;
    						cout << endl;
    						cout << "请输入第" << i + 1 << "本书价格:" << endl;
    						cin >> d_Price;
    					}
    				} while (!book->Judge(d_OtherProperties));
    				//结束}
    				cout << endl;
    				book->SetOtherProperties(d_OtherProperties);
    				break;
    			}
    				
    			case 2:
    			{
    				cout << "请输入第" << i + 1 << "本书页数:" << endl;
    				cin >> d_Page_Words;
    				cout << endl;
    				book = new CMagazine(d_Id, d_Name, d_Press, d_Price, d_Page_Words);
    				cout << "请输入第" << i + 1 << "本书Issn号:" << endl;
    				cin >> d_OtherProperties;
    				cout << endl;
    				book->SetOtherProperties(d_OtherProperties);
    				break;
    			}
    				
    			case 3:
    			{
    				cout << "请输入第" << i + 1 << "本书字数:" << endl;//电子书的字数
    				cin >> d_Page_Words;
    				cout << endl;
    				book = new CEBook(d_Id, d_Name, d_Press, d_Price, d_Page_Words);
    				cout << "请输入第" << i + 1 << "本书格式:" << endl;//电子书的格式
    				cout << "电子书的格式有:txt、pdf、epub、azw3、kindle" << endl;
    				cin >> d_OtherProperties;
    				cout << endl;
    				book->SetOtherProperties(d_OtherProperties);
    				break;
    			}
    				
    			default:
    				break;
    			}
    			//将创建好的书本增加到数组中
    			newspace[this->m_BookNum + i] = book;
    		}
    		delete[]this->m_BookArray;//释放原来的空间
    		this->m_BookArray = newspace;//将新的空间指向m_BookArrary
    		this->m_BookNum = newSize;//更新新的书本数量
    
    		//保存数据到文件中
    		//this->delete_txt();
    		this->Save();
    		this->m_isFile = true;//添加成功,则说明文件创建成功且数据不为空
    		cout << "成功添加" << add_number << "本新书" << endl;
    
    	}
    	else
    	{
    		cout << "输入的数据有误!" << endl;
    	}
    	system("pause");
    	system("cls");
    }
    
    //保存书本数据
    void CLIbraryManager::Save()
    {
    	ofstream ofs;//定义
    	ofs.open(FILENAME, ios::out);//用输出的方式文件——写文件
    	//将每本书的数据写入到文件中
    	
    	for (int i = 0; i < this->m_BookNum; i++)
    	{
    		ofs << this->m_BookArray[i]->m_Id << " "
    			<< this->m_BookArray[i]->m_Name << " "
    			<< this->m_BookArray[i]->m_Press << " "
    			<< this->m_BookArray[i]->m_Price << " "
    			<< this->m_BookArray[i]->m_Page << " "
    			<< this->m_BookArray[i]->GetOtherProperties() << endl;
    	}
    	//关闭文件
    	ofs.close();
    }
    
    //获取文件中已有书本的数量
    int CLIbraryManager::Get_BookNum()
    {
    	int d_Id = 0;//书本编号
    	string d_Name;  //书本名字
    	string d_Press; //出版社
    	string d_Price; //图书价格
    	string d_Page_Words;  //图书页数或字数
    	string d_OtherProperties;//书的其他属性(Isbn,Issn,Format)
    
    	ifstream ifs;
    	ifs.open(FILENAME, ios::in);
    
    	int num = 0;
    	while (ifs >> d_Id && ifs >> d_Name && ifs >> d_Press && ifs >> d_Price && ifs >> d_Page_Words && ifs >> d_OtherProperties)
    	{
    		num++;
    	}
    
    	return num;
    }
    
    //初始化文件中已有书本数组、数量
    void CLIbraryManager::init_Book()
    {
    	ifstream ifs;
    	ifs.open(FILENAME, ios::in);
    	int d_Id;//书本编号
    	string d_Name;  //书本名字
    	string d_Press; //出版社
    	string d_Price; //图书价格
    	string d_Page_Words;  //图书页数或字数
    	string d_OtherProperties;//书的其他属性(Isbn,Issn,Format)
    
    	int index = 0;//记录数组位置
    	while (ifs >> d_Id && ifs >> d_Name && ifs >> d_Press && ifs >> d_Price && ifs >> d_Page_Words && ifs >> d_OtherProperties)
    	{
    		CColective* book = NULL;
    		
    		//截取读取的其他属性的前4个字符串。如果为"ISBN",则说明这一行数据是一般图书
    		if (d_OtherProperties.substr(0, 4) == "ISBN")
    		{
    			book = new CBooks(d_Id, d_Name, d_Press, d_Price, d_Page_Words);
    			book->SetOtherProperties(d_OtherProperties.substr(5, d_OtherProperties.size() - 1));
    		}
    
    		//截取读取的其他属性的前4个字符串。如果为"ISSN",则说明这一行数据是杂志
    		else if (d_OtherProperties.substr(0, 4) == "ISSN")
    		{
    			book = new CMagazine(d_Id, d_Name, d_Press, d_Price, d_Page_Words);
    			book->SetOtherProperties(d_OtherProperties.substr(5, d_OtherProperties.size() - 1));
    		}
    
    		//否则就是电子书类
    		else
    		{
    			book = new CEBook(d_Id, d_Name, d_Press, d_Price, d_Page_Words);
    			book->SetOtherProperties(d_OtherProperties);
    		}
    
    		//将读取的书本信息存入书本数组中
    		this->m_BookArray[index] = book;
    		index++;
    	}
    
    	ifs.close();//关闭文件
    }
    
    //显示函数
    void CLIbraryManager::show_BookArray()
    {
    	if (this->m_BookNum == 0)
    	{
    		cout << "无书本信息!" << endl;
    	}
    	else
    	{
    		for (int i = 0; i < this->Get_BookNum(); i++)
    		{
    			this->m_BookArray[i]->showInfo();
    			cout << endl << endl;//利用函数的多态,调用派生类显示函数
    		}
    	}
    
    	system("pause");
    	system("cls");
    	
    }
    
    //查找函数
    void CLIbraryManager::find_Book()
    {
    	if (this->m_BookNum == 0)
    	{
    		cout << "无书本信息!" << endl;
    	}
    	else
    	{
    		cout << "可通过以下查找:" << endl;
    		cout << "1.书本编号" << endl
    			<< "2.书本名称" << endl;
    		int select;//用户查找选择
    		cin >> select;
    		int Id = 0;
    		string book_name = "";
    		switch (select)
    		{
    		case 1:
    		{
    			cout << "请输入书本编号:" << endl;
    			cin >> Id;
    			for (int i = 0; i < this->m_BookNum; i++)
    			{
    				if (i == this->m_BookNum - 1 && this->m_BookArray[i]->m_Id != Id) {
    					cout << "未查询到该书信息!" << endl;
    				}
    				if (this->m_BookArray[i]->m_Id == Id) {
    					cout << "该书本信息为:" << endl;
    					this->m_BookArray[i]->showInfo();
    					cout << endl;
    					break;
    				}
    			}
    			break;
    		}
    			
    		case 2:
    		{
    			cout << "请输入书本名称:" << endl;
    			cin >> book_name;
    			for (int i = 0; i < this->m_BookNum; i++)
    			{
    				if (i == this->m_BookNum - 1 && this->m_BookArray[i]->m_Name != book_name) {
    					cout << "未查询到该书信息!" << endl;
    				}
    				if (this->m_BookArray[i]->m_Name == book_name) {
    					cout << "该书本信息为:" << endl;
    					this->m_BookArray[i]->showInfo();
    					cout << endl;
    					break;
    				}
    			}
    			break;
    		}
    			
    		default:
    			break;
    		}
    	}
    	system("pause");
    	system("cls");
    }
    
    //清空文档函数
    void CLIbraryManager::clear_Txt()
    {
    	if (!this->m_isFile)
    	{
    		cout << "文件不存在!" << endl;
    	}
    	else
    	{
    		int select;
    		cout << "是否确定清空所有文档?" << endl
    			<< "1.是" << endl
    			<< "2.否" << endl;
    		cin >> select;
    		ofstream ofs;
    		switch (select)
    		{
    		case 1:
    		{
    			ofs.open(FILENAME, ios::out | ios::trunc);
    			ofs.close();
    			delete[]this->m_BookArray;
    			this->m_BookArray = NULL;
    			this->m_BookNum = 0;
    			this->m_isFile = false;
    			cout << "文档已清空!" << endl;
    			break;
    		}
    			
    		case 2:
    		break;
    		default:
    			break;
    		}
    	}
    
    	system("pause");
    	system("cls");
    }
    
    //通过Id判断该书是否存在,存在则返回数组下标
    int CLIbraryManager::isBook(int Id)
    {
    	int index = -1;
    	for (int i = 0; i < this->m_BookNum; i++)
    	{
    		if (this->m_BookArray[i]->m_Id == Id) {
    			index = i;
    			break;
    		}
    	}
    	return index;
    }
    //通过name判断该书是否存在,存在则返回数组下标(重载)
    int CLIbraryManager::isBook(string name)
    {
    	int index = -1;
    	for (int i = 0; i < this->m_BookNum; i++)
    	{
    		if (this->m_BookArray[i]->m_Name == name) {
    			index = i;
    			break;
    		}
    	}
    	return index;
    }
    
    //删除书本信息
    void CLIbraryManager::delete_Book()
    {
    	//判断文件或记录是否存在
    	if (!this->m_isFile)
    	{
    		cout << "文件不存在或记录为空!" << endl;
    	}
    	else
    	{
    		int Id;
    		string name;
    		int select;//接収用户选择
    		int index = -1;//接收返回的数组下标
    
    		cout << "请输入通过什么删除:" << endl
    			<< "1.书本编号" << endl
    			<< "2.书本名称" << endl;
    		cin >> select;
    
    		switch (select)
    		{
    		case 1:
    		{
    			cout << "请输入书本编号:" << endl;
    			cin >> Id;
    			index = this->isBook(Id);
    			break;
    		}
    		
    		case 2:
    		{
    			cout << "请输入书本名称:" << endl;
    			cin >> name;
    			index = this->isBook(name);
    			break;
    		}
    		default:
    			break;
    		}
    		//若index的值不为-1,则说明该书存在
    		if (index != -1)
    		{
    			cout << "该书本信息为:" << endl;
    			this->m_BookArray[index]->showInfo();//显示该书信息
    			cout << endl << endl << "是否确认删除该书信息?" << endl
    				<< "1.是" << endl
    				<< "2.否" << endl;
    			cin >> select;
    
    			switch (select)
    			{
    			case 1:
    			{
    				for (int i = index; i < this->m_BookNum - 1 ; i++)
    				{
    					this->m_BookArray[i] = this->m_BookArray[i + 1];
    				}
    				this->m_BookNum--;
    				cout << "删除成功!" << endl;
    				this->Save();
    				break;
    			}
    			case 2:
    				cout << "已取消删除!" << endl;
    				break;
    			default:
    				break;
    			}
    		}
    		else
    		{
    			cout << "删除失败,无该书信息!" << endl;
    		}
    	}
    	system("pause");
    	system("cls");
    }
    
    //排序实现
    void CLIbraryManager::sort_BookArray()
    {
    	if (!this->m_isFile)
    	{
    		cout << "文件不存在或记录为空!" << endl;
    	}
    	else {
    		for (int i = 0; i < this->m_BookNum; i++)
    		{
    			for (int j = 0; j < this->m_BookNum; j++)
    			{
    				if (this->m_BookArray[i]->m_Id < this->m_BookArray[j]->m_Id)
    				{
    					CColective* Tbook = this->m_BookArray[i];//创建Tbook中间变量
    					this->m_BookArray[i] = this->m_BookArray[j];
    					this->m_BookArray[j] = Tbook;
    				}
    			}
    		}
    		this->Save();
    		cout << "排序成功!" << endl;
    	}
    	system("pause");
    	system("cls");
    }
    
    
    CColective* CLIbraryManager::find_By_Num(int Id)
    {
    	for (int i = 0; i < this->m_BookNum; i++)
    	{
    		if (i == this->m_BookNum - 1 && this->m_BookArray[i]->m_Id != Id) {
    			return nullptr;
    			break;
    		}
    		if (this->m_BookArray[i]->m_Id == Id) {
    			return m_BookArray[i];
    			break;
    		}
    	}
    }
    
    CColective* CLIbraryManager::find_By_Name(string name)
    {
    	for (int i = 0; i < this->m_BookNum; i++)
    	{
    		if (i == this->m_BookNum - 1 && this->m_BookArray[i]->m_Name != name) {
    			return nullptr;
    			break;
    		}
    		if (this->m_BookArray[i]->m_Name == name) {
    			return m_BookArray[i];
    			break;
    		}
    	}
    	return nullptr;
    }
    
    //析构函数
    CLIbraryManager::~CLIbraryManager()
    {
    	if (this->m_BookArray != NULL)
    	{
    		delete[] this->m_BookArray;
    		this->m_BookArray = NULL;
    	}
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • 234
    • 235
    • 236
    • 237
    • 238
    • 239
    • 240
    • 241
    • 242
    • 243
    • 244
    • 245
    • 246
    • 247
    • 248
    • 249
    • 250
    • 251
    • 252
    • 253
    • 254
    • 255
    • 256
    • 257
    • 258
    • 259
    • 260
    • 261
    • 262
    • 263
    • 264
    • 265
    • 266
    • 267
    • 268
    • 269
    • 270
    • 271
    • 272
    • 273
    • 274
    • 275
    • 276
    • 277
    • 278
    • 279
    • 280
    • 281
    • 282
    • 283
    • 284
    • 285
    • 286
    • 287
    • 288
    • 289
    • 290
    • 291
    • 292
    • 293
    • 294
    • 295
    • 296
    • 297
    • 298
    • 299
    • 300
    • 301
    • 302
    • 303
    • 304
    • 305
    • 306
    • 307
    • 308
    • 309
    • 310
    • 311
    • 312
    • 313
    • 314
    • 315
    • 316
    • 317
    • 318
    • 319
    • 320
    • 321
    • 322
    • 323
    • 324
    • 325
    • 326
    • 327
    • 328
    • 329
    • 330
    • 331
    • 332
    • 333
    • 334
    • 335
    • 336
    • 337
    • 338
    • 339
    • 340
    • 341
    • 342
    • 343
    • 344
    • 345
    • 346
    • 347
    • 348
    • 349
    • 350
    • 351
    • 352
    • 353
    • 354
    • 355
    • 356
    • 357
    • 358
    • 359
    • 360
    • 361
    • 362
    • 363
    • 364
    • 365
    • 366
    • 367
    • 368
    • 369
    • 370
    • 371
    • 372
    • 373
    • 374
    • 375
    • 376
    • 377
    • 378
    • 379
    • 380
    • 381
    • 382
    • 383
    • 384
    • 385
    • 386
    • 387
    • 388
    • 389
    • 390
    • 391
    • 392
    • 393
    • 394
    • 395
    • 396
    • 397
    • 398
    • 399
    • 400
    • 401
    • 402
    • 403
    • 404
    • 405
    • 406
    • 407
    • 408
    • 409
    • 410
    • 411
    • 412
    • 413
    • 414
    • 415
    • 416
    • 417
    • 418
    • 419
    • 420
    • 421
    • 422
    • 423
    • 424
    • 425
    • 426
    • 427
    • 428
    • 429
    • 430
    • 431
    • 432
    • 433
    • 434
    • 435
    • 436
    • 437
    • 438
    • 439
    • 440
    • 441
    • 442
    • 443
    • 444
    • 445
    • 446
    • 447
    • 448
    • 449
    • 450
    • 451
    • 452
    • 453
    • 454
    • 455
    • 456
    • 457
    • 458
    • 459
    • 460
    • 461
    • 462
    • 463
    • 464
    • 465
    • 466
    • 467
    • 468
    • 469
    • 470
    • 471
    • 472
    • 473
    • 474
    • 475
    • 476
    • 477
    • 478
    • 479
    • 480
    • 481
    • 482
    • 483
    • 484
    • 485
    • 486
    • 487
    • 488
    • 489
    • 490
    • 491
    • 492
    • 493
    • 494
    • 495
    • 496
    • 497
    • 498
    • 499
    • 500
    • 501
    • 502
    • 503
    • 504
    • 505
    • 506
    • 507
    • 508
    • 509
    • 510
    • 511
    • 512
    • 513
    • 514
    • 515
    • 516
    • 517
    • 518
    • 519
    • 520
    • 521
    • 522
    • 523
    • 524
    • 525
    • 526
    • 527
    • 528
    • 529
    • 530
    • 531
    • 532
    • 533
    • 534
    • 535
    • 536
    • 537
    • 538
    • 539
    • 540
    • 541
    • 542
    • 543
    • 544
    • 545
    • 546
    • 547
    • 548
    • 549
    • 550
    • 551
    • 552
    • 553
    • 554
    • 555
    • 556
    • 557
    • 558
    • 559
    • 560
    • 561
    • 562
    • 563
    • 564
    • 565
    • 566
    • 567
    • 568
    • 569
    • 570
    • 571
    • 572
    • 573
    • 574
    • 575
    • 576
    • 577
    • 578
    • 579
    • 580
    • 581
    • 582
    • 583
    • 584
    • 585
    • 586
    • 587
    • 588
    • 589
    • 590
    • 591
    • 592
    • 593
    • 594
    • 595
    • 596
    • 597
    • 598
    • 599
    • 600
    • 601
    • 602
    • 603
    • 604

    运行结果

    在这里插入图片描述

    说明

    个人能力有限,仅供参考,共同学习!

  • 相关阅读:
    BFC(边距重叠解决方案)
    关注消费主力军,如何利用AI外呼抓住“Z世代”的心
    Pandas数据操作_Python数据分析与可视化
    CentOS7如何安装图形界面
    泰凌微蓝牙 HCI层事件的注册和使用
    QGraphicsView实现拖拽缩放
    基于JavaWeb+SpringBoot+Vue医疗器械商城微信小程序系统的设计和实现
    图像处理之图像统计特性
    常见的缓存淘汰算法
    fscanf/fscanf_s和fgets使用差异
  • 原文地址:https://blog.csdn.net/qq_29711355/article/details/125460126