目录
设计要求
利用c++以及其中类的相关知识设计图书管理系统,实现图书管理系统的程序设计,要求完成图书管理系统的需求分析、总体设计、详细设计、界面设计以及各模块的功能实现,测试后能运行通过。
总的 来说就是实现书本的增,删,改,查功能,实现人员的增,删,改,查功能,以及借书,还书功能。
程序流图
开始会有两个选择,只能选择 一种身份登录。管理员可以对书籍和人员信息进行修改,读者可以借还书。
代码部分
book.h
#pragma once
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include "draw.h"
#include "staff.h"
using namespace std;
#define BORROWED 0 // 借出
#define IN_STOCK 1 // 在库
#define INVALID_INDEX -1 // 未找到索引
class Book
{
public:
Book(string name, string author, long id, string status, string owner); // 通过传入参数对属性赋值
~Book();
// 两个主要的借还操作
void borrow(string name);
void back(string name);
// 获取更改私有属性
vector<string> show();
int get_status();
string get_name();
void __get(string& name, string& author, long& id, string& status, string& owner);
void set_name(string name);
void set_author(string author);
void set_id(long id);
void set_status(string status);
void set_owner(string owner);
private:
string name; // 书籍姓名
string author; // 书籍作者
long id; // 书籍编号
int status = IN_STOCK; // 书籍状态
string owner; // 书籍所有者,若被借出为借出者姓名,若在库为 无
};
class Books
{
public:
Books();
~Books();
void add();
void del();
void change();
void show();
void borrow(string name, int n);
void back(string name, int n);
int __find(string name);
friend int draw_borrow();
friend int draw_back();
friend int draw_show_all_book();
private:
vector<Book> books; // 书籍容器,包含所有的Book类的书本
};
extern Books B; // 事先定义好的B类对象
book.cpp
#include "book.h"
Books B; // 储存所有书本信息
// 构造函数
Book::Book(string name, string author, long id, string status, string owner) :
name(name), author(author), id(id), owner(owner)
{
if (status == "在库")
this->status = IN_STOCK;
else
this->status = BORROWED;
}
// 析构函数
Book:: ~Book() {}
// 书本借还函数
void Book::borrow(string name)
{
this->status = BORROWED;
this->owner = name;
}
void Book::back(string name)
{
this->status = IN_STOCK;
this->owner = "无";
}
// 返回书本信息
vector<string> Book::show()
{
vector<string>messages = {this->name, this->author, to_string(this->id)};
if (this->status == IN_STOCK)
messages.push_back("在库");
else
messages.push_back("借出");
messages.push_back(this->owner);
return messages;
}
// 获取书本信息
int Book :: get_status()
{
return this->status;
}
string Book::get_name()
{
return this->name;
}
void Book::__get(string &name, string &author, long &id, string &status, string & owner)
{
name = this->name;
author = this->author;
id = this->id;
owner = this->owner;
if (this->status == BORROWED)
status = "借出";
else
status = "在库";
}
// 设置书本信息
void Book::set_name(string name)
{
this->name = name;
}
void Book :: set_author(string author)
{
this->author = author;
}
void Book:: set_id(long id)
{
this->id = id;
}
void Book:: set_status(string status)
{
if (status == "借出")
this->status = BORROWED;
else
this->status = IN_STOCK;
}
void Book:: set_owner(string owner)
{
this->owner = owner;
}
/*---------------------------------------------------------------------------------------------------*/
// 构造函数
Books::Books()
{
ifstream infile;
infile.open("books.txt");
string name, author, owner, status;
long id;
while (infile >> name >> author >> id >> status >> owner)
{
Book b(name, author, id, status, owner);
books.push_back(b);
}
infile.close();
}
// 析构函数
Books::~Books()
{
ofstream outfile;
outfile.open("books.txt", ios::trunc);
string name, author, owner, status;
long id;
for (auto i : books)
{
i.__get(name, author, id, status, owner);
outfile << name << " " << author << " " << id << " " << status << " " << owner<< endl;
}
outfile.close();
}
// 添加书籍
void Books::add()
{
string name, author, bookStatus = "0", owner;
long id = 0;
cout << " >> 请输入书籍信息" << endl << endl;
cout << " >> 名称 : ";
cin >> name; cout << endl;
int index = this->__find(name);
if (index != INVALID_INDEX)
{
cout << " -——-——-——>> 该书已存在 <<——-——-——-" << endl;
}
else
{
cout << " >> 作者 : ";
cin >> author; cout << endl;
cout << " >> id : ";
id = __get_(id); cout << endl;
cout << " >> 状态 : ";
bookStatus = __get_(bookStatus); cout << endl;
cout << " >> 拥有者 : ";
cin >> owner ; cout << endl;
Book b(name, author, id, bookStatus, owner);
books.push_back(b);
cout << " -——-——-——>> 添加成功! <<——-——-——-" << endl;
}
}
// 删除书籍
void Books::del()
{
string name;
cout << " >> 请输入书籍信息" << endl << endl;
cout << " >> 名称 : ";
cin >> name; cout << endl;
int index = this->__find(name);
if (index != INVALID_INDEX)
{
books[index] = books.back();
books.pop_back();
cout << " -——-——-——>> 删除成功! <<——-——-——-" << endl;
}
else
{
cout << " -——-——-——>> 该书不存在 <<——-——-——-" << endl;
}
}
// 修改书籍
void Books::change()
{
string name, author, status = "0", owner;
long id = 0;
cout << " >> 请输入书籍信息" << endl << endl;
cout << " >> 名称 : ";
cin >> name; cout << endl;
int index = this->__find(name);
if (index != INVALID_INDEX)
{
cout << " >> 请输入修改后的书籍信息:" << endl << endl;
cout << " >> 名称 : ";
cin >> name; books[index].set_name(name); cout << endl;
cout << " >> 作者 : ";
cin >> author; books[index].set_author(author); cout << endl;
cout << " >> id : ";
id = __get_(id); cout << endl;
cout << " >> 状态 : ";
status = __get_(status); books[index].set_status(status); cout << endl;
cout << " >> 拥有者 : ";
cin >> owner; books[index].set_owner(owner); cout << endl;
cout << " -——-——-——>> 修改成功! <<——-——-——-" << endl;
}
else
{
cout << " -——-——-——>> 该书不存在 <<——-——-——-" << endl;
}
}
void Books::show()
{
string name;
cout << " >> 请输入书籍信息" << endl << endl;
cout << " >> 名称 : ";
cin >> name; cout << endl;
int index = this->__find(name);
if (index != INVALID_INDEX)
{
vector<string> messages = books[index].show();
messages.push_back("输入任意值返回");
__draw_body_2(messages);
}
else
{
cout << " -——-——-——>> 该书不存在 <<——-——-——-" << endl;
}
}
void Books:: borrow(string name, int n)
{
books[n].borrow(name);
}
void Books::back(string name, int n)
{
books[n].back(name);
}
int Books:: __find(string searchName)
{
string name, author, owner, status;
long id, n = 0;
for (auto i : books)
{
i.__get(name, author, id, status, owner);
if (name == searchName)
{
return n;
}
n++;
}
return INVALID_INDEX;
}
staff.h
#pragma once
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include "draw.h"
#include "book.h"
using namespace std;
#define MAX_BORROWED_BOOKS 3 // 最小为2,因为没有为无,有些许bug,待改进
// 人员类
class Staff
{
public:
Staff(string name, long password, string id, vector<string> borrowed);
~Staff();
// 赋值操作
// 两个借还操作
void borrow(string book);
void back(string book);
// 检查人物身份
int check(string book);
// 返回人物信息
vector<string> show();
// 设置属性函数
void set_name(string name);
void set_id(string id);
void set_password(long password);
// 获取私有属性
void get_all(string& name, long& password, string& id, vector<string>& borrowed);
string get_name();
string get_id();
long get_password();
bool get_achievable();
vector<string> get_borrowed();
private:
string name; // 姓名
long password; // 密码
string id; // 身份
vector<string> borrowed; // 借的书名容器
};
/*-----------------------------------------------------------------------*/
class Staffs
{
public:
// 构造函数 析构函数
Staffs();
~Staffs();
// 添加人员 删除人员
void add();
void del();
// 检查登录人员身份
int check(int i);
// 借书 还书 改变人物信息 展示人物信息 找人函数
void borrowe(string book, int n);
void back(string book, int n);
void change();
void show();
int __find(string name);
// 下面的函数由于是对私有属性进行操作,故友元了
friend int draw_borrow();
friend int draw_back();
friend int draw_show_book();
friend int draw_show_all_visit();
private:
vector<Staff> person; // 人物总信息容器
string user; // 当前登录人名
};
extern Staffs S; // 声明一个对象
staff.cpp
#include "staff.h"
string user; // 储存当前用户名
Staffs S; // 储存用户信息
Staff::Staff(string name, long password, string id, vector<string> borrowed):
name(name), password(password), id(id), borrowed(borrowed){}
Staff::~Staff(){}
// 设置个人信息函数
void Staff::set_name(string name)
{
this->name = name;
}
void Staff::set_id(string id)
{
this->id = id;
}
void Staff::set_password(long password)
{
this->password = password;
}
// 获取个人信息函数
void Staff::get_all(string& name, long& password, string& id, vector<string>& borrowed)
{
name = this->name;
password = this->password;
id = this->id;
borrowed = this->borrowed;
}
string Staff:: get_name()
{
return this->name;
}
string Staff::get_id()
{
return this->id;
}
long Staff:: get_password()
{
return this->password;
}
bool Staff:: get_achievable()
{
if (this -> borrowed.size() > (MAX_BORROWED_BOOKS - 1))
return 0;
return 1;
}
vector<string> Staff:: get_borrowed()
{
return this->borrowed;
}
// 个人借书,还书,检查身份函数
void Staff::borrow(string book)
{
if (borrowed.back() == "无")
borrowed.pop_back();
borrowed.push_back(book);
}
void Staff::back(string book)
{
auto it = find(borrowed.begin(), borrowed.end(), book);
if (it != borrowed.end()) {
borrowed.erase(it);
if (borrowed.size() < 1)
borrowed.push_back("无");
}
}
int Staff::check(string book)
{
int n = 0;
for (auto i : borrowed)
{
if (i == book)
return n;
n++;
}
return -1;
}
vector<string> Staff::show()
{
vector<string>messages = { this->name, to_string(this->password), this->id };
for (auto i : borrowed)
messages.push_back(i);
return messages;
}
/*-------------------------------------------------------------------------------------------------*/
// 构造函数:从文件中读取数据 析构函数:向文件中写入数据
Staffs::Staffs()
{
ifstream infile;
infile.open("person.txt");
string name, id, temp;
long password;
vector<string> borrowed;
while (getline(infile, temp))
{
stringstream line_stream(temp);
line_stream >> name >> password >> id;
while (line_stream >> temp)
{
borrowed.push_back(temp);
}
Staff s(name, password, id, borrowed);
person.push_back(s);
borrowed.clear();
}
infile.close();
}
Staffs::~Staffs()
{
ofstream infile;
infile.open("person.txt", ios:: trunc);
string name, id;
long password;
vector<string> borrowed;
for (auto i : person)
{
i.get_all(name, password, id, borrowed);
infile << name << " " << password << " " << id << " ";
for (auto j : borrowed)
{
infile << j << " ";
}
infile << endl;
}
infile.close();
}
// 添加人员 和 删除人员 函数
void Staffs::add()
{
string name, id = "1";
long password = 0;
vector<string> borrowed = { "无" };
cout << " >> 请输入人员信息: " << endl;
cout << " >> 姓名 :";
cin >> name; cout << endl;
int Index = __find(name);
if (Index != INVALID_INDEX)
{
cout << " -——-——-——>> 该人已存在 <<——-——-——-" << endl << endl;
}
else
{
cout << " >> 密码: ";
password = __get_(password); cout << endl;
cout << " >> 身份: ";
id = __get_(id); cout << endl;
Staff staff(name, password, id, borrowed);
person.push_back(staff);
cout << " -——-——-——>> 添加成功! <<——-——-——-" << endl << endl;
}
}
void Staffs::del()
{
string name;
cout << " >> 请输入人员信息: " << endl;
cout << " >> 姓名 :";
cin >> name; cout << endl;
int Index = __find(name);
if (Index == INVALID_INDEX)
{
cout << " -——-——-——>> 该人不存在 <<——-——-——-" << endl << endl;
}
else
{
person[Index] = person.back();
person.pop_back();
cout << " -——-——-——>> 删除成功! <<——-——-——-" << endl << endl;
}
}
// 检查登录人员身份函数
int Staffs::check(int i)
{
string name, id = "读者", id_input;
vector<string> borrowed;
if (i)
id = "管理员";
long password_input = 0, password;
cout << " >> 输入用户名: ";
cin >> name; cout << endl;
int Index = __find(name);
if (Index == INVALID_INDEX)
{
cout << " -——-——-——>> 该人不存在 <<——-——-——-" << endl << endl;
}
else
{
person[Index].get_all(name, password, id_input, borrowed);
cout << " >> 输入密码: ";
password_input = __get_(password_input); cout << endl;
if (password == password_input)
{
if (id == id_input)
{
user = name;
cout << " >> 输入任意值返回" << endl;
return 1;
}
else
{
cout << " -——-——-——>> 身份错误 <<——-——-——-" << endl << endl;
cout << " >> 输入任意值返回" << endl;
}
}
else
{
cout << " -——-——-——>> 密码错误 <<——-——-——-" << endl << endl;
cout << " >> 输入任意值返回" << endl;
}
}
return 0;
}
// 借 还 改 相关函数
void Staffs::borrowe(string book, int n)
{
person[n].borrow(book);
}
void Staffs::back(string book, int n)
{
person[n].back(book);
}
void Staffs::change()
{
cout << " >> 请输入人员名称: ";
string name, id = "1";
long password = 0;
cin >> name;cout << endl;
int Index = __find(name);
if (Index != INVALID_INDEX)
{
cout << " >> 请输入新的信息" << endl << endl;
cout << " >> 姓名: ";
cin >> name;cout << endl;
cout << " >> 密码: ";
password = __get_(password); cout << endl;
cout << " >> 身份:";
id = __get_(id); cout << endl;
person[Index].set_name(name);
person[Index].set_id(id);
person[Index].set_password(password);
cout << " -——-——-——>> 修改成功! <<——-——-——-" << endl << endl;
}
else
{
cout << " -——-——-——>> 该人不存在 <<——-——-——-" << endl << endl;
}
}
void Staffs::show()
{
string name;
cout << " >> 请输入人员信息" << endl << endl;
cout << " >> 姓名 : ";
cin >> name; cout << endl;
int index = this->__find(name);
if (index != INVALID_INDEX)
{
vector<string> messages = person[index].show();
messages.push_back("输入任意值返回");
__draw_body_2(messages);
}
else
{
cout << " -——-——-——>> 该人不存在 <<——-——-——-" << endl;
}
}
// 接受名字,返回该人在容器中的索引
int Staffs::__find(string name)
{
int n = 0;
for (auto i : person)
{
if (i.get_name() == name)
{
return n;
}
n++;
}
return INVALID_INDEX;
}
draw.h
#pragma once
#include <stdlib.h>
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include "book.h"
#include "staff.h"
using namespace std;
int draw_begin(); // 开始界面
int draw_manager(); // 管理员界面
int draw_log_in_manager(); // 管理员登陆界面
int draw_log_in_reader(); // 读者登陆界面
int draw_reader(); // 读者界面
int draw_borrow(); // 借书界面
int draw_back(); // 还书界面
int draw_manage_book(); // 管理书籍界面
int draw_add(); // 添加书籍界面
int draw_del(); // 删除书籍界面
int draw_find(); // 查找图书界面
int draw_change(); // 修改图书界面
int draw_manage_visit(); // 管理人员界面
int draw_add_visit(); // 添加人员界面
int draw_del_visit(); // 删除人员界面
int draw_change_visit(); // 修改人员界面
int draw_show_book(); // 查看所借图书界面
int draw_find_visit(); // 查找人员界面
int draw_show_all_visit(); // 查看所有人员界面
int draw_show_all_book(); // 查看所有图书界面
void pause(); // 暂停等待输入函数
void __draw(vector <string> messages); // 第一种绘制函数
void __draw_2(vector<string> messages); // 第二种绘制函数
void __draw_head(); // 一种界面头样式
void __draw_end_2(); // 一种界面尾样式
void __draw_end_1();
void __draw__end_3();
void __draw_body_1(vector<string> messages); // 绘制主体信息函数
void __draw_body_2(vector<string> messages); //
// 检测输入函数
template <typename T>
T __get_(T t)
{
T input;
bool out = 0;
while (!out)
{
cin >> input;
// 如果类型不匹配
if (cin.fail())
{
cout << " !>> >> 类型错误 << <<! " << endl << " >> 请重新输入:";
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
}
// 如果传入的类型是数字,则检查是否在正确范围内
else if constexpr (std::is_same<T, int>::value)
{
if (input <= 0 || input > t)
{
cout << " !>> >> 输入错误 << <<! " << endl << " >> 请重新输入:";
}
else
out = 1;
}
else if constexpr (std::is_same<T, long>::value)
{
if (input < 100000 || input > 999999)
{
cout << " !>> >> 输入错误 << <<! " << endl << " >> 请重新输入:";
}
else
out = 1;
}
else if constexpr (std::is_same<T, string>::value)
{
if (t == "1" && input != "管理者" && input != "读者")
{
cout << " !>> >> 输入错误 << <<! " << endl
<< " !>> >> 应输入管理者或读者 << <<! " << endl << " >> 请重新输入:";
}
else if (t == "0" && input != "在库" && input != "借出")
{
cout << " !>> >> 输入错误 << <<! " << endl
<< " !>> >> 应输入在库或借出 << <<! " << endl << " >> 请重新输入:";
}
else
out = 1;
}
}
return input;
}
// 界面函数数组
extern vector<int(*)()> Interface;
draw.cpp
#include "draw.h"
// Interface 界面函数数组
vector<int(*)()> Interface = { draw_begin, draw_reader, draw_manager, draw_manage_book ,draw_manage_visit, draw_back, draw_borrow, draw_add, draw_del, draw_find, draw_change, draw_add_visit, draw_del_visit, draw_change_visit, draw_log_in_reader, draw_log_in_manager, draw_show_book, draw_find_visit, draw_show_all_visit , draw_show_all_book};
// 0 开始 1 读者 2 管理员 3 管理书籍 4 管理人员 5 还书 6 借书 7添加 8删除 9查找 10修改 11添加人员 12删除人员 13修改人员 14登录读者 15登录管理员 16展示图书 17展示人员 18展示所有人员 19展示所有图书
// 开始界面 管理员界面 登录界面
int draw_begin()
{
vector<string> messages = { "1 管理员", "2 普通读客", "3 退出"};
__draw(messages);
int message = __get_(3);
switch (message)
{
case 1: return 15;
case 2: return 14;
case 3: exit(0);
}
return 0;
}
int draw_manager()
{
vector<string> messages = { "1 管理书籍", "2 管理人员", "3 返回"};
__draw(messages);
int message = __get_(3);
switch (message)
{
case 1: return 3;
case 2: return 4;
case 3: return 0;
}
return 0;
}
int draw_log_in_manager()
{
__draw_head();
int n = S.check(1);
__draw__end_3();
pause();
if (n)
return 2;
return 0;
}
int draw_log_in_reader()
{
__draw_head();
int n = S.check(0);
__draw__end_3();
pause();
if (n)
return 1;
return 0;
}
// 管理书籍界面 添加界面 删除界面 查找书籍界面 修改信息界面 查看所有书籍
int draw_manage_book()
{
vector<string> messages = { "1 添加书籍", "2 删除书籍", "3 查找书籍", "4 修改书籍", "5 查看所有书籍", "6 返回"};
__draw(messages);
int message = __get_(6);
switch (message)
{
case 1: return 7;
case 2: return 8;
case 3: return 9;
case 4: return 10;
case 5: return 19;
case 6: return 2;
}
return 0;
}
int draw_add()
{
__draw_head();
B.add();
cout << " >> 输入任意值返回" << endl;
__draw__end_3();
pause();
return 3;
}
int draw_del()
{
__draw_head();
B.del();
cout << " >> 输入任意值返回" << endl;
__draw__end_3();
pause();
return 3;
}
int draw_find()
{
__draw_head();
B.show();
__draw__end_3();
pause();
return 3;
}
int draw_change()
{
__draw_head();
B.change();
cout << " >> 输入任意值返回" << endl;
__draw__end_3();
pause();
return 3;
}
int draw_show_all_book()
{
vector<string> messages;
for (auto i : B.books)
{
string temp = i.get_name();
if (i.get_status())
{
temp += " ";
temp += "在库";
messages.push_back(temp);
}
}
messages.push_back("输入任意值返回");
__draw_head();
__draw_body_2(messages);
__draw__end_3();
pause();
return 3;
}
// 管理人员界面 添加人员界面 删除人员界面 修改人员信息界面 查看所有人信息界面
int draw_manage_visit()
{
vector<string> messages = { "1 添加用户", "2 删除用户", "3 修改用户","4 查看用户", "5 查看所有人员", "6 返回"};
__draw(messages);
int message = __get_(6);
switch (message)
{
case 1: return 11;
case 2: return 12;
case 3: return 13;
case 4: return 17;
case 5: return 18;
case 6: return 2;
}
return 0;
}
int draw_add_visit()
{
__draw_head();
S.add();
cout << " >> 输入任意值返回" << endl;
__draw__end_3();
pause();
return 4;
}
int draw_del_visit()
{
__draw_head();
S.del();
cout << " >> 输入任意值返回" << endl;
__draw__end_3();
pause();
return 4;
}
int draw_change_visit()
{
__draw_head();
S.change();
cout << " >> 输入任意值返回" << endl;
__draw__end_3();
pause();
return 4;
}
int draw_find_visit()
{
__draw_head();
S.show();
cout << " >> 输入任意值返回" << endl;
__draw__end_3();
pause();
return 4;
}
int draw_show_all_visit()
{
vector<string> messages;
for (auto i : S.person)
{
string temp = i.get_name();
temp += " ";
temp += i.get_id();
messages.push_back(temp);
}
messages.push_back("输入任意值返回");
__draw_head();
__draw_body_2(messages);
__draw__end_3();
pause();
return 4;
}
// 读者界面 借书界面 还书界面 查看借书信息界面
int draw_reader()
{
vector<string> messages = { "1 借书", "2 还书", "3 查看书籍", "4 返回"};
__draw(messages);
int message = __get_(4);
switch (message)
{
case 1: return 6;
case 2: return 5;
case 3: return 16;
case 4: return 0;
}
return 0;
}
int draw_borrow()
{
__draw_head();
string name;
cout << " >> 请输入要借阅书的名字:";
cin >> name; cout << endl;
int staff_Index = S.__find(S.user);
int book_Index = B.__find(name);
if (S.person[staff_Index].get_achievable() && B.books[book_Index].get_status())
{
S.borrowe(name, staff_Index);
B.borrow(S.user, book_Index);
cout << " >> 借阅成功!" << endl << endl;
cout << " >> 输入任意值返回" << endl;
__draw__end_3();
pause();
return 1;
}
cout << " >> 借阅失败!" << endl << endl;
cout << " >> 输入任意值返回" << endl;
__draw__end_3();
cin >> name;
return 1;
}
int draw_back()
{
__draw_head();
string book;
cout << " >> 请输入要归还书的名字:";
cin >> book; cout << endl;
int staff_Index = S.__find(S.user);
int book_Index = B.__find(book);
if (S.person[staff_Index].check(book) != INVALID_INDEX && (!B.books[book_Index].get_status()))
{
S.back(book, staff_Index);
B.back(S.user, book_Index);
cout << " >> 归还成功!" << endl << endl;
cout << " >> 输入任意值返回" << endl;
__draw__end_3();
pause();
return 1;
}
cout << " >> 并未借阅该书籍" << endl << endl;
cout << " >> 输入任意值返回" << endl;
__draw__end_3();
cin >> book;
return 1;
}
int draw_show_book()
{
int n = S.__find(S.user);
vector<string> borrowed = S.person[n].get_borrowed();
borrowed.push_back("输入任意值返回");
__draw_head();
__draw_body_2(borrowed);
__draw__end_3();
pause();
return 1;
}
void pause()
{
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cin.get();
}
// 绘制函数 两个设定好的函数 一个绘制头的函数 两个绘制内容主体函数 三种绘制底部函数
void __draw(vector <string> messages)
{
__draw_head();
__draw_body_1(messages);
__draw_end_1();
}
void __draw_2(vector<string> messages)
{
__draw_head();
__draw_body_2(messages);
__draw_end_1();
}
void __draw_head()
{
cout << "-——-——-——-——-——-——-——-——-——-——-——-——-——" << endl << endl;
cout << " 欢迎来到图书管理系统 |" << endl << endl;
}
void __draw_body_1(vector<string> messages)
{
for (auto i : messages)
{
cout << " ——- ——->> " << setw(12) << left << i << " << -—— - —— |" << endl << endl;
}
int n = 5 - messages.size();
for (int i = 0; i < n; i++)
{
cout << " |" << endl << endl;
}
}
void __draw_body_2(vector<string> messages)
{
for (auto i : messages)
{
cout << " >> " << setw(30) << left << i << " << |" << endl << endl;
}
int n = messages.size();
for (int i = 0; i < 5- n; i++)
{
cout << " |" << endl << endl;
}
}
void __draw_end_1()
{
cout << "-——-——-——-——-——-——-——-——-——-——-——-——-——" << endl << endl;
cout << "<<-—— 请选择 ——->> : ";
}
void __draw_end_2()
{
cout << "-——-——-——-——-——-——-——-——-——-——-——-——-——" << endl << endl;
cout << "<<-—— 请输入 ——->> : ";
}
void __draw__end_3()
{
cout << "-——-——-——-——-——-——-——-——-——-——-——-——-——" << endl << endl;
}
main.cpp
#include "draw.h"
// 循环调用页面,Interface 界面函数数组
int main()
{
int n = 0;
while (1)
n = Interface[n]();
return 0;
}
/*请先阅读 readme.txt 会帮助你理解本程序的整体框架*/
person.txt
大大 100203 读者 无
赵六 900422 读者 无
钱七 200110 管理员 无
孙八 900202 读者 计算机网络
张三 200201 管理员 无
AA 123456 管理员 无
李四 900322 读者 无
王五 123456 读者 无
张一 888888 管理员 无
books.txt
算法竞赛入门经典 题解组 132323 在库 无
编程之美 计算机程序设计艺术研究组 132332 在库 无
深入浅出C++ 巴拉圭·布罗茨基 255555 在库 无
数据库原理与应用 格雷厄姆·巴克 399999 在库 无
黑客与画家 弗兰克·史蒂文森 409098 在库 无
编程之美 兰蔻·达芙妮 505050 在库 无
编程语言实现技术 埃里克·霍尔 777777 在库 无
计算机程序设计语言 库比·柯尔 787878 在库 无
深入浅出计算机科学 丹·巴登 878787 在库 无
程序员修炼之道 理查德·弗兰克 909090 在库 无
算法竞赛进阶指南 小甲鱼团队 132324 在库 有
数据结构与算法分析 弗雷德·克劳德 255556 在库 无
计算机网络 张志华 399999 借出 孙八
readme.md
## 本程序是一个用c++实现,在终端运行的图书管理系统
> 开发平台 windows; 开发工具 Visual Studio 开发人员 Achiever 开发时间 2022.12.26 - 2022.12.28
# 实现双重身份登录
# 对书本信息修改,对人员信息修改
# 还书 借书
具体人物信息格式见 person.txt 从左到右为 姓名 密码 身份 借阅书籍名
具体书籍信息见 book.txt 从左到右为 书名 作者 id编号 状态 所有者### 关于界面切换:相关函数写在 draw.h 及 draw.cpp中
本程序采用利用函数的返回值,来判断该进入哪个界面
应该不难注意到 extern vector<int(*)()> Interface 这个函数数组
每一个界面函数如 draw_begin() 函数都会返回一个 int 型,这个返回值对应就是函数数组的下标
同时对于用户输入同一用 __get_() 这个模板函数来处理
要求用户输入类型合法,数据合法### 关于书籍结构: 相关函数写在 book.h 及 book.cpp 中
其中 Book 类是一本书的类,用于储存一本书的相关信息,以及改变书籍状态
Books 类中 books 容器会在构造函数从设定好的文件中读取数据
并在析构函数中将 books 中的数据重新写入文件中
Books 在book.cpp 相关文件定义了一个 B 对象,意味着程序已启动,文件读入就完成了
因此对于书本的操作就是对 books 中容器中数据的操作### 关于人物结构:相关函数写在 staff.h 及 staff.cpp 中
其中 Staff 是个人类,用于存储一个人的信息
Staffs 中 person 容器在构造函数中会从文件中读取所有的人物数据
在析构函数中重新写入文件中
Staffs 在staff.cpp 相关文件定义了一个 S对象,意味着程序已启动,文件读入就完成了
对于人物的信息变化,就是对 person 容器中的数据进行改变### 行为实现 : 借书,还书需要人员数据和图书数据一起变化
人员信息更改,调用 Staffs 类的方法
图书信息更改,调用 Books 类的方法
效果图
下面是一些效果图