日常的一个作业,还存在一些bug,如果有找到,可以给本菜菜提建议,以后也会慢慢更新,现在先去学算法啦,以后思路也会专门写一篇博客的,有任何问题及时交流。
#include <iostream>
#include <cstring>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
#include <queue>
#include <unordered_map>
#include <fstream>
using namespace std;
class max_books {
int book_nums;
public:
max_books(int n) {
book_nums = n;
}
max_books() {}
int get_booknums() {
return book_nums;
}
};
class max_data {
int data_max;
public:
max_data(int n) { data_max = n; }
max_data() {}
int get_datanums() { return data_max; }
};
//数据类
//日期类
class date {
int year, month, day;
public:
date(int a, int b, int c) { year = a; month = b; day = c; }
date() {}
friend ostream& operator<<(ostream& out, date& p);
friend istream& operator>>(istream& in, date& p);
bool operator+(int n);
bool operator<(const date& p)const;
bool operator==(const date& p)const;
int get_year() { return year; }
int get_month() { return month; }
int get_day() { return day; }
};
ostream& operator<<(ostream& out, date& p) {
out << p.year << " " << p.month << " " << p.day;
return out;
}
istream& operator>>(istream& in, date& p) {
int x, y, z;
int max_days = 0;
int arr[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
bool flag = 0;
while (in >> x >> y >> z) {
if (x % 4 == 0 && x % 100 != 0 || x % 100 == 0) {
flag = 1;
}
if (y > 12 || y < 1) {
continue;
}
else {
if (flag == 1) {
arr[1] = 29;
}
max_days = arr[y - 1];
}
if (y <= max_days) {
p.year = x;
p.month = y;
p.day = z;
break;
}
}
return in;
}
bool date::operator<(const date& p)const {
if (year != p.year) { return year < p.year; }
else if (month != p.month){return month < p.month;}
else { return day < p.day; }
}
bool date::operator==(const date& p)const {
if (year == p.year && month == p.month && day == p.day) {
return true;
}
else {
return false;
}
}
//图书类
class books {
string nums;
string name;
string zuozhe;
string press;
string book_size;
date add;
int sum_books;
int now_books;
public:
books(string anums, string aname, string azuozhe, string apress, string abook_size,date a_add, int asum_books, int anow_books) {
nums = anums;
name = aname;
zuozhe = azuozhe;
press = apress;
add = a_add;
book_size = abook_size;
sum_books = asum_books;
now_books = anow_books;
}
books() {}
void set_nums(string a_nums) { nums = a_nums; }
void set_name(string a_name) { name = a_name; }
void set_zuozhe(string a_zuozhe) { zuozhe = a_zuozhe; }
void set_press(string z_press) { press = z_press; }
void set_booksize(string size) { book_size = size; }
void set_sumbooks(int a) { sum_books = a; }
void set_nowbooks(int a) { now_books = a; }
void set_date(date a) { add = a; }
string get_nums() { return nums; }
string get_name() { return name; }
string get_zuozhe() { return zuozhe; }
string get_press() { return press; }
string get_book_size() { return book_size; }
int get_sum_books() { return sum_books; }
int get_now_books() { return now_books; }
date get_date() {return add;}
friend ostream& operator<<(ostream& out, books& p);
friend istream& operator>>(istream& in, books& p);
};
ostream& operator<<(ostream& out, books& p) {
out << p.nums << " " << p.name << " " << p.zuozhe << " " << p.press << " " << p.book_size << " " << p.add <<" "<<p.sum_books<<" "<<p.now_books<<endl;
return out;
}
istream& operator>>(istream& in, books& p) {
in >> p.nums >> p.name >> p.zuozhe >> p.press >> p.book_size >> p.add>>p.sum_books>>p.now_books;
return in;
}
//学生类
class Student {
private:
string s_nums;
string s_name;
string s_major;
string s_grade;
int s_borrow;//借阅数量
//date s_a;//借阅日期
//books s_p;
public:
Student(string a, string b, string c, string d, int e) {
s_nums = a;
s_name = b;
s_major = c;
s_grade = d;
s_borrow = e;
//s_a = ee;
//s_p = f;
}
Student() {};
~Student(){}
void set_nums(string a) { s_nums = a; }
void set_name(string a) { s_name = a; }
void set_major(string a) { s_major = a; }
void set_grade(string a) { s_grade = a; }
void set_borrow(int a) { s_borrow = a; }
//void set_date(date a) { s_a = a; }
//void set_book(books a) { s_p = a; }
string get_nums() { return s_nums; };
string get_name() { return s_name; };
string get_major() { return s_major; }
string get_grade() { return s_grade; }
int get_borrow() { return s_borrow; }
//date get_date() { return s_a; }
//books get_book() { return s_p; }
friend istream& operator>>(istream& in, Student& p);
friend ostream& operator<<(ostream& out, Student& p);
};
istream& operator>>(istream& in, Student& p) {
in >> p.s_nums >> p.s_name >> p.s_major >> p.s_grade >> p.s_borrow;
return in;
}
ostream& operator<<(ostream& out, Student& p) {
out << p.s_nums << " " << p.s_name << " " << p.s_major << " " << p.s_grade << " " << p.s_borrow << " ";
return out;
}
//借阅纪录类
class record {
string b_nums;
string b_name;
string st_nums;
string s_size;
string b_size;
date ss;
public:
//学号,班级
record(string a,string aa,string b,string c,string d,date e) {
b_nums = a;
b_name = aa;
st_nums = b;
s_size = c;
b_size = d;
ss = e;
}
record() {};
~record(){}
void set_bnums(string s) {b_nums = s;}
void set_bname(string s) { b_name = s; }
void set_stnums(string s) {st_nums = s;}
void set_ssize(string s) {s_size = s;}
void set_bsize(string s) {b_size = s;}
void set_date(date s) {ss = s;}
string get_bnums() { return b_nums; }
string get_bname() { return b_name; }
string get_stnums() { return st_nums; }
string get_ssize() { return s_size; }
string get_bsize() { return b_size; }
date get_date() { return ss; }
friend ostream& operator<<(ostream& out, record& p);
friend istream& operator>>(istream& in, record& p);
};
ostream& operator<<(ostream& out, record& p) {
out << p.b_nums << " " <<p.b_name<<" "<< p.st_nums << " " << p.s_size << " " << p.b_size << " " << p.ss;
return out;
}
istream& operator>>(istream& in, record& p) {
in>> p.b_nums>> p.b_name>> p.st_nums>> p.s_size>> p.b_size>>p.ss;
return in;
}
class reader {
public:
//基本查找
virtual void b_name_lookup()=0;
virtual void b_nums_lookup() = 0;
virtual void b_zuozhe_lookup() = 0;
virtual void b_press_lookup() = 0;
virtual void b_date_lookup() = 0;
//精确查找
virtual void lookup_name() = 0;//书名+作者
virtual void lookup_press() = 0;//出版社+作者
//书名模糊查找
virtual void lookup_mohu_name() = 0;
};
//将数据写进数组以及容器里
//图书查询
class book_lookup {
public:
vector<books>book_v;
multimap<string, int>book_nums;
multimap<string, int>book_name;
multimap<string, int>book_zuozhe;
multimap<string, int>book_press;
multimap<string, int>book_size;//书的类型
multimap<date, int>book_date;
int c_booknums(string nums);
void c1_bookname(string name);
void c2_bookname(string s);
void c1_bookzuozhe(string zuozhe);
void c2_bookzuozhe(string s);
void c1_bookpress(string press);
//void c2_bookpress(string s);
void c1_booksize(string size);
//void c2_booksize(string size);
void c1_date(date a);
void c2_date(date a, date b);
//精确查找
void zuozhe_bname_find(string name, string zuozhe);
void zuozhe_press_find(string zuozhe, string press);
//展示所有信息
void book_display() {
vector<books>::iterator it;
for (it = book_v.begin(); it != book_v.end(); it++) {
cout << "书号:" << it->get_nums();
cout << " 书名:" << it->get_name();
cout << " 作者:" << it->get_zuozhe();
cout << " 出版社:" << it->get_press();
cout << " 出版日期:" << it->get_date().get_year() << "年 " << it->get_date().get_month() << "月 " << it->get_date().get_day() << "日";
cout << " 图书类型:" << it->get_book_size();
cout << " 图书在馆数量:" << it->get_now_books();
cout << " 图书总数量:" << it->get_sum_books() << endl;
}
}
};
int book_lookup::c_booknums(string nums) {
multimap<string, int>::iterator it;
it = book_nums.find(nums);
if (it != book_nums.end()) {
cout << "书号:" << book_v[it->second].get_nums();
cout << " 书名:" << book_v[it->second].get_name();
cout << " 作者:" << book_v[it->second].get_zuozhe();
cout << " 出版社:" << book_v[it->second].get_press();
cout << " 出版日期:" << book_v[it->second].get_date().get_year() << "年 " << book_v[it->second].get_date().get_month() << "月 " << book_v[it->second].get_date().get_day() << "日";
cout << " 图书类型:" << book_v[it->second].get_book_size();
cout << " 图书在馆数量:" << book_v[it->second].get_now_books();
cout << " 图书总数量:" << book_v[it->second].get_sum_books() << endl;
return 0;
}
else {
return -1;
cout <<"没有查到该书的信息!" << endl;
}
}
void book_lookup::c1_bookname(string name) {
multimap<string, int>::iterator it;
if (book_name.find(name) != book_name.end()) {
pair < multimap<string, int>::iterator, multimap<string, int>::iterator>range;
range = book_name.equal_range(name);
for (it = range.first; it != range.second; it++) {
cout << "书号:" << book_v[it->second].get_nums();
cout << " 书名:" << book_v[it->second].get_name();
cout << " 作者:" << book_v[it->second].get_zuozhe();
cout << " 出版社:" << book_v[it->second].get_press();
cout << " 出版日期:" << book_v[it->second].get_date().get_year() << "年 " << book_v[it->second].get_date().get_month() << "月 " << book_v[it->second].get_date().get_day() << "日";
cout << " 图书类型:" << book_v[it->second].get_book_size();
cout << " 图书在馆数量:" << book_v[it->second].get_now_books();
cout << " 图书总数量:" << book_v[it->second].get_sum_books() << endl;
}
}
else {
cout << "该书名的图书未能找到!" << endl;
}
}
void book_lookup::c1_bookpress(string press) {
multimap<string, int>::iterator it;
if (book_press.find(press) != book_press.end()) {
pair < multimap<string, int>::iterator, multimap<string, int>::iterator>range;
range = book_press.equal_range(press);
for (it = range.first; it != range.second; it++) {
cout << "书号:" << book_v[it->second].get_nums();
cout << " 书名:" << book_v[it->second].get_name();
cout << " 作者:" << book_v[it->second].get_zuozhe();
cout << " 出版社:" << book_v[it->second].get_press();
cout << " 出版日期:" << book_v[it->second].get_date().get_year() << "年 " << book_v[it->second].get_date().get_month() << "月 " << book_v[it->second].get_date().get_day() << "日";
cout << " 图书类型:" << book_v[it->second].get_book_size();
cout << " 图书在馆数量:" << book_v[it->second].get_now_books();
cout << " 图书总数量:" << book_v[it->second].get_sum_books() << endl;
}
}
else {
cout << "该出版社的图书未能找到!" << endl;
}
}
void book_lookup::c1_booksize(string size) {
multimap<string, int>::iterator it;
pair < multimap<string, int>::iterator, multimap<string, int>::iterator>range;
range = book_size.equal_range(size);
for (it = range.first; it != range.second; it++) {
cout << "书号:" << book_v[it->second].get_nums();
cout << " 书名:" << book_v[it->second].get_name();
cout << " 作者:" << book_v[it->second].get_zuozhe();
cout << " 出版社:" << book_v[it->second].get_press();
cout << " 出版日期:" << book_v[it->second].get_date().get_year() << "年 " << book_v[it->second].get_date().get_month() << "月 " << book_v[it->second].get_date().get_day() << "日";
cout << " 图书类型:" << book_v[it->second].get_book_size();
cout << " 图书在馆数量:" << book_v[it->second].get_now_books();
cout << " 图书总数量:" << book_v[it->second].get_sum_books() << endl;
}
}
void book_lookup::c1_bookzuozhe(string zuoshe) {
multimap<string, int>::iterator it;
pair < multimap<string, int>::iterator, multimap<string, int>::iterator>range;
range = book_zuozhe.equal_range(zuoshe);
for (it = range.first; it != range.second; it++) {
cout << "书号:" << book_v[it->second].get_nums();
cout << " 书名:" << book_v[it->second].get_name();
cout << " 作者:" << book_v[it->second].get_zuozhe();
cout << " 出版社:" << book_v[it->second].get_press();
cout << " 出版日期:" << book_v[it->second].get_date().get_year()<<"年 "<< book_v[it->second].get_date().get_month()<<"月 "<< book_v[it->second].get_date().get_day()<<"日";
cout << " 图书类型:" << book_v[it->second].get_book_size();
cout << " 图书在馆数量:" << book_v[it->second].get_now_books();
cout << " 图书总数量:" << book_v[it->second].get_sum_books() << endl;
}
}
void book_lookup::c1_date(date a) {
multimap<date, int>::iterator it;
pair < multimap<date, int>::iterator, multimap<date, int>::iterator>range;
range = book_date.equal_range(a);
//因为只有一本时不容易输出
if (range.first == book_date.end()) {
cout << "未能找到该日期的书!" << endl;
return;
}
it = range.first;
do {
cout << "书号:" << book_v[it->second].get_nums();
cout << " 书名:" << book_v[it->second].get_name();
cout << " 作者:" << book_v[it->second].get_zuozhe();
cout << " 出版社:" << book_v[it->second].get_press();
cout << " 出版日期:" << book_v[it->second].get_date().get_year() << "年 " << book_v[it->second].get_date().get_month() << "月 " << book_v[it->second].get_date().get_day() << "日";
cout << " 图书类型:" << book_v[it->second].get_book_size();
cout << " 图书在馆数量:" << book_v[it->second].get_now_books();
cout << " 图书总数量:" << book_v[it->second].get_sum_books() << endl;
it++;
} while (it != range.second);
}
void book_lookup::c2_date(date a, date b) {
multimap<date, int>::iterator it1, it2, it;
it1 = book_date.lower_bound(a);
it2 = book_date.upper_bound(b);
for (it = it1; it != it2; it++) {
//cout << book_v[it->second];
cout << "书号:" << book_v[it->second].get_nums();
cout << " 书名:" << book_v[it->second].get_name();
cout << " 作者:" << book_v[it->second].get_zuozhe();
cout << " 出版社:" << book_v[it->second].get_press();
cout << " 出版日期:" << book_v[it->second].get_date().get_year() << "年 " << book_v[it->second].get_date().get_month() << "月 " << book_v[it->second].get_date().get_day() << "日";
cout << " 图书类型:" << book_v[it->second].get_book_size();
cout << " 图书在馆数量:" << book_v[it->second].get_now_books();
cout << " 图书总数量:" << book_v[it->second].get_sum_books() << endl;
}
}
//模糊查找,重载find_if函数
class map_value_finder
{
public:
map_value_finder(const string& cmp_string) :map_cmp_string(cmp_string) {}
bool operator ()(const multimap<string, int>::value_type& pair)
{
int l;
l = pair.first.find(map_cmp_string);
if (l != pair.first.npos)
return true;
return false;
}
private:
const string& map_cmp_string;
};
//利用书名进行模糊查找
void book_lookup::c2_bookname(string s) {
multimap<string, int>::iterator it, p1, p2, p, begin;
p1 = book_name.begin();
p2 = book_name.end();
begin = p1;
int flag = 0;
for (p = p1; p != p2; p++)
{
it = find_if(begin, book_name.end(), map_value_finder(s));
if (it == book_name.end()) {
//cout << "未能找到相似图书!" << endl;
return;
}
else {
flag = 1;
//cout << book_v[it->second];
cout << "书号:" << book_v[it->second].get_nums();
cout << " 书名:" << book_v[it->second].get_name();
cout << " 作者:" << book_v[it->second].get_zuozhe();
cout << " 出版社:" << book_v[it->second].get_press();
cout << " 出版日期:" << book_v[it->second].get_date().get_year() << "年 " << book_v[it->second].get_date().get_month() << "月 " << book_v[it->second].get_date().get_day() << "日";
cout << " 图书类型:" << book_v[it->second].get_book_size();
cout << " 图书在馆数量:" << book_v[it->second].get_now_books();
cout << " 图书总数量:" << book_v[it->second].get_sum_books() << endl;
}//book是存放所有书籍的vector
it++;
begin = it;
}
if (flag == 0) {
cout << "未能找到相似图书!" << endl;
}
}
//利用作者进行模糊查找
void book_lookup::c2_bookzuozhe(string s) {
multimap<string, int>::iterator it, p1, p2, p, begin;
p1 = book_zuozhe.begin();
int flag = 0;
p2 = book_zuozhe.end();
begin = p1;
for (p = p1; p != p2; p++)
{
it = find_if(begin, book_zuozhe.end(), map_value_finder(s));
if (it == book_zuozhe.end()) {
//cout << "未能找到相似图书!" << endl;
return;
}
else {
flag = 1;
//cout << book_v[it->second];
cout << "书号:" << book_v[it->second].get_nums();
cout << " 书名:" << book_v[it->second].get_name();
cout << " 作者:" << book_v[it->second].get_zuozhe();
cout << " 出版社:" << book_v[it->second].get_press();
cout << " 出版日期:" << book_v[it->second].get_date().get_year() << "年 " << book_v[it->second].get_date().get_month() << "月 " << book_v[it->second].get_date().get_day() << "日";
cout << " 图书类型:" << book_v[it->second].get_book_size();
cout << " 图书在馆数量:" << book_v[it->second].get_now_books();
cout << " 图书总数量:" << book_v[it->second].get_sum_books() << endl;
}
it++;
begin = it;
}
if (flag == 0) {
cout << "未能找到相似图书!" << endl;
}
}
//精确查找
//作者+出版社
void book_lookup::zuozhe_press_find(string zuozhe, string press) {
multimap<string, int>::iterator it;
int flag = 0;
pair < multimap<string, int>::iterator, multimap<string, int>::iterator>range;
range = book_zuozhe.equal_range(zuozhe);
for (it = range.first; it != range.second; it++) {
flag = 1;
if (book_v[it->second].get_press() == press) {
cout << "书号:" << book_v[it->second].get_nums();
cout << " 书名:" << book_v[it->second].get_name();
cout << " 作者:" << book_v[it->second].get_zuozhe();
cout << " 出版社:" << book_v[it->second].get_press();
cout << " 出版日期:" << book_v[it->second].get_date().get_year() << "年 " << book_v[it->second].get_date().get_month() << "月 " << book_v[it->second].get_date().get_day() << "日";
cout << " 图书类型:" << book_v[it->second].get_book_size();
cout << " 图书在馆数量:" << book_v[it->second].get_now_books();
cout << " 图书总数量:" << book_v[it->second].get_sum_books() << endl;
}
}
if (flag == 0) {
cout << "未找到符合相关条件的书!" << endl;
}
}
//书名+作者
void book_lookup::zuozhe_bname_find(string name, string zuozhe) {
multimap<string, int>::iterator it;
pair < multimap<string, int>::iterator, multimap<string, int>::iterator>range;
range = book_name.equal_range(name);
int flag = 0;
for (it = range.first; it != range.second; it++) {
if (book_v[it->second].get_zuozhe() == zuozhe) {
flag = 1;
cout << "书号:" << book_v[it->second].get_nums();
cout << " 书名:" << book_v[it->second].get_name();
cout << " 作者:" << book_v[it->second].get_zuozhe();
cout << " 出版社:" << book_v[it->second].get_press();
cout << " 出版日期:" << book_v[it->second].get_date().get_year() << "年 " << book_v[it->second].get_date().get_month() << "月 " << book_v[it->second].get_date().get_day() << "日";
cout << " 图书类型:" << book_v[it->second].get_book_size();
cout << " 图书在馆数量:" << book_v[it->second].get_now_books();
cout << " 图书总数量:" << book_v[it->second].get_sum_books() << endl;
}
}
if (flag == 0) {
cout << "未找到符合相关条件的书!" << endl;
}
}
//学生信息查询
//虽然也可以进行模糊查找,但是本人觉得不会有人自己学号都记不住吧,所以说还是学号精确查找会比较方便一些
class student_lookup {
public:
vector<Student>st_v;
multimap<string, int>st_nums;
multimap<string, int>st_name;
multimap<date, int>st_date;
//void st_add();
//精确查找学号
void st_lookup1(string nums);
//姓名查找
void st_lookup2(string name);
//学号+日期
void st_lookup3(string nums,date aa);
};
void student_lookup::st_lookup1(string nums) {
multimap<string, int>::iterator it;
it = st_nums.find(nums);
if (it != st_nums.end()) {
cout << " 学号:"<<st_v[it->second].get_nums();
cout << " 姓名:"<<st_v[it->second].get_name();
cout << " 专业:"<<st_v[it->second].get_major();
cout << " 年级:"<<st_v[it->second].get_grade();
cout << " 借阅数量:"<<st_v[it->second].get_borrow() << endl;
}
else {
cout << "没有查到该学生的信息!" << endl;
}
}
void student_lookup::st_lookup2(string name) {
multimap<string, int>::iterator it;
if (st_name.find(name) != st_name.end()) {
pair < multimap<string, int>::iterator, multimap<string, int>::iterator>range;
range = st_name.equal_range(name);
for (it = range.first; it != range.second; it++) {
cout << " 学号:" << st_v[it->second].get_nums();
cout << " 姓名:" << st_v[it->second].get_name();
cout << " 专业:" << st_v[it->second].get_major();
cout << " 年级:" << st_v[it->second].get_grade();
cout << " 借阅数量:" << st_v[it->second].get_borrow() << endl;
}
}
else {
cout << "未能找到该学生信息!" << endl;
}
}
//图书操作类
class book_admin {
book_lookup p;
public:
book_admin() {
book_xie();
}
~book_admin() {
book_du();
}
//文件读写函数
void book_xie();
void book_du();
//增加
void book_add(books b);
//最终要的查询操作
int c_booknums(string nums);
void c1_bookname(string name);
void c2_bookname(string s);
void c1_bookzuozhe(string zuozhe);
void c2_bookzuozhe(string s);
void c1_bookpress(string press);
//void c2_bookpress(string s);
void c1_booksize(string size);
//void c2_booksize(string size);
void c1_date(date a);
void c2_date(date a, date b);
void jingque1(string name, string zuozhe);
void jingque2(string name, string press);
//修改(需要重建map),为什么需要重建因为map会自动排序
void xiu_booknums(string nums, books book);
//删除(需要重建map)
void del_book(string nums);
//重建map函数
void new_bookmap();
//图书数量更改(借出)
void sum_book1(string nums);
//还回
void sum_book2(string nums);
//展示所有图书
void book_display() {p.book_display();}
};
void book_admin::book_xie() {
p.book_v.clear();
books book;
ifstream ifs("book.txt", ios::in);
if (!ifs) { return; }
//int a = 0;
while (ifs >> book) {
//a++;
p.book_v.push_back(book);
p.book_nums.insert(make_pair(book.get_nums(), p.book_v.size() - 1));
p.book_name.insert(make_pair(book.get_name(), p.book_v.size() - 1));
p.book_zuozhe.insert(make_pair(book.get_zuozhe(), p.book_v.size() - 1));
p.book_press.insert(make_pair(book.get_press(), p.book_v.size() - 1));
p.book_size.insert(make_pair(book.get_book_size(), p.book_v.size() - 1));
p.book_date.insert(make_pair(book.get_date(), p.book_v.size() - 1));
}
}
void book_admin::book_du() {
//cout << " * ****" << endl;
fstream ofs("book.txt", ios::out);
vector<books>::iterator it;
//for (it = book_v.begin(); it < book_v.end(); it++) {
// cout << *it;//文件读取工作一定要注意
//}
for (it = p.book_v.begin(); it < p.book_v.end(); it++) {
ofs << *it;//文件读取工作一定要注意
}
}
void book_admin::book_add(books b) {
multimap<string, int>::iterator it;
it = p.book_nums.find(b.get_nums());
if (it == p.book_nums.end()) {
p.book_v.push_back(b);
b.set_sumbooks(b.get_sum_books() + 1);
b.set_nowbooks(b.get_now_books() + 1);
p.book_nums.insert(make_pair(b.get_nums(), p.book_v.size() - 1));
p.book_name.insert(make_pair(b.get_name(), p.book_v.size() - 1));
p.book_zuozhe.insert(make_pair(b.get_zuozhe(), p.book_v.size() - 1));
p.book_press.insert(make_pair(b.get_press(), p.book_v.size() - 1));
p.book_size.insert(make_pair(b.get_book_size(), p.book_v.size() - 1));
p.book_date.insert(make_pair(b.get_date(), p.book_v.size() - 1));
cout << "新的图书已经添加成功!" << endl;
}
else {
b.set_sumbooks(p.book_v[it->second].get_sum_books() + 1);
b.set_nowbooks(p.book_v[it->second].get_now_books() + 1);
p.book_v[it->second] = b;
cout << "重复图书已经添加成功!" << endl;
}
}
int book_admin::c_booknums(string nums) {
return p.c_booknums(nums);
}
void book_admin::c1_bookname(string name) {
p.c1_bookname(name);
}
void book_admin::c1_bookpress(string press) {
p.c1_bookpress(press);
}
void book_admin::c1_booksize(string size) {
p.c1_booksize(size);
}
void book_admin::c1_bookzuozhe(string zuoshe) {
p.c1_bookzuozhe(zuoshe);
}
void book_admin::c1_date(date a) {
p.c1_date(a);
}
void book_admin::c2_date(date a, date b) {
p.c2_date(a, b);
}
//模糊查找,重载find_if函数
void book_admin::c2_bookname(string s) {
p.c2_bookname(s);
}
//利用作者进行模糊查找
void book_admin::c2_bookzuozhe(string s) {
p.c2_bookzuozhe(s);
}
//精确查找
//书名+作者
void book_admin::jingque1(string name, string zuozhe) {
p.zuozhe_bname_find(name, zuozhe);
}
//作者+出版社
void book_admin::jingque2(string name, string press) {
p.zuozhe_press_find(name, press);
}
//重构map
void book_admin::new_bookmap() {
vector<books>::iterator it;
p.book_name.clear();
p.book_nums.clear();
p.book_zuozhe.clear();
p.book_press.clear();
p.book_size.clear();
p.book_date.clear();
int side = 0;
for (it = p.book_v.begin(); it < p.book_v.end(); it++) {
side = it - p.book_v.begin();
p.book_nums.insert(make_pair(it->get_nums(), side));
p.book_name.insert(make_pair(it->get_name(), side));
p.book_zuozhe.insert(make_pair(it->get_zuozhe(), side));
p.book_press.insert(make_pair(it->get_press(), side));
p.book_size.insert(make_pair(it->get_book_size(), side));
p.book_date.insert(make_pair(it->get_date(), side));
}
}
//修改操作
void book_admin::xiu_booknums(string nums, books book) {
multimap<string, int>::iterator it;
it = p.book_nums.find(nums);
if (it == p.book_nums.end()) {
cout << "该书未能找到!" << endl;
return;
}
else {
p.book_v[it->second] = book;
new_bookmap();
}
}
//删除操作
void book_admin::del_book(string nums) {
multimap<string, int>::iterator it;
it = p.book_nums.find(nums);
if (it == p.book_nums.end()) {
cout << "该书未能找到!" << endl;
return;
}
else {
//cout << "111111111" << endl;
int index = it->second;
p.book_v.erase(p.book_v.begin() + index);
new_bookmap();
cout << "删除成功!" << endl;
}
}
//借出的书容量-1
void book_admin::sum_book1(string nums) {
multimap<string, int>::iterator it;
it = p.book_nums.find(nums);
if (it == p.book_nums.end()) {
cout << "尚未找到该图书!" << endl;
return;
}
else {
int a = p.book_v[it->second].get_now_books();
int b = p.book_v[it->second].get_sum_books();
p.book_v[it->second].set_nowbooks(a - 1);
p.book_v[it->second].set_sumbooks(b - 1);
cout << "借阅该书籍成功!" << endl;
}
}
void book_admin::sum_book2(string nums) {
multimap<string, int>::iterator it;
it = p.book_nums.find(nums);
if (it == p.book_nums.end()) {
cout << "尚未找到该图书!" << endl;
return;
}
else {
int a = p.book_v[it->second].get_now_books();
int b = p.book_v[it->second].get_sum_books();
p.book_v[it->second].set_nowbooks(a+1);
p.book_v[it->second].set_sumbooks(b+1);
}cout << "还回该书籍成功!" << endl;
}
//学生操作类
class st_admin {
student_lookup p;
public:
st_admin(){ st_xie(); }
~st_admin()
{
st_du();
}
//文件读写函数
void st_xie();
void st_du();
//增加
void st_add(Student b);
//最终要的查询操作
void st_lookup1(string nums);
//姓名查找
void st_lookup2(string name);
//学号+日期
void st_lookup3(string nums, date aa);
//修改(需要重建map),为什么需要重建因为map会自动排序
void xiu_stnums(string nums, Student s);
//删除(需要重建map)
void del_student(string nums);
//重建map函数
void new_st_map();
//学生借书量
int student_book1(string s);
//学生还书量
void student_book2(string s);
void st_display();
};
//借出,学生借阅数量增加
int st_admin::student_book1(string s) {
multimap<string, int>::iterator it;
it = p.st_nums.find(s);
if (it == p.st_nums.end()) {
cout << "未能找到该学生信息!" << endl;
return 0;
}
else {
int a = p.st_v[it->second].get_borrow();
if (a >=5) {
cout << "您的图书借阅量已达上线,不能够再借阅!" << endl;
return -1;
}
else {
p.st_v[it->second].set_borrow(a + 1);
return 0;
}
}
//p.book_v[it->second].set_sumbooks(b - 1);
}
void st_admin::student_book2(string s) {
multimap<string, int>::iterator it;
it = p.st_nums.find(s);
if (it == p.st_nums.end()) {
cout << "未能找到该学生信息!" << endl;
return;
}
else {
int a = p.st_v[it->second].get_borrow();
p.st_v[it->second].set_borrow(a-1);
}
//p.book_v[it->second].set_sumbooks(b - 1);
}
void st_admin::st_xie() {
p.st_v.clear();
Student st;
ifstream ifs("student.txt", ios::in);
if (!ifs) { return; }
//int a = 0;
while (ifs >>st) {
//a++;
p.st_v.push_back(st);
p.st_nums.insert(make_pair(st.get_nums(), p.st_v.size() - 1));
p.st_name.insert(make_pair(st.get_name(), p.st_v.size() - 1));
//p.st_date.insert(make_pair(st.get_date(), p.st_v.size() - 1));
}
}
void st_admin::st_du() {
fstream ofs("student.txt", ios::out);
vector<Student>::iterator it;
for (it = p.st_v.begin(); it < p.st_v.end(); it++) {
ofs << *it<<endl;//文件读取工作一定要注意
}
}
void st_admin::st_add(Student b) {
p.st_v.push_back(b);
p.st_nums.insert(make_pair(b.get_nums(), p.st_v.size() - 1));
p.st_name.insert(make_pair(b.get_name(), p.st_v.size() - 1));
//p.st_date.insert(make_pair(b.get_date(), p.st_v.size() - 1));
}
void st_admin::st_lookup1(string nums) {
p.st_lookup1(nums);
}
void st_admin::st_lookup2(string name) {
p.st_lookup2(name);
}
//学生信息重建map
void st_admin::new_st_map() {
p.st_name.clear();
p.st_nums.clear();
p.st_date.clear();
int side = 0;
vector<Student>::iterator it;
for (it = p.st_v.begin(); it != p.st_v.end(); it++) {
side = it - p.st_v.begin();
p.st_nums.insert(make_pair(it->get_nums(), side));
p.st_name.insert(make_pair(it->get_name(), side));
//p.st_date.insert(make_pair(it->get_date(), side));
}
}
//学生信息修改操作
void st_admin::xiu_stnums(string nums, Student s) {
multimap<string, int>::iterator it;
if(p.st_nums.find(nums)==p.st_nums.end()) {
cout << "未能找到该学生!" << endl;
return;
}
else {
it = p.st_nums.find(nums);
p.st_v[it->second] = s;
new_st_map();
cout << "该学生信息已修改成功!" << endl;
}
}
//删除操作
void st_admin::del_student(string nums) {
multimap<string, int>::iterator it;
if (p.st_nums.find(nums) == p.st_nums.end()) {
cout << "未能找到该学生!" << endl;
return;
}
else {
it = p.st_nums.find(nums);
int index = it->second;
p.st_v.erase(p.st_v.begin() + index);
//cout << 1 << endl;
new_st_map();
cout << "该学生信息删除成功!" << endl;
}
}
//学生信息展示
void st_admin::st_display() {
vector<Student>::iterator it;
for (it = p.st_v.begin(); it != p.st_v.end(); it++) {
cout << " 学号:" << it->get_nums();
cout << " 姓名:" << it->get_name();
cout << " 专业:" << it->get_major();
cout << " 年级:" << it->get_grade();
cout << " 借阅数量:" << it->get_borrow() << endl;
}
}
//借阅纪录类(借阅记录一般不采用删除或者修改,所以这里我只写了增加记录,以及利用学号查询记录,还有日期查询记录的方式)
//然后我们也要想到借阅记录的增加,首先是图书现存量-1,以及学生本人借书量+1,这里我也想将最大借书总量加上,等后期我会继续维护
//借阅,还回,两种状态
class record_admin {
book_admin p1;
st_admin p2;
vector<record>r_v;
multimap<string, int>r_nums;
multimap<string, int>r_name;
multimap<string, int>r_b_nums;
multimap<date, int>r_date;
public:
record_admin() {
record_xie();
p1.book_xie();
p2.st_xie();
}
~record_admin()
{
record_du();
p1.book_du();
p2.st_du();
}
void record_xie();
void record_du();
void re_add(record b);
void re_nums_find(string s);
void re_name_find(string s);
void re_nums_b_find(string s);
void re_date_find1(date ss);
void re_date_find2(date a,date b);
void re_date_find3(string s, date a, date b);
void re_size_find(string s1, string s2);
void re_display();
};
void record_admin::record_xie() {
r_v.clear();
record r;
ifstream ifs("Record.txt", ios::in);
if (!ifs) { return; }
//int a = 0;
while (ifs >> r) {
//a++;
r_v.push_back(r);
r_nums.insert(make_pair(r.get_stnums(), r_v.size() - 1));
r_b_nums.insert(make_pair(r.get_bnums(), r_v.size() - 1));
r_date.insert(make_pair(r.get_date(), r_v.size() - 1));
r_name.insert(make_pair(r.get_bname(), r_v.size() - 1));
}
ifs.close();
}
void record_admin::record_du() {
fstream ofs("Record.txt", ios::out);
vector<record>::iterator it;
for (it = r_v.begin(); it < r_v.end(); it++) {
ofs << *it << endl;//文件读取工作一定要注意
}
}
void record_admin::re_add(record b) {
//重点就是借阅记录的增加啊啊啊啊啊!!!!
if (p1.c_booknums(b.get_bnums())==0) {
string a = b.get_bnums();
string c = b.get_stnums();
if (b.get_ssize() == "借出") {
//借出的时候书-1,学生借的数量+1
//p2.student_book1(c);
if (p2.student_book1(c) == -1) {
return;
}
r_v.push_back(b);
r_nums.insert(make_pair(b.get_stnums(), r_v.size() - 1));
r_b_nums.insert(make_pair(b.get_bnums(), r_v.size() - 1));
r_date.insert(make_pair(b.get_date(), r_v.size() - 1));
r_name.insert(make_pair(b.get_bname(), r_v.size() - 1));
p1.sum_book1(a);
}
else if (b.get_ssize() == "还回") {
//还回
r_v.push_back(b);
r_nums.insert(make_pair(b.get_stnums(), r_v.size() - 1));
r_b_nums.insert(make_pair(b.get_bnums(), r_v.size() - 1));
r_date.insert(make_pair(b.get_date(), r_v.size() - 1));
r_name.insert(make_pair(b.get_bname(), r_v.size() - 1));
p1.sum_book2(a);
p2.student_book2(c);
}
else {
r_v.push_back(b);
r_nums.insert(make_pair(b.get_stnums(), r_v.size() - 1));
r_b_nums.insert(make_pair(b.get_bnums(), r_v.size() - 1));
r_date.insert(make_pair(b.get_date(), r_v.size() - 1));
r_name.insert(make_pair(b.get_bname(), r_v.size() - 1));
p1.sum_book1(a);
}
cout << "借阅记录添加成功!" << endl;
}
else {
cout << "未找到该图书!" << endl;
}
}
void record_admin::re_nums_find(string s) {
multimap<string, int>::iterator it;
if (r_nums.find(s) != r_nums.end()) {
pair < multimap<string, int>::iterator, multimap<string, int>::iterator>range;
range = r_nums.equal_range(s);
for (it = range.first; it != range.second; it++) {
cout <<"书号:" << r_v[it->second].get_bnums()<<" 书名:" << r_v[it->second].get_bname() << " 学号:" << r_v[it->second].get_stnums() << " 借阅类型:" << r_v[it->second].get_ssize();
cout <<" 图书类型:"<<r_v[it->second].get_bsize();
cout <<" 借阅日期:"<< r_v[it->second].get_date().get_year()<<"(年) " << r_v[it->second].get_date().get_month()<<"(月)"<< r_v[it->second].get_date().get_day()<<"(日)"<<endl;
}
}
else {
cout << "该学生的借阅记录未找到!" << endl;
}
}
//利用书名进行查询
void record_admin::re_name_find(string s) {
multimap<string, int>::iterator it;
if (r_name.find(s) != r_name.end()) {
pair < multimap<string, int>::iterator, multimap<string, int>::iterator>range;
range = r_name.equal_range(s);
for (it = range.first; it != range.second; it++) {
cout << "书号:" << r_v[it->second].get_bnums() << " 书名:" << r_v[it->second].get_bname() << " 学号:" << r_v[it->second].get_stnums() << " 借阅类型:" << r_v[it->second].get_ssize();
cout << " 图书类型:" << r_v[it->second].get_bsize();
cout << " 借阅日期:" << r_v[it->second].get_date().get_year() << "(年) " << r_v[it->second].get_date().get_month() << "(月)" << r_v[it->second].get_date().get_day() << "(日)" << endl;
}
}
else {
cout << "该书名的借阅记录未找到!" << endl;
}
}
void record_admin::re_nums_b_find(string s) {
multimap<string, int>::iterator it;
if (r_b_nums.find(s) != r_b_nums.end()) {
pair < multimap<string, int>::iterator, multimap<string, int>::iterator>range;
range = r_b_nums.equal_range(s);
for (it = range.first; it != range.second; it++) {
cout << "书号:" << r_v[it->second].get_bnums() << " 书名:" << r_v[it->second].get_bname() << " 学号:" << r_v[it->second].get_stnums() << " 借阅类型:" << r_v[it->second].get_ssize();
cout << " 图书类型:" << r_v[it->second].get_bsize();
cout << " 借阅日期:" << r_v[it->second].get_date().get_year() << "(年) ";
cout<< r_v[it->second].get_date().get_month() << "(月)" << r_v[it->second].get_date().get_day() << "(日)" << endl;
}
}
else {
cout << "该图书的借阅记录未找到!" << endl;
}
}
//借阅记录单天查询
void record_admin::re_date_find1(date ss) {
multimap<date, int>::iterator it;
if (r_date.find(ss) != r_date.end()) {
pair < multimap<date, int>::iterator, multimap<date, int>::iterator>range;
range = r_date.equal_range(ss);
for (it = range.first; it != range.second; it++) {
cout << "书号:" << r_v[it->second].get_bnums() << " 书名:" << r_v[it->second].get_bname() << " 学号:" << r_v[it->second].get_stnums() << " 借阅类型:" << r_v[it->second].get_ssize();
cout << " 图书类型:" << r_v[it->second].get_bsize();
cout << " 借阅日期:" << r_v[it->second].get_date().get_year() << "(年) ";
cout << r_v[it->second].get_date().get_month() << "(月)" << r_v[it->second].get_date().get_day() << "(日)" << endl;
}
}
else {
cout << "该日期的借阅记录未找到!" << endl;
}
}
//借阅记录日期查询
void record_admin::re_date_find2(date a, date b) {
multimap<date, int>::iterator it1, it2, it;
it1 = r_date.lower_bound(a);
it2 = r_date.upper_bound(b);
for (it = it1; it != it2; it++) {
//cout << book_v[it->second];
cout << "书号:" << r_v[it->second].get_bnums() << " 书名:" << r_v[it->second].get_bname() << " 学号:" << r_v[it->second].get_stnums() << " 借阅类型:" << r_v[it->second].get_ssize();
cout << " 图书类型:" << r_v[it->second].get_bsize();
cout << " 借阅日期:" << r_v[it->second].get_date().get_year() << "(年) ";
cout << r_v[it->second].get_date().get_month() << "(月)" << r_v[it->second].get_date().get_day() << "(日)" << endl;
}
}
//学号+借阅记录日期
void record_admin::re_date_find3(string s, date a, date b) {
multimap<date, int>::iterator it1, it2, it;
bool flag = true;
it1 = r_date.lower_bound(a);
it2 = r_date.upper_bound(b);
for (it = it1; it != it2; it++) {
if (r_v[it->second].get_stnums() == s) {
flag = false;
//cout << book_v[it->second];
cout << "书号:" << r_v[it->second].get_bnums() << " 书名:" << r_v[it->second].get_bname() << " 学号:" << r_v[it->second].get_stnums() << " 借阅类型:" << r_v[it->second].get_ssize();
cout << " 图书类型:" << r_v[it->second].get_bsize();
cout << " 借阅日期:" << r_v[it->second].get_date().get_year() << "(年) ";
cout << r_v[it->second].get_date().get_month() << "(月)" << r_v[it->second].get_date().get_day() << "(日)" << endl;
}
}
if (flag == true) {
cout << "未找到该学生在指定日期的借阅记录!" << endl;
}
}
//图书类型+学号
void record_admin::re_size_find(string s1, string s2) {
multimap<string, int>::iterator it;
int flag = 0;
if (r_nums.find(s1) != r_nums.end()) {
pair < multimap<string, int>::iterator, multimap<string, int>::iterator>range;
range = r_nums.equal_range(s1);
for (it = range.first; it != range.second; it++) {
if (r_v[it->second].get_bsize() == s2) {
flag = 1;
cout << "书号:" << r_v[it->second].get_bnums() << " 书名:" << r_v[it->second].get_bname() << " 学号:" << r_v[it->second].get_stnums() << " 借阅类型:" << r_v[it->second].get_ssize();
cout << " 图书类型:" << r_v[it->second].get_bsize();
cout << " 借阅日期:" << r_v[it->second].get_date().get_year() << "(年) " << r_v[it->second].get_date().get_month() << "(月)" << r_v[it->second].get_date().get_day() << "(日)" << endl;
}
}
if (flag == 0) {
cout << "该学生的此类型图书借阅记录未找到!" << endl;
return;
}
}
else {
cout << "该学生的借阅记录未找到!" << endl;
}
}
void record_admin::re_display(){
vector<record>::iterator it;
for (it = r_v.begin(); it != r_v.end(); it++) {
cout << "书号:" << it->get_bnums() << " 书名:" << it->get_bname() << " 学号:" << it->get_stnums() << " 借阅类型:" << it->get_ssize();
cout << " 图书类型:" << it->get_bsize();
cout << " 借阅日期:" << it->get_date().get_year() << "(年) ";
cout << it->get_date().get_month() << "(月)" << it->get_date().get_day() << "(日)" << endl;
}
}
//多态c
class base {
public:
//virtual void add() = 0;
virtual void b_name_find(string name) = 0;
//书号查找
virtual void b_nums_find(string nums) = 0;
//出版社查找
virtual void b_press_find(string press) = 0;
//作者查找
virtual void b_zuozhe_find(string zuozhe) = 0;
//模糊查找
//书名进行模糊查找
virtual void mh_bname_find(string s) = 0;
//作者进行模糊查找
virtual void mh_zuozhe_find(string s) = 0;
//利用学号查看个人借阅信息
virtual void record_nums_find(string s) = 0;
//利用书号进行借阅查询
virtual void record_bnums_find(string s) = 0;
//利用书名进行借阅查询
virtual void record_bname_find(string s) = 0;
//精确查找!!!!!!!!!!!!!!!!!!!!
//书名+作者
virtual void jingque_find1(string name, string zuozhe) = 0;
//作者+出版社
virtual void jingque_find2(string zuozhe, string press) = 0;
};
//管理员工作类
class works :public base{
book_admin a;
st_admin b;
record_admin c;
string password;
public:
works() {}
//添加类的函数
//图书增加
void add(books a1) {a.book_add(a1);}
//学生信息增加
void add2(Student a1) {b.st_add(a1);}
//借阅记录增加
void add3(record a1) { c.re_add(a1); }
//查找函数
//书名查找
void b_name_find(string ss) {a.c1_bookname(ss);}
//书号查找
void b_nums_find(string nums) { a.c_booknums(nums); };
//出版社查找
void b_press_find(string press) { a.c1_bookpress(press); }
//作者查找
void b_zuozhe_find(string zuozhe) { a.c1_bookzuozhe(zuozhe); }
//模糊查找
//书名进行模糊查找
void mh_bname_find(string s) { a.c2_bookname(s); }
//作者进行模糊查找
void mh_zuozhe_find(string s) { a.c2_bookzuozhe(s); }
//利用学号查看学生信息(主要是看借阅了几本)
void st_nums_find(string s) { b.st_lookup1(s); }
//利用学号查看个人借阅信息
void record_nums_find(string s) { c.re_nums_find(s); }
//利用书号进行借阅查询
void record_bnums_find(string s) { c.re_nums_b_find(s); };
//利用书名进行借阅查询
void record_bname_find(string s) { c.re_name_find(s); }
//精确查找!!!!!!!!!!!!!!!!!!!!
//书名+作者
void jingque_find1(string name, string zuozhe) { a.jingque1(name, zuozhe); };
//作者+出版社
void jingque_find2(string zuozhe, string press) { a.jingque2(zuozhe, press); }
//出版日期查找
void publication_date1(date ss) {a.c1_date(ss);}
//出版区间查找
void publication_date2(date aa, date bb) { a.c2_date(aa, bb); }
//借阅日期查找(单天)
void borrow_date1(date s) { c.re_date_find1(s); }
//借阅日期查找(区间)
void borrow_date1(date s1, date s2) { c.re_date_find2(s1, s2); }
//图书信息修改(利用书号)因为图书不会轻易修改
void book_modify(string s,books aaa) {
a.xiu_booknums(s,aaa);
}
//学生信息修改(利用学号)还是说不会轻易修改
void student_modify(string s, Student aaa) {
b.xiu_stnums(s, aaa);
}
//图书信息删除(利用书号)因为图书不会轻易删除
void book_del(string s) {
a.del_book(s);
}
//学生信息删除(利用学号)还是说不会轻易删除
void student_del(string s) {
b.del_student(s);
}
//展示所有的图书
void book_display() {a.book_display();}
//展示所有的学生信息
void st_display() {b.st_display();}
//展示所有的借阅记录
void re_display() { c.re_display(); }
};
//客户端类
class client:public base {
book_admin a;
st_admin b;
record_admin c;
public:
//增加借阅记录
void add(record a1) { c.re_add(a1); }
//查找
//查找函数
//书名查找
void b_name_find(string ss) { a.c1_bookname(ss); }
//书号查找
void b_nums_find(string nums) { a.c_booknums(nums); };
//出版社查找
void b_press_find(string press) { a.c1_bookpress(press); }
//作者查找
void b_zuozhe_find(string zuozhe) { a.c1_bookzuozhe(zuozhe); }
//模糊查找
//书名进行模糊查找
void mh_bname_find(string s) { a.c2_bookname(s); }
//作者进行模糊查找
void mh_zuozhe_find(string s) { a.c2_bookzuozhe(s); }
//精确查找!!!!!!!!!!!!!!!!!!!!
//书名+作者
void jingque_find1(string name, string zuozhe) { a.jingque1(name, zuozhe); };
//作者+出版社
void jingque_find2(string zuozhe, string press) { a.jingque2(zuozhe, press); }
//查询本人借阅信息(利用学号)
void record_nums_find(string s) { c.re_nums_find(s); }
//利用书号进行借阅查询
void record_bnums_find(string s) { c.re_nums_b_find(s); };
//利用书名进行借阅查询
void record_bname_find(string s) { c.re_name_find(s); }
//学号+借阅记录日期
void re_stnums_date_find(string s, date a, date b) { c.re_date_find3(s, a, b); }
//学号+图书类型
void re_stnums_size_find(string s1, string s2) { c.re_size_find(s1, s2); }
};
//管理员类测试
class works_test {
public:
void add1();
void add2();
void add3();
//查找函数
//书名查找
void b_name_find();
//书号查找
void b_nums_find();
//出版社查找
void b_press_find();
//作者查找
void b_zuozhe_find();
//模糊查找
//书名进行模糊查找
void mh_bname_find();
//作者进行模糊查找
void mh_zuozhe_find();
//精确查找!!!!!!!!!!!!!!!!!!!!
//书名+作者
void jingque_find1(string name, string zuozhe);
//作者+出版社
void jingque_find2(string zuozhe, string press);
//利用学号查看学生信息(主要是看借阅了几本)
void st_nums_find();
//利用学号查看个人借阅信息
void record_nums_find();
//利用书号进行借阅查询
void record_bnums_find();
//利用书名进行借阅查询
void record_bname_find();
//精确查找!!!!!!!!!!!!!!!!!!!!
//书名+作者
void jingque_find1();
//作者+出版社
void jingque_find2();
//出版日期查找
void publication_date1();
//出版区间查找
void publication_date2();
//借阅日期查找(单天)
void borrow_date1();
//借阅日期查找(区间)
void borrow_date2();
//图书信息修改(利用书号)因为图书不会轻易修改
void book_modify();
//学生信息修改(利用学号)还是说不会轻易修改
void student_modify();
//图书信息删除(利用书号)因为图书不会轻易删除
void book_del();
//学生信息删除(利用学号)还是说不会轻易删除
void student_del();
//展示所有book
void book_display() {
works p;
p.book_display();
}
//展示所有学生信息
void st_display() {
works p;
p.st_display();
}
//展示所有借阅信息
void record_display() {
works p;
p.re_display();
}
//菜单
void works_menu() {
cout << "******************管理员系统界面******************" << endl;
cout << "** **" << endl;
cout << "** **" << endl;
cout << "** 1.增加图书 **" << endl;
cout << "** 2.查询图书 **" << endl;
cout << "** 3.修改图书 **" << endl;
cout << "** 4.删除图书 **" << endl;
cout << "** 5.添加学生 **" << endl;
cout << "** 6.查询学生 **" << endl;
cout << "** 7.修改学生 **" << endl;
cout << "** 8.删除学生 **" << endl;
cout << "** 9.增加借阅记录 **" << endl;
cout << "** 10.查询借阅记录 **" << endl;
cout << "** 11.退出管理员系统 **" << endl;
cout << "** **" << endl;
cout << "** **" << endl;
cout << "** **" << endl;
cout << "**************************************************" << endl;
}
};
void works_test::add1() {
works p;
string nums;
string name;
string zuozhe;
string press;
string book_size;
//date add;
int a;
int b;
int c;
int sum_books;
int now_books;
//in >> p.nums >> p.name >> p.zuozhe >> p.press >> p.book_size >> p.add >> p.sum_books >> p.now_books;
cout << "书号:"; cin >> nums;
cout << "书名:"; cin >> name;
cout << "作者:"; cin >> zuozhe;
cout << "出版社:"; cin >> press;
cout << "图书类型:"; cin >> book_size;
cout << "日期(年):"; cin >> a;
cout << "日期(月):"; cin >> b;
cout << "日期(日):"; cin >> c;
cout << "图书总量:"; cin >> sum_books;
cout << "图书在馆数量:"; cin >> now_books;
date add(a, b, c);
books bb(nums, name, zuozhe, press, book_size, add, sum_books, now_books);
p.add(bb);
}
void works_test::add2() {
st_admin p;
string s_nums;
string s_name;
string s_major;
string s_grade;
int s_borrow;
cout << "学号:"; cin >> s_nums;
cout << "姓名:"; cin >> s_name;
cout << "专业:"; cin >> s_major;
cout << "年级:"; cin >> s_grade;
cout << "借阅数量:"; cin >> s_borrow;
Student s(s_nums, s_name, s_major, s_grade, s_borrow);
p.st_add(s);
}
void works_test::add3() {
works p;
string b_nums;
string b_name;
string st_nums;
string s_size;
string b_size;
date ss;
cout << "请输入书号:"; cin >> b_nums;
cout << "请输入书名:"; cin >> b_name;
cout << "请输入学号:"; cin >> st_nums;
cout << "请输入借阅类型:"; cin >> s_size;
cout << "请输入图书类型:"; cin >> b_size;
cout << "请输入日期:"; cin >> ss;
record aa(b_nums, b_name, st_nums, s_size, b_size, ss);
p.add3(aa);
}
//查找函数
//书名查找
void works_test::b_name_find() {
works p;
string name;
cout << "*请您输入书名:"; cin >> name;
p.b_name_find(name);
}
//书号查找
void works_test::b_nums_find() {
works p;
string nums;
cout << "*请您输入书号:"; cin >> nums;
p.b_nums_find(nums);
};
//出版社查找
void works_test::b_press_find() {
works p;
string press;
cout << "*请您输入出版社:"; cin >> press;
p.b_press_find(press);
}
//作者查找
void works_test::b_zuozhe_find() {
works p;
string zuozhe;
cout << "*请您输入作者:"; cin >> zuozhe;
p.b_zuozhe_find(zuozhe);
}
//模糊查找
//书名进行模糊查找
void works_test::mh_bname_find() {
works p;
cout << "请输入书名:";
string s; cin >> s;
p.mh_bname_find(s);
}
//作者进行模糊查找
void works_test::mh_zuozhe_find() {
works p;
cout << "请输入作者:";
string s; cin >> s;
p.mh_zuozhe_find(s);
}
//利用学号查看学生信息(主要是看借阅了几本)
void works_test::st_nums_find() {
string nums;
cout << "请输入您需要查找的学号:"; cin >> nums;
works p;
p.st_nums_find(nums);
}
//利用学号查看个人借阅信息
void works_test::record_nums_find() {
string nums;
cout << "请您输入需要查找的学号:"; cin >> nums;
works p;
p.record_nums_find(nums);
}
//利用书号进行借阅查询
void works_test::record_bnums_find() {
string nums;
cout << "请您输入需要查找的书号:"; cin >> nums;
works p;
p.record_bnums_find(nums);
};
//利用书名进行借阅查询
void works_test::record_bname_find() {
string nums;
cout << "请您输入需要查找的书名:"; cin >> nums;
works p;
p.record_bname_find(nums);
}
//精确查找!!!!!!!!!!!!!!!!!!!!
//书名+作者
void works_test::jingque_find1() {
string name; string zuozhe;
cout << "请您输入需要查找的书名:"; cin >> name;
cout << "请您输入需要查找的作者:"; cin >> zuozhe;
works p;
p.jingque_find1(name, zuozhe);
};
//作者+出版社
void works_test::jingque_find2() {
string name; string zuozhe;
cout << "请您输入需要查找的作者:"; cin >> name;
cout << "请您输入需要查找的出版社:"; cin >> zuozhe;
works p;
p.jingque_find2(name, zuozhe);
}
//出版日期查找
void works_test::publication_date1() {
works p;
int a;
int b;
int c;
cout << "请您输入出版日期(年)"; cin >> a;
cout << "请您输入出版日期(月)"; cin >> b;
cout << "请您输入出版日期(日)"; cin >> c;
date d(a, b, c);
p.publication_date1(d);
}
//出版区间查找
void works_test::publication_date2() {
works p;
int a1;
int b1;
int c1;
int a2;
int b2;
int c2;
cout << "请您输入出版起始日期(年)"; cin >> a2;
cout << "请您输入出版起始日期(月)"; cin >> b2;
cout << "请您输入出版起始日期(日)"; cin >> c2;
cout << "请您输入出版结束日期(年)"; cin >> a1;
cout << "请您输入出版结束日期(月)"; cin >> b1;
cout << "请您输入出版结束日期(日)"; cin >> c1;
date d1(a2, b2, c2);
date d2(a1, b1, c1);
p.publication_date2(d1, d2);
}
//借阅日期查找(单天)
void works_test::borrow_date1() {
works p;
int a;
int b;
int c;
cout << "请您输入借阅日期(年)"; cin >> a;
cout << "请您输入借阅日期(月)"; cin >> b;
cout << "请您输入借阅日期(日)"; cin >> c;
date d(a, b, c);
p.borrow_date1(d);
}
//借阅日期查找(区间)
void works_test::borrow_date2() {
works p;
int a1;
int b1;
int c1;
int a2;
int b2;
int c2;
cout << "请您输入起始日期(年)"; cin >> a2;
cout << "请您输入起始日期(月)"; cin >> b2;
cout << "请您输入起始日期(日)"; cin >> c2;
cout << "请您输入结束日期(年)"; cin >> a1;
cout << "请您输入结束日期(月)"; cin >> b1;
cout << "请您输入结束日期(日)"; cin >> c1;
date d1(a2, b2, c2);
date d2(a1, b1, c1);
p.publication_date2(d1, d2);
}
//图书信息修改(利用书号)因为图书不会轻易修改
void works_test::book_modify() {
string nums;
string name;
string zuozhe;
string press;
string book_size;
//date add;
int a;
int b;
int c;
int sum_books;
int now_books;
//in >> p.nums >> p.name >> p.zuozhe >> p.press >> p.book_size >> p.add >> p.sum_books >> p.now_books;
cout << "请输入您要修改书的书号:"; cin >> nums;
cout << "请重新输入该书的内容:" << endl;
//cout << "书号:"; cin >> nums;
cout << "书名:"; cin >> name;
cout << "作者:"; cin >> zuozhe;
cout << "出版社:"; cin >> press;
cout << "图书类型:"; cin >> book_size;
cout << "日期(年):"; cin >> a;
cout << "日期(月):"; cin >> b;
cout << "日期(日):"; cin >> c;
cout << "图书总量:"; cin >> sum_books;
cout << "图书在馆数量:"; cin >> now_books;
date add(a, b, c);
books bb(nums, name, zuozhe, press, book_size, add, sum_books, now_books);
works p;
p.book_modify(nums, bb);
}
//学生信息修改(利用学号)还是说不会轻易修改
void works_test::student_modify() {
works p;
string s_nums;
string s_name;
string s_major;
string s_grade;
int s_borrow;
cout << "请输入您需要修改学生的学号:"; cin >> s_nums;
cout << "姓名:"; cin >> s_name;
cout << "专业:"; cin >> s_major;
cout << "年级:"; cin >> s_grade;
cout << "借阅数量:"; cin >> s_borrow;
Student s(s_nums, s_name, s_major, s_grade, s_borrow);
p.student_modify(s_nums, s);
}
//图书信息删除(利用书号)因为图书不会轻易删除
void works_test::book_del() {
string s;
cout << "请您输入需要删除的书的书号:";
cin >> s;
works p;
p.book_del(s);
}
//学生信息删除(利用学号)还是说不会轻易删除
void works_test::student_del() {
string s;
cout << "请您输入需要删除的学生信息的学号:";
cin >> s;
works p;
p.student_del(s);
}
//客户端测试
class client_test {
string st_nums;
public:
client_test(string s) {
st_nums = s;
}
client_test() {}
//增加借阅记录
void add();
//查找
//查找函数
//书名查找
void b_name_find();
//书号查找
void b_nums_find();
//出版社查找
void b_press_find();
//作者查找
void b_zuozhe_find();
//模糊查找
//书名进行模糊查找
void mh_bname_find();
//作者进行模糊查找
void mh_zuozhe_find();
//精确查找!!!!!!!!!!!!!!!!!!!!
//书名+作者
void jingque_find1();
//作者+出版社
void jingque_find2();
//查询本人借阅信息(利用学号)
void record_nums_find();
//利用书号进行借阅查询
void record_bnums_find();
//利用书名进行借阅查询
void record_bname_find();
//学号+借阅记录日期
void re_stnums_date_find();
//学号+图书类型
void re_stnums_size_find();
//客户端菜单
void client_menu();
};
//增加借阅记录
void client_test::add() {
client p;
string b_nums;
string b_name;
string st_nums;
string s_size;
string b_size;
date ss;
cout << "请输入书号:"; cin >> b_nums;
cout << "请输入书名:"; cin >> b_name;
cout << "请输入学号:"; cin >> st_nums;
cout << "请输入借阅类型:"; cin >> s_size;
cout << "请输入图书类型:"; cin >> b_size;
cout << "请输入日期:"; cin >> ss;
record aa(b_nums, b_name, st_nums, s_size, b_size, ss);
p.add(aa);
}
//查找
//查找函数
//书名查找
void client_test::b_name_find() {
works p;
string name;
cout << "*请您输入书名:"; cin >> name;
p.b_name_find(name);
}
//书号查找
void client_test::b_nums_find() {
client p;
string nums;
cout << "*请您输入书号:"; cin >> nums;
p.b_nums_find(nums);
};
//出版社查找
void client_test::b_press_find() {
client p;
string press;
cout << "*请您输入出版社:"; cin >> press;
p.b_press_find(press);
}
void client_test::client_menu() {
cout << "******************客户端系统界面******************" << endl;
cout << "** **" << endl;
cout << "** **" << endl;
cout << "** 1.借阅图书 **" << endl;
cout << "** 2.归还图书 **" << endl;
cout << "** 3.续借图书 **" << endl;
cout << "** 4.查阅图书 **" << endl;
cout << "** 5.查询本人借阅信息 **" << endl;
cout << "** 6.查询图书借阅信息 **" << endl;
cout << "** 7.退出客户端 **" << endl;
cout << "** **" << endl;
cout << "** **" << endl;
cout << "**************************************************" << endl;
}
//作者查找
void client_test::b_zuozhe_find() {
client p;
string zuozhe;
cout << "*请您输入作者:"; cin >> zuozhe;
p.b_zuozhe_find(zuozhe);
}
//模糊查找
//书名进行模糊查找
void client_test::mh_bname_find() {
client p;
cout << "请输入书名:";
string s; cin >> s;
p.mh_bname_find(s);
}
//作者进行模糊查找
void client_test::mh_zuozhe_find() {
client p;
cout << "请输入作者:";
string s; cin >> s;
p.mh_zuozhe_find(s);
}
//精确查找!!!!!!!!!!!!!!!!!!!!
//书名+作者
void client_test::jingque_find1() {
string name; string zuozhe;
client p;
cout << "请输入书名:"; cin >> name;
cout << "请输入作者:"; cin >> zuozhe;
p.jingque_find1(name, zuozhe);
};
//作者+出版社
void client_test::jingque_find2() {
string zuozhe; string press;
client p;
cout << "请输入作者:"; cin >> zuozhe;
cout << "请输入出版社:"; cin >> press;
p.jingque_find2(zuozhe, press);
}
//查询本人借阅信息(利用学号)
void client_test::record_nums_find() {
string nums;
cout << "请您输入学号:"; cin >> nums;
client p;
p.record_nums_find(nums);
}
//利用书号进行借阅查询
void client_test::record_bnums_find() {
string nums;
cout << "请您输入需要查找的书号:"; cin >> nums;
client p;
p.record_bnums_find(nums);
};
//利用书名进行借阅查询
void client_test::record_bname_find() {
string nums;
cout << "请您输入需要查找的书名:"; cin >> nums;
client p;
p.record_bname_find(nums);
}
//学号+借阅记录日期
void client_test::re_stnums_date_find() {
client p;
string aaa;
int a1;
int b1;
int c1;
int a2;
int b2;
int c2;
cout << "请您输入学号: "; cin >> aaa;
cout << "请您输入起始日期(年)"; cin >> a2;
cout << "请您输入起始日期(月)"; cin >> b2;
cout << "请您输入起始日期(日)"; cin >> c2;
cout << "请您输入结束日期(年)"; cin >> a1;
cout << "请您输入结束日期(月)"; cin >> b1;
cout << "请您输入结束日期(日)"; cin >> c1;
date d1(a2, b2, c2);
date d2(a1, b1, c1);
p.re_stnums_date_find(aaa, d1, d2);
}
//学号+图书类型
void client_test::re_stnums_size_find() {
string nums;
string size;
cout << "请您输入学号:"; cin >> nums;
cout << "请您输入图书类型:"; cin >> size;
client p;
p.re_stnums_size_find(nums, size);
}
//首页菜单
void fisrt_menu() {
cout << "*****************淼淼图书管理系统*****************" << endl;
cout << "** **" << endl;
cout << "** **" << endl;
cout << "** **" << endl;
cout << "** **" << endl;
cout << "** 1.管理员模式 **" << endl;
cout << "** 2.客户端模式 **" << endl;
cout << "** 3.退出系统 **" << endl;
cout << "** **" << endl;
cout << "** **" << endl;
cout << "** **" << endl;
cout << "** **" << endl;
cout << "** **" << endl;
cout << "**************************************************" << endl;
}
//菜单函数
int n = 0;int m = 0;
works_test p1;
client_test p2;
void init_z() {
system("cls");
fisrt_menu();
cout << "请您选择系统操作:";
cin >> n;
}
void init1() {
system("cls");
p1.works_menu();
cin >> m;
}
void admin_add() {
system("cls");
p1.add1();
system("pause");
}
void admin_chaxun() {
system("cls");
int t1=0;
//cout << "您可以进行的操作:" << endl;
cout << "1.书名查找" << endl;
cout << "2.书号查找" << endl;
cout << "3.出版社查找" << endl;
cout << "4.作者查找" << endl;
cout << "5.书名进行模糊查找" << endl;
cout << "6.作者进行模糊查找" << endl;
cout << "7.精确查找+书名+作者" << endl;
cout << "8.精确查找作者+出版社" << endl;
cout << "9.出版日期查找" << endl;
cout << "10.出版区间查找" << endl;
cout << "11.打印所有图书信息" << endl;
cout << "请选择您要进行的操作:" << endl;
cin >> t1;
system("cls");
switch (t1)
{
case 1:
p1.b_name_find();
system("pause");
break;
case 2:
p1.b_nums_find();
system("pause");
break;
case 3:
p1.b_press_find();
system("pause");
break;
case 4:
p1.b_zuozhe_find();
system("pause");
break;
case 5:
p1.mh_bname_find();
system("pause");
break;
case 6:
p1.mh_zuozhe_find();
system("pause");
break;
case 7:
p1.jingque_find1();
system("pause");
break;
case 8:
p1.jingque_find2();
system("pause");
break;
case 9:
p1.publication_date1();
system("pause");
break;
case 10:
p1.publication_date2();
system("pause");
break;
default:
p1.book_display();
system("pause");
break;
}
}
void admin_modity() {
system("cls");
p1.book_modify();
system("pause");
}
void admin_del() {
system("cls");
p1.book_del();
system("pause");
}
void admin_add2() {
system("cls");
p1.add2();
system("pause");
}
void st_find_admin() {
int t2 = 0;
system("cls");
cout << "请选择您要进行的操作:" << endl;
cout << "1.学号查询学生信息" << endl;
cout << "2.打印全部学生信息" << endl;
cin >> t2;
if (t2 == 1) {
//system("cls");
p1.st_nums_find();
system("pause");
}
else {
//system("cls");
p1.st_display();
system("pause");
}
}
void admin_re_find() {
system("cls");
//查询借阅记录
int t3 = 0;
system("cls");
cout << "1.书号查询" << endl;
cout << "2.书名查询" << endl;
cout << "3.学号查询" << endl;
cout << "4.日期查询" << endl;
cout << "5.日期区间查询" << endl;
cout << "6.打印所有借阅信息" << endl;
cout << "请输入您要进行的操作:" << endl;
cin >> t3;
switch (t3)
{
case 1:
p1.record_bnums_find();
system("pause");
break;
case 2:
p1.record_bname_find();
system("pause");
break;
case 3:
p1.record_nums_find();
system("pause");
break;
case 4:
p1.borrow_date1();
system("pause");
break;
case 5:
p1.borrow_date2();
system("pause");
break;
default:
p1.record_display();
system("pause");
break;
}
}
void admin_zong1() {
while (m != 11) {
init1();
switch (m)
{
case 1:
admin_add();
break;
case 2:
admin_chaxun();
break;
case 3:
admin_modity();
break;
case 4:
admin_del();
break;
case 5:
admin_add2();
break;
case 6://查询学生
st_find_admin();
break;
case 7:
system("cls");
p1.student_modify();
system("pause");
break;
case 8:
system("cls");
p1.student_del();
system("pause");
break;
case 9:
system("cls");
p1.add3();
system("pause");
break;
case 10:
admin_re_find();
break;
default:
cout << "已退出管理员系统!" << endl;
system("pause");
break;
}
}
}
void client_zong1() {
while (m != 7) {
system("cls");
p2.client_menu();
cin >> m;
int t1 = 0;
int t2 = 0;
int t3 = 0;
switch (m)
{
case 1:
system("cls");
p2.add();
system("pause");
break;
case 2:
system("cls");
p2.add();
system("pause");
break;
case 3:
system("cls");
p2.add();
system("pause");
break;
case 4:
system("cls");
cout << "1.书名查找" << endl;
cout << "2.书号查找" << endl;
cout << "3.出版社查找" << endl;
cout << "4.作者查找" << endl;
cout << "5.书名进行模糊查找" << endl;
cout << "6.作者进行模糊查找" << endl;
cout << "7.精确查找+书名+作者" << endl;
cout << "8.精确查找作者+出版社" << endl;
cout << "请选择您要进行的操作:" << endl;
cin >> t1;
switch (t1)
{
case 1:
p2.b_name_find();
system("pause");
break;
case 2:
p2.b_nums_find();
system("pause");
break;
case 3:
p2.b_press_find();
system("pause");
break;
case 4:
p2.b_zuozhe_find();
system("pause");
break;
case 5:
p2.mh_bname_find();
system("pause");
break;
case 6:
p2.mh_zuozhe_find();
system("pause");
break;
case 7:
p2.jingque_find1();
system("pause");
break;
case 8:
p2.jingque_find2();
system("pause");
break;
default:
break;
}
//system("pause");
break;
case 5:
system("cls");
cout << "1.输入学号查找本人借阅记录" << endl;
cout << "2.输入学号+日期查询借阅记录" << endl;
cout << "3.输入学号+图书类型查询借阅记录" << endl;
cout << "请选择您要进行的操作:" << endl;
cin >> t2;
if (t2 == 1) {
p2.record_nums_find();
}
else if (t2 == 2) {
p2.re_stnums_date_find();
}
else {
p2.re_stnums_size_find();
}
system("pause");
break;
case 6:
system("cls");
cout << "1.输入书号查找借阅记录" << endl;
cout << "2.输入书名查询借阅记录" << endl;
cout << "请选择您要进行的操作:" << endl;
cin >> t3;
if (t3 == 1) {
p2.record_bnums_find();
}
else {
p2.record_bname_find();
}
system("pause");
break;
default:
cout << "已退出客户端系统" << endl;
break;
}
}
}
void jieshu() {
cout << "已退出淼淼图书管理系统!" << endl;
cout << "欢迎再次使用!" << endl;
}
int main()
{
//test p;
//test_max();
//test_date();
//p.test_book();
//test_date2();
//caozuo p;
//test_newmap();
//test p;
//p.test_caozuo_add();
//p.test_caozuo_find1();
//p.test_caozuo_find2();
//p.test_date2();
//p.test_newmap();
//book_test1 a1;
//a1.add();
//a1.booknums_query();
//a1.zuozhe_query();
//a1.name_query();
//a1.press_query();
//a1.date1_query();
//a1.date2_query();
//a1.date2_query();
//book_test2 a2;
//a2.book_mohu_query();
//a2.zuozhe_mohu_query();
//book_test3 a3;
//a3.shanchu();
//a3.xiugai();
//student_test1 a1;
//a1.add();
//a1.add();
//a1.add();
//a1.add();
//a1.booknums_query();
//a1.studentnums_query();
//a1.name_query();
//student_test2 a2;
//a2.shanchu();
//a2.xiugai();
//record_test a1;
//a1.add();
//a1.add();
//a1.book_nums_find();
//a1.st_nums_find();
//a1.date_find();
//book_test1 a1;
//a1.add();
//*a1.add();
//a1.add();
//a1.booknums_query();
// a1.sum_book1();
//a1.sum_books2();
//record_test a1;
//a1.add();
//a1.st_nums_find();
//a1.book_nums_find();
//a1.date_find();
//works p;
//p.b_nums_find("1");
//works_test p;
//p.add1();
//p.add2();
//p.add3();
//p.b_name_find();
//p.b_nums_find();
//p.b_press_find();
//p.b_zuozhe_find();
//p.jingque_find1();
//p.jingque_find2();
//p.mh_bname_find();
//p.mh_zuozhe_find();
//client_test p;
//p.add();
//p.b_name_find();
//p.b_nums_find();
//p.b_press_find();
//p.b_zuozhe_find();
//精确全部都出了问题
//p.jingque_find1();
//p.jingque_find2();
//p.mh_bname_find();//模糊书名出问题了
//p.mh_zuozhe_find();
//p.record_bname_find();
//p.record_bnums_find();
//p.re_stnums_date_find();
//p.re_stnums_size_find();
//fisrt_menu();
while (n != 3)
{
init_z();
//管理员操作
if (n == 1) {
admin_zong1();
}
//客户端操作
if (n == 2) {
client_zong1();
}
if (n == 3) {
jieshu();
break;
}
}
}