这几天写大作业,本来已经调试成功了,但是过两天突然乱码了两个文件,导致我只能重新写。现在将写好的文件保存在这里,以免又乱码了。
1.Book.h
#ifndef BOOK_H_
#define BOOK_H_
#include<string>
#include<fstream>
#include<iostream>
#include<time.h>
using namespace std;
/*
此文件定义书本类book.
包括私有变量:name, code, author, time(出版日期),price(价格), available(是否可借),lend_time(可借日期数)
一共七个
公有函数:
构造函数,析构函数,显示图书信息函数,设置图书各私有变量的函数,
获得所有私有变量的函数
两个友元函数重载操作符<<和>>, 用来进行文件的读写。
一个函数CatchTime, 用来获得当前时间,以便进行记录
类变量:static int book_num用来记录书籍数量
*/
class book
{
private:
string name;
string code;
string author;
string time;
bool available;
float price;
int lend_time;
public:
static int book_num;
//构造函数
book(){}
book(string n, string c, string a, string t, float p, int le, bool av=false):
name(n), code(c), author(a), time(t), price(p), available(av), lend_time(le){}
//析构函数
~book(){}
//显示图书信息函数
void show();
//设置图书私有变量函数
void set_name(string);
void set_code(string);
void set_author(string);
void set_time(string);
void lend_or_return(bool);
void set_price(float);
void set_lend_time(int);
//获得所有变量的函数
string get_name();
string get_code();
string get_author();
string get_time();
bool get_available();
float get_price();
int get_lendtime();
friend istream& operator >> (istream& stream, book& b);
friend ostream& operator << (ostream& stream, book& b);
friend string CatchTime();
};
#endif // !_BOOK.H_
2.CatchTime.h
#ifndef CATCHTIME_H_
#define CATCHTIME_H_
#include<time.h>
#include<string>
using namespace std;
string CatchTime();
#endif // !CATCHTIME_H_
3.Librarian.h
#ifndef LIBRARIAN_H_
#define LIBRARIAN_H_
/*
图书管理员类Librarian_user,继承自User类和Log类
包含成员变量:Librarian_num(图书管理员人数),mode(恒为Librarian)
成员函数:构造函数(创建一个管理员对象,并且为User数组添加)
成员函数:Add_book(添加图书), Delete_book(删除图书),
Change_book(改变图书信息), Find_book(查找图书), Addup_book(统计所有图书)
*/
#include"user.h"
#include"Log.h"
#include"book.h"
#include"CatchTime.h"
class Librarian_user:public User, public Log
{
public:
static int Librarian_num; //图书管理员人数
const User_mode mode = Librarian;
Librarian_user() {}
Librarian_user(string, int, string, User*);
~Librarian_user(){}
//friend string CatchTime();
//下面是管理员对图书的操作
void Add_book(book* B);
void Delete_book(book* B);
void Change_book(book* B);
void Find_book(book* B);
void Addup_book(book* B);
};
#endif // !LIBRARIAN_H_
4.Log.h
#ifndef LOG_H_
#define LOG_H_
#include"user.h"
/*
这是用户注册和登录用的类
成员变量:当前用户和用户对应的User类中的下标
成员函数:构造函数,析构函数,注册(rigister),登录(login),判断登录是否成功(Log_success),
判断注册是否成功(rigister_success)
*/
class Log
{
public:
User us;
int number; //对应User类中的下标
Log();
~Log();
void rigister(User* pu);
void login(User* pu);
bool Log_success;
bool rig_success;
};
#endif // !LOG_H_
5.Reader.h
#ifndef READER_H_
#define READER_H_
//定义读者类
/*它时一个派生类,继承了User类和Log类
私有变量:borrow[10],表示最多借10本书
公有变量:Reader_num, 记录读者数量
公有函数:lend_book, return_book, lend_show, book_show
*/
#include"user.h"
#include"Log.h"
#include"book.h"
class Reader_user :public User, public Log
{
private:
book borrow[10]; //用户所借的书,最多10本
int book_lend; //已经借阅的书,默认为0
public:
void zc(User* u, Log lo, Reader_user* r); //读者类进行注册的函数
static int Reader_num; //读者数量
void lend_book(book* B); //借书
void return_book(book* B); //还书
void lend_show(); //查看已经借阅的图书
void book_show(book* B); //查看所有图书
Reader_user() :User() { User::mode = Reader; book_lend = 0; }//默认构造函数
Reader_user(string, int, string, User*); //构造函数
~Reader_user(){} //析构函数
};
#endif // !READER_H_
6.User.h
#ifndef USER_H_
#define USER_H_
#include<string>
using namespace std;
/*
这个文件定义用户类User,这是一个基类
私有对象:name,account(账户), password(密码), mode(用户类型)
公有函数:change_pass(更换密码),change_name(改变姓名), change_mode(改变身份),
get_mode(获得身份), get_name(获得姓名), show(展示信息)
公有对象:static int User_num用来记录当前用户人数
*/
enum User_mode{Librarian, Reader };//用户类型
class User
{
protected:
string name;
int account;
string password;
User_mode mode;
public:
static int User_num;
User(string, int, string, User_mode); //构造函数
User() { mode = Reader; } //默认构造函数
//User(const User& u1); //复制构造函数
~User();
void show();
void change_pass();
void set_pass(string); //这是注册用户时填入密码的函数
void change_name(string name);
void change_account(int);
void change_mode(User_mode);
string get_name();
User_mode get_mode();
int get_account();
string get_password(); //这个获得密码的函数似乎有点危险,不过不用我又无法登录
};
#endif // !USER_H_