/*! @file
/********************************************************************************
模块名 : CAdmin 类声明文件
文件名 : administrator.h
相关文件 : administrator.cpp
person.h
AdminManager.h
文件实现功能 : CAdmin类中函数及数据的声明
作者 : 任震宇
版本 : 1.0
--------------------------------------------------------------------------------
备注 : 基类为CPerson类
--------------------------------------------------------------------------------
修改记录 :
日 期 版本 修改人 修改内容
2011/6/10 1.0 任震宇 创建
*******************************************************************************/
#ifndef ADMINISTRATOR_H_INCLUDED
#define ADMINISTRATOR_H_INCLUDED
#include <string>
#include "Person.h"
extern const std::string ADMINLIST[];
/*! @class
******************************************************************************
类名称 : CAdmin
功能 : 管理员可以进行的操作,包括登录、查找、修改、显示、写入到文件等功能
--------------------------------------------------------------------------------
作者 : 任震宇
*****************************************************************************/
class CAdmin:public CPerson
{
public:
bool Login(char* ,char*); //管理员登录
void Solve(); //主功能
void ShowList(); //显示菜单
bool Find(bool=false); //查询管理员
void Modify(); //修改管理员
void NewAdmin(); //添加管理员
void Display(); //显示管理员
void WriteToFile(); //向文件里写入
};
#endif
/*! @file
/********************************************************************************
模块名 : CAdminManage 类声明文件
文件名 : AdminManager.h
相关文件 : AdminManager.cpp
administrator.h
文件实现功能 : CAdminManage类中函数及数据的声明
作者 : 任震宇
版本 : 1.0
--------------------------------------------------------------------------------
备注 :
--------------------------------------------------------------------------------
修改记录 :
日 期 版本 修改人 修改内容
2011/6/10 1.0 任震宇 创建
*******************************************************************************/
#ifndef ADMINMANAGER_H_INCLUDED
#define ADMINMANAGER_H_INCLUDED
#include <string>
/*! @class
******************************************************************************
类名称 : CAdminManage
功能 : 对管理员进行的操作,添加、修改、删除管理员等
--------------------------------------------------------------------------------
作者 : 任震宇
*****************************************************************************/
class CAdminManage
{
static const std::string LIST[]; //菜单
char m_chKey; //输入选择
public:
void AddAdmin(); //添加管理员
void ModifyAdmin(); //修改管理员
void DeleteAdmin(); //删除管理员
void GatherAdminInf(); //统计管理员信息
void Solve(); //主功能
void ShowList(); //显示菜单
void GetKey(); //获取输入选择
};
#endif
/*! @file
/********************************************************************************
模块名 : CBookManager 类声明文件
文件名 : BookManager.h
相关文件 : BookManager.cpp
BOOKS.H
文件实现功能 : CBookManager类中函数及数据的声明
作者 : 任震宇
版本 : 1.0
--------------------------------------------------------------------------------
备注 :
--------------------------------------------------------------------------------
修改记录 :
日 期 版本 修改人 修改内容
2011/6/10 1.0 任震宇 创建
*******************************************************************************/
#ifndef BOOKMANAGER_H_INCLUDED
#define BOOKMANAGER_H_INCLUDED
#include <string>
#include "BOOKS.H"
using namespace std;
/*! @class
******************************************************************************
类名称 : CBookManager
功能 : 对图书进行的操作,包括增加、修改、删除、统计图书
--------------------------------------------------------------------------------
作者 : 任震宇
*****************************************************************************/
class CBookManager
{
static const string LIST[]; //菜单
char m_chKey; //输入选择
public:
void InsertNewBook(); //增加图书
void ChangeBookInf(); //修改图书
void DeleteBook(); //删除图书
void GatherStatistics(); //统计图书
bool FindBook(CBook&,bool = false); //查找图书
bool FindBook(char*,CBook&,char = '1',bool = false); //查找图书,有删除功能
void Solve(); //主功能
void ShowList1(); //显示菜单
void ShowList2(); //显示另一套菜单
void ShowList3(); //显示更另一套菜单
void GetKey(); //获取输入
};
#endif
/*! @file
/********************************************************************************
模块名 : CBook 类声明文件
文件名 : BOOKS.H
相关文件 : BOOKS.CPP
BookManager.h
文件实现功能 : CBook类中函数及数据的声明
作者 : 任震宇
版本 : 1.0
--------------------------------------------------------------------------------
备注 :
--------------------------------------------------------------------------------
修改记录 :
日 期 版本 修改人 修改内容
2011/6/10 1.0 任震宇 创建
*******************************************************************************/
#ifndef BOOKS_H_INCLUDED
#define BOOKS_H_INCLUDED
#include <string>
#include <fstream>
#include "style.h"
#include "record.h"
using namespace std;
extern const string BOOKLIST[];
/*! @class
******************************************************************************
类名称 : CBook
功能 : 记录图书的有关信息和对图书的一些操作
--------------------------------------------------------------------------------
作者 : 任震宇
*****************************************************************************/
class CBook
{
char m_chTag; //是否删除的标志
char m_sName[ NAME_LENGTH ]; //图书名
char m_sISBN[ ISBN_LENGTH ]; //密码
int m_nTotal; //数量
int m_nLeft; //剩余数量
int m_nLend; //借出数量
public:
void GetInf(); //获取图书信息
void AppToFile(char *FileName); //添加到文件
bool ReadFromFile(fstream &file); //从文件里读取
int Display(); //显示信息
static void ShowLine(); //显示表头
void ADisplay(); //显示表头和信息,用于显示单本图书时
void ModifyInf(); //修改图书信息
bool Equal(char*, char); //查询两本书是否一致
char*GetISBN(); //返回图书编号
char*GetName(); //返回图书名
void Lend(CRecord); //借阅图书
bool Return(CRecord); //归还图书
};
#endif
/*! @file
/********************************************************************************
模块名 : CFinalMana 类声明文件
文件名 : finalMana.h
相关文件 : finalMana.cpp
文件实现功能 : CFinalMana类中函数及数据的声明
作者 : 任震宇
版本 : 1.0
--------------------------------------------------------------------------------
备注 :
--------------------------------------------------------------------------------
修改记录 :
日 期 版本 修改人 修改内容
2011/6/10 1.0 任震宇 创建
*******************************************************************************/
#ifndef FINALMANAGER_H_INCLUDED
#define FINALMANAGER_H_INCLUDED
#include <string>
#include "style.h"
using namespace std;
/*! @class
******************************************************************************
类名称 : CFinalMana
功能 : 最高一层的管理菜单,包括选择登录方式,重置系统等
--------------------------------------------------------------------------------
作者 : 任震宇
*****************************************************************************/
class CFinalMana
{
static const string LIST[]; //菜单
char m_chKey; //输入选择
char m_sUserName[ NAME_LENGTH ]; //用户名
char m_sPassword[ PASSWORD_LENGTH ]; //密码
public:
static void ShowList(); //显示菜单
static void ShowList2(); //显示另一个菜单
void Reset(); //重置系统
void GetKey(); //获取输入选择
void Solve(); //主功能
void ShowLogin(); //显示登录菜单
void ClearBook(); //清空图书
void ClearAdmin(); //清空管理员
void ClearReaderCard(); //清空读者卡
void ClearReaderRecord(); //清空借阅记录
void ClearRecord(); //清空记录
bool ShowAsk(char*); //询问
void ResetPassword(); //设置重置密码
};
#endif
/*! @file
/********************************************************************************
模块名 : CLendManage 类声明文件
文件名 : LendManager.h
相关文件 : LendManager.cpp
文件实现功能 : CLendManage类中函数及数据的声明
作者 : 任震宇
版本 : 1.0
--------------------------------------------------------------------------------
备注 :
--------------------------------------------------------------------------------
修改记录 :
日 期 版本 修改人 修改内容
2011/6/10 1.0 任震宇 创建
*******************************************************************************/
#ifndef LENDMANAGER_H_INCLUDED
#define LENDMANAGER_H_INCLUDED
#include <string>
#include "BOOKS.H"
/*! @class
******************************************************************************
类名称 : CLendManage
功能 : 借阅、查找、归还、统计图书
--------------------------------------------------------------------------------
作者 : 任震宇
*****************************************************************************/
class CLendManage
{
static const std::string LIST[]; //菜单
char m_chKey; //输入选择
public:
bool FindBook(CBook &book); //查找图书
void LendBook(); //借阅图书
void ReturnBook(); //归还图书
void GatherLendStatistics(); //借阅图书统计
void ExpireBook(); //到期图书统计
void GatherFineInf(); //罚款统计
void Solve(); //借阅的主功能
void ShowList1(); //显示菜单
void GetKey(); //获取输入
};
#endif
/*! @file
/********************************************************************************
模块名 : CPerson 类声明文件
文件名 : Person.h
相关文件 : reader.h
administrator.h
文件实现功能 : CPerson类中函数及数据的声明
作者 : 任震宇
版本 : 1.0
--------------------------------------------------------------------------------
备注 :
--------------------------------------------------------------------------------
修改记录 :
日 期 版本 修改人 修改内容
2011/6/10 1.0 任震宇 创建
*******************************************************************************/
#ifndef PERSON_H_INCLUDED
#define PERSON_H_INCLUDED
#include <iostream>
#include <iomanip>
#include "style.h"
using namespace std;
/*! @class
******************************************************************************
类名称 : CPerson
功能 : 作为reader和admin的基类,有两者共同需要的功能:登录,创建密码等
--------------------------------------------------------------------------------
作者 : 任震宇
*****************************************************************************/
class CPerson
{
protected:
char m_chTag; //是否删除的标志
char m_sUserName[ NAME_LENGTH ]; //用户名
char m_sPassword[ PASSWORD_LENGTH ]; //密码
char m_chKey; //输入选择
public:
virtual bool Login(char* ,char*)=0; //登录的虚函数
virtual void Solve()=0; //主功能的虚函数
virtual void ShowList()=0; //显示表头的虚函数
char*GetName() //返回用户名
{
return m_sUserName;
}
void GetKey() //获取输入选择
{
cin >> m_chKey;
cin.clear();
}
void NewPassword() //新建密码
{
char pass2[ PASSWORD_LENGTH ];
do
{
cout < < setw( WID3 ) << "请输入密码:";
GetPassword(m_sPassword);
cout << setw( WID3 ) << "请再次输入密码:";
GetPassword(pass2);
if(strcmp( m_sPassword, pass2 ))
{
cout << "两次输入不一致,请重新输入!" << endl;
}
}while(strcmp( m_sPassword, pass2 ));
}
};
#endif
/*! @file
/********************************************************************************
模块名 : CReader 类声明文件
文件名 : reader.h
相关文件 : Person.h
reader.cpp
文件实现功能 : CReader类中函数及数据的声明
作者 : 任震宇
版本 : 1.0
--------------------------------------------------------------------------------
备注 :
--------------------------------------------------------------------------------
修改记录 :
日 期 版本 修改人 修改内容
2011/6/10 1.0 任震宇 创建
*******************************************************************************/
#ifndef READER_H_INCLUDED
#define READER_H_INCLUDED
#include "Person.h"
#include "BOOKS.H"
#include "record.h"
extern const string READERLIST[];
/*! @class
******************************************************************************
类名称 : CReader
功能 : 读者的基本信息及其操作
--------------------------------------------------------------------------------
作者 : 任震宇
*****************************************************************************/
class CReader:public CPerson
{
int m_nCardNum; //读者卡号
public:
bool Login(char* ,char*); //验证登录
void Solve(); //读者的主功能
void ShowList(); //显示菜单
void ShowList2(); //显示另一个菜单
void BorrowBook(CRecord); //借阅图书
bool ReturnBook(CRecord); //归还图书
bool Find(int,bool=false); //查询读者
int Display(); //显示读者信息
void NewReader(int); //新建读者
void AppToFile(); //添加到文件
void Modify(); //修改读者
void GetBorrowInf(); //显示借阅信息
void ShowHead(); //显示表头
};
#endif
/*! @file
/********************************************************************************
模块名 : CReaderManage 类声明文件
文件名 : ReaderManager.h
相关文件 : ReaderManager.cpp
reader.h
文件实现功能 : CReaderManage类中函数及数据的声明
作者 : 任震宇
版本 : 1.0
--------------------------------------------------------------------------------
备注 :
--------------------------------------------------------------------------------
修改记录 :
日 期 版本 修改人 修改内容
2011/6/10 1.0 任震宇 创建
*******************************************************************************/
#ifndef READERMANAGER_H_INCLUDED
#define READERMANAGER_H_INCLUDED
#include <string>
/*! @class
******************************************************************************
类名称 : CReaderManage
功能 : 管理读者类,申请、删除、修改、统计读者卡
--------------------------------------------------------------------------------
作者 : 任震宇
*****************************************************************************/
class CReaderManage
{
static const std::string LIST[]; //菜单信息
char m_chKey; //输入选择
static int s_nCardNum; //当前要给的卡号
public:
void ApplyReaderCard(); //申请读者卡
void DeleteReaderCard(); //删除读者卡
void ModifyReaderCard(); //修改读者卡
void GatherReaderLendInf(); //某人借书统计
void GatherCardInf(); //卡号统计
void Sovle(); //该类地主功能
void ShowList(); //显示表头
void GetKey(); //获得输入
};
#endif
/*! @file
/********************************************************************************
模块名 : CRecord 类声明文件
文件名 : record.h
相关文件 : record.cpp
文件实现功能 : CRecord类中函数及数据的声明
作者 : 任震宇
版本 : 1.0
--------------------------------------------------------------------------------
备注 :
--------------------------------------------------------------------------------
修改记录 :
日 期 版本 修改人 修改内容
2011/6/10 1.0 任震宇 创建
*******************************************************************************/
#ifndef RECORD_H_INCLUDED
#define RECORD_H_INCLUDED
#include "style.h"
#include <string>
#include <time .h>
extern const std::string RECORDLINE[];
/*! @class
******************************************************************************
类名称 : CRecord
功能 : 借阅记录的相关内容及功能
--------------------------------------------------------------------------------
作者 : 任震宇
*****************************************************************************/
class CRecord
{
int m_nNum; //借阅者卡号
time_t m_dBorrowTime; //借出时间
time_t m_dDeadline; //截止日期
time_t m_dReturnTime; //归还时间
bool m_bReturn; //是否归还的标志
bool m_bReturnFine; //是否归还欠款
char m_sISBN[ ISBN_LENGTH ]; //所借图书的编号
public:
double GetFine(); //计算欠款并返回
void ShowRecord(); //显示借阅记录
static void ShowLine(); //显示表头
bool SetRecord(); //添加借阅记录
bool ReturnBook(); //归还图书记录
char*GetISBN(); //返回所借图书编号
bool IsReturn(); //返回是否归还图书
void Copy(CRecord); //有选择的拷贝记录
int GetNum(); //返回借阅者的卡号
time_t GetBorrowTime(); //返回借阅时间
time_t GetDeadline(); //返回截止日期
};
#endif
/*! @file
/********************************************************************************
模块名 : 格式控制及公用函数声明
文件名 : style.h
相关文件 : style.cpp
文件实现功能 : 输出控制及一些公用函数的声明
作者 : 任震宇
版本 : 1.0
--------------------------------------------------------------------------------
备注 :
--------------------------------------------------------------------------------
修改记录 :
日 期 版本 修改人 修改内容
2011/6/10 1.0 任震宇 创建
*******************************************************************************/
#ifndef STYLE_H_INCLUDED
#define STYLE_H_INCLUDED
//菜单格式控制声明的一些量
extern const int WID1;
extern const int WID2;
extern const int WID3;
extern const int WID4;
extern const int WID5;
extern const int WID6;
extern const int LENGTH0;
extern const int LENGTH1_1;
extern const int LENGTH1_2;
extern const int LENGTH3;
extern const int CARD_NUM_START;
const int PATH_LENGTH = 40; //保存路径的最大长度
const int NAME_LENGTH = 40; //名字最大长度
const int PASSWORD_LENGTH = 40; //密码最大长度
const int ISBN_LENGTH = 30; //图书编号的最大长度
extern char *BOOKINFPATH; //图书信息保存的路径
extern char *LENDPATH; //所有信息保存的目录
extern char *LENDRECORD; //借阅记录保存的路径
extern char *USERINF; //读者信息保存的路径
extern char *ADMININF; //管理员信息保存的路径
extern char *PROGRAMDATA; //程序配置文件保存的路径
void MyPut(const char ch,const int length); //讲字符ch输出length次
void ShowError(); //显示错误信息
void PutLine(); //输出一行**
void ShowChoice(); //显示选择
void ShowHeader(); //显示表头
void GetPassword(char *); //获取用户输入的密码
#endif
/*! @file
/********************************************************************************
模块名 : CAdmin 类定义文件
文件名 : administrator.cpp
相关文件 : administrator.h
person.h
AdminManager.h
文件实现功能 : CAdmin类中函数及数据的定义
作者 : 任震宇
版本 : 1.0
--------------------------------------------------------------------------------
备注 : 基类为CPerson类
--------------------------------------------------------------------------------
修改记录 :
日 期 版本 修改人 修改内容
2011/6/10 1.0 任震宇 创建
*******************************************************************************/
#include <iostream>
#include <iomanip>
#include "style.h"
#include "administrator.h"
#include "BookManager.h"
#include "LendManager.h"
#include "ReaderManager.h"
#include "AdminManager.h"
using namespace std;
const string ADMINLIST[]={
"欢迎 ",
"* 1 图书管理 *",
"* 2 借阅管理 *",
"* 3 读者管理 *",
"* 4 馆员管理 *",
"请输入管理员名称:",
"添加成功!",
};
/*! @function
******************************************************************************
<pre>
函数名 : Solve()
功能 : 算是这个类地一个main函数,对各种功能的调用
--------------------------------------------------------------------------------
作者 : 任震宇
</pre>
*****************************************************************************/
void CAdmin::Solve()
{
do
{
ShowList();
GetKey();
CBookManager bookMana;
CLendManage lendMana;
CReaderManage readMana;
CAdminManage adminMana;
switch( m_chKey )
{
case '1':bookMana.Solve();break;
case '2':lendMana.Solve();break;
case '3':readMana.Sovle();break;
case '4':adminMana.Solve();break;
case 'B':break;
case 'E':exit(0);
default:ShowError();
}
}while( m_chKey != 'B' );
}
/*! @function
******************************************************************************
<pre>
函数名 : Login()
功能 : 管理员登录验证函数
参数 :
[IN] username : 传入要验证的用户名
[IN] password : 传入要验证的密码
返回值 : 用户名和密码是否匹配
--------------------------------------------------------------------------------
作者 : 任震宇
</pre>
*****************************************************************************/
bool CAdmin::Login(char *username,char *password)
{
fstream file(ADMININF,ios::in);
if(!file)
{
cout < < "当前用户个数为0" << endl;
return false;
}
bool IsExist = false;
while(file.read((char*)this,sizeof(CAdmin)))
{
if( m_chTag == '#' && !strcmp( m_sUserName, username ) )
{
IsExist = true;
if( !strcmp( m_sPassword, password ))
{
cout << "登录成功!" << endl;
file.close();
system("pause");
return true;
}
}
}
file.close();
if( IsExist )
{
cout << "密码输入错误,请重试!" << endl;
}
else
{
cout << "用户名不存在!" << endl;
}
system("pause");
return false;
}
/*! @function
******************************************************************************
<PRE>
函数名 : ShowList()
功能 : 显示菜单以供用户选择
--------------------------------------------------------------------------------
作者 : 任震宇
</iomanip></iostream></pre>
*****************************************************************************/
void CAdmin::ShowList()
{
ShowHeader();
cout < < setw( WID5 ) << ADMINLIST[0] << m_sUserName << endl;
PutLine();
int i;
for(i = 0 ; i < 4 ; i++ )
{
cout << setw( WID2 ) << ADMINLIST[ i+1 ] << endl;
}
ShowChoice();
}
/*! @function
******************************************************************************
<PRE>
函数名 : Find()
功能 : 查询管理员功能
参数 :
[IN] IsErase : 是否删除的标记,真则删除
返回值 : 是否查找到此管理员
--------------------------------------------------------------------------------
作者 : 任震宇
</iomanip></iostream></pre>
*****************************************************************************/
bool CAdmin::Find(bool IsErase)
{
fstream file(ADMININF,ios::in | ios::out);
cout < < setw( WID3 ) << ADMINLIST[ 5 ];
char name[ NAME_LENGTH ];
cin >> name;
while( file.read( (char*)this, sizeof(CAdmin) ) )
{
if( m_chTag == '#' && strcmp( m_sUserName, name ) == 0)
{
if(IsErase)
{
file.seekp(-sizeof(CAdmin)+4,ios::cur);
file.put('*');
}
file.close();
return true;
}
}
cout < < "未找到此管理员!" << endl;
system("pause");
file.close();
return false;
}
/*! @function
******************************************************************************
<PRE>
函数名 : NewAdmin()
功能 : 添加管理员功能
--------------------------------------------------------------------------------
作者 : 任震宇
*****************************************************************************/
void CAdmin::NewAdmin()
{
cout < < setw( WID3 ) << ADMINLIST[ 5 ];
cin >> m_sUserName;
NewPassword();
cout < < setw( WID3 ) << ADMINLIST[ 6 ] << endl;
m_chTag = '#';
system("pause");
}
void CAdmin::Display()
{
if(m_chTag == '#' )
cout << m_sUserName << endl;
}
void CAdmin::Modify()
{
cout << setw( WID3 ) << "新用户名:";
cin >> m_sUserName;
}
void CAdmin::WriteToFile()
{
fstream file(ADMININF,ios::out|ios::app);
file.write((char*)this,sizeof(CAdmin));
file.close();
}
/*! @file
/********************************************************************************
模块名 : CAdminManage 类定义文件
文件名 : AdminManager.cpp
相关文件 : AdminManager.h
administrator.h
文件实现功能 : CAdminManage类中函数及数据的定义
作者 : 任震宇
版本 : 1.0
--------------------------------------------------------------------------------
备注 :
--------------------------------------------------------------------------------
修改记录 :
日 期 版本 修改人 修改内容
2011/6/10 1.0 任震宇 创建
*******************************************************************************/
#include <iostream>
#include <fstream>
#include <iomanip>
#include "AdminManager.h"
#include "administrator.h"
#include "style.h"
using namespace std;
const string CAdminManage::LIST[]={
"************馆员管理**********",
"* 1 增加管理员 *",
"* 2 修改管理员 *",
"* 3 删除管理员 *",
"* 4 管员统计 *",
};
void CAdminManage::Solve()
{
do
{
ShowList();
GetKey();
switch(m_chKey)
{
case '1':
AddAdmin();
break;
case '2':
ModifyAdmin();
break;
case '3':
DeleteAdmin();
break;
case '4':
GatherAdminInf();
break;
case 'B':
break;
case 'E':
exit(0);
default:
ShowError();
}
}while( m_chKey != 'B' );
}
void CAdminManage::AddAdmin()
{
CAdmin admin;
admin.NewAdmin();
admin.WriteToFile();
}
void CAdminManage::ModifyAdmin()
{
CAdmin admin;
admin.Find(true);
admin.Modify();
admin.WriteToFile();
cout < < "修改完毕!" << endl;
system("pause");
}
void CAdminManage::DeleteAdmin()
{
CAdmin admin;
admin.Find(true);
cout << "成功删除!" << endl;
system("pause");
}
void CAdminManage::GatherAdminInf()
{
CAdmin admin;
fstream file(ADMININF,ios::in);
while(file.read((char*)&admin,sizeof(admin)))
{
admin.Display();
}
file.close();
system("pause");
}
void CAdminManage::GetKey()
{
cin >> m_chKey;
cin.clear();
}
void CAdminManage::ShowList()
{
ShowHeader();
for(int i = 0; i < 5; i++)
{
cout << setw( WID2 ) << LIST[ i ] << endl;
}
ShowChoice();
}
/*! @file
/********************************************************************************
模块名 : CBookManager 类定义文件
文件名 : BookManager.cpp
相关文件 : BookManager.h
BOOKS.H
文件实现功能 : CBookManager类中函数及数据的定义
作者 : 任震宇
版本 : 1.0
--------------------------------------------------------------------------------
备注 :
--------------------------------------------------------------------------------
修改记录 :
日 期 版本 修改人 修改内容
2011/6/10 1.0 任震宇 创建
*******************************************************************************/
#include <iostream>
#include <iomanip>
#include "BookManager.h"
#include "BOOKS.H"
#include "style.h"
#include "finalMana.h"
using namespace std;
const string CBookManager::LIST[] = {
"图书管理系统",
"************图书管理**********",
"* 1 增加图书 *",
"* 2 修改图书 *",
"* 3 删除图书 *",
"* 4 统计图书 *",
"* B 返回 *",
"* E 退出 *",
"请输入你的选择:",
"* 0 按照图书名 *",
"* 1 按照ISBN号码 *",
"请输入图书名 :",
"请输入ISBN号码:",
"图书名",
"ISBN号码",
"库存数量",
"借出数量",
"总数",
"************修改图书**********",
"************删除图书**********",
};
void CBookManager::Solve()
{
do
{
ShowList1();
GetKey();
switch( m_chKey )
{
case '1':
InsertNewBook();
break;
case '2':
ChangeBookInf();
break;
case '3':
DeleteBook();
break;
case '4':
GatherStatistics();
break;
case 'B':
break;
case 'E':
exit(0);
default :
ShowError();
}
}while( m_chKey != 'B' );
}
//添加图书
void CBookManager::InsertNewBook()
{
CBook NewBook;
NewBook.GetInf();
NewBook.AppToFile(BOOKINFPATH);
}
bool CBookManager::FindBook(char * ToFind, CBook &Book, char flag, bool IsErase)
{
fstream file(BOOKINFPATH,ios::in | ios::out);
bool IsFind = false;
CBook book;
while( !IsFind && book.ReadFromFile(file) )
{
if( book.Equal(ToFind, flag) )
{
IsFind = true;
Book = book;
file.seekp( -sizeof(CBook), ios::cur);
if( IsErase ) file.put('*');
break;
}
}
file.close();
return IsFind;
}
//查找图书
bool CBookManager::FindBook(CBook &Book,bool IsErase)
{
ShowList2();
GetKey();
char ToFind[ ISBN_LENGTH ];
int i = 11;
switch (m_chKey)
{
case '1':
i++;
case '0':
break;
case 'B':
m_chKey = '0';
return false;
case 'E':
exit(0);
default:
ShowError();
return false;
}
cout < < setw( WID3 ) << LIST[ i ];
cin >> ToFind;
bool IsFind = FindBook(ToFind,Book,m_chKey,IsErase);
if(!IsFind)
{
cout < < "未找到此图书" << endl;
system("pause");
}
return IsFind;
}
//修改图书
void CBookManager::ChangeBookInf()
{
CBook book;
cout << setw( WID2 ) << LIST[ 18 ] << endl;
if( !FindBook(book,true) ) return ;
book.ADisplay();
book.ModifyInf();
book.AppToFile(BOOKINFPATH);
}
//删除图书
void CBookManager::DeleteBook()
{
CBook book;
cout << setw( WID2 ) << LIST[ 19 ] << endl;
if(FindBook(book,true))
{
cout << "删除成功!" << endl;
system("pause");
}
}
//统计图书
void CBookManager::GatherStatistics()
{
fstream file(BOOKINFPATH,ios::in | ios:: binary);
CBook book;
if( !file )
{
cout << "0书目" << endl;
system("pause");
return;
}
CBook::ShowLine();
int total = 0;
while( !file.eof() && book.ReadFromFile( file ) )
{
total += book.Display();
}
cout << endl;
cout << " 共 " << total << " 种图书" << endl;
file.close();
system("pause");
}
void CBookManager::ShowList1()
{
ShowHeader();
for(int i = 0 ; i < 5 ; i++ )
{
cout << setw( WID2 ) << LIST[ i+1 ] << endl;
}
ShowChoice();
}
void CBookManager::ShowList2()
{
cout << setw( WID2 ) << LIST[ 9 ] << endl;
cout << setw( WID2 ) << LIST[ 10 ] << endl;
ShowChoice();
}
void CBookManager::GetKey()
{
cin >> m_chKey;
cin.clear();
}
/*! @file
/********************************************************************************
模块名 : CBook 类定义文件
文件名 : BOOKS.CPP
相关文件 : BOOKS.H
BookManager.h
文件实现功能 : CBook类中函数及数据的定义
作者 : 任震宇
版本 : 1.0
--------------------------------------------------------------------------------
备注 :
--------------------------------------------------------------------------------
修改记录 :
日 期 版本 修改人 修改内容
2011/6/10 1.0 任震宇 创建
*******************************************************************************/
#include <iostream>
#include <iomanip>
#include <fstream>
#include "style.h"
#include "BOOKS.H"
using namespace std;
const string BOOKLIST[] = {
"请输入图书名 :",
"请输入ISBN号码:",
"请输入数量 :",
"输入错误,数的总数不能为负数!",
"请重新输入 :",
"************修改图书**********",
"* 0 修改图书名 *",
"* 1 修改ISBN号码 *",
"* 2 修改库存数量 *",
"图书名",
"ISBN号码",
"库存数量",
"借出数量",
"总数",
};
void CBook::GetInf()
{
m_chTag = '#';
cout < < setw( WID3 ) << BOOKLIST[ 0 ]; cin >> m_sName;
cout < < setw( WID3 ) << BOOKLIST[ 1 ]; cin >> m_sISBN;
cout < < setw( WID3 ) << BOOKLIST[ 2 ]; cin >> m_nTotal;
m_nLeft = m_nTotal;
m_nLend = 0;
}
void CBook::AppToFile(char *FileName)
{
fstream file(FileName , ios::app | ios::out | ios::binary);
file.write((char*)this,sizeof(CBook));
file.close();
}
int CBook::Display()
{
if( m_chTag == '#' )
{
cout < < setw( WID6 ) << m_sName;
cout << setw( WID6 ) << m_sISBN;
cout << setw( WID6 ) << m_nLeft;
cout << setw( WID6 ) << m_nLend;
cout << setw( WID6 ) << m_nTotal;
cout << endl;
return 1;
}
return 0;
}
void CBook::ADisplay()
{
ShowLine();
Display();
}
void CBook::ModifyInf()
{
int i;
for( i = 5; i < 9 ; i++ )
{
cout << setw( WID2 ) << BOOKLIST[ i ] << endl;
}
ShowChoice();
char ch;
cin >> ch;
switch( ch )
{
case '0':
cout < < setw( WID3 ) << BOOKLIST[ 0 ];
cin >> m_sName;
break;
case '1':
cout < < setw( WID3 ) << BOOKLIST[ 1 ];
cin >> m_sISBN;
break;
case '2':
cout < < setw( WID3 ) << BOOKLIST[ 2 ];
m_nTotal -= m_nLeft;
cin >> m_nLeft;
m_nTotal += m_nLeft;
case 'B':
break;
case 'E':
AppToFile(BOOKINFPATH);
exit(0);
default:
ShowError();
}
cin.clear();
}
bool CBook::ReadFromFile(fstream &file)
{
if( file.read((char*)this,sizeof(CBook)) ) return true;
return false;
}
bool CBook::Equal(char* ToFind, char flag)
{
if( m_chTag == '*' ) return false;
if( flag == '0' && strcmp(ToFind , m_sName) == 0 ) return true;
if( flag == '1' && strcmp(ToFind , m_sISBN) == 0 ) return true;
return false;
}
void CBook::ShowLine()
{
int i = 9;
for( ; i < 14 ; i ++ )
cout << setw( WID6 ) << BOOKLIST[ i ];
cout << endl;
}
char*CBook::GetISBN()
{
return m_sISBN;
}
void CBook::Lend(CRecord record)
{
fstream file(LENDRECORD,ios::out | ios::app );
file.write((char*)&record,sizeof(record));
file.close();
m_nLeft--;
m_nLend++;
AppToFile(BOOKINFPATH);
}
bool CBook::Return(CRecord record)
{
fstream file(LENDRECORD,ios::in | ios::out);
CRecord rec;
while(file.read((char*)&rec,sizeof(rec)))
{
if( rec.GetNum() == record.GetNum() && !strcmp( rec.GetISBN(), record.GetISBN()) && !rec.IsReturn() )
{
file.seekp(-sizeof(rec),ios::cur);
rec.Copy(record);
file.write((char*)&rec,sizeof(rec));
file.close();
m_nLeft++;
m_nLend--;
AppToFile(BOOKINFPATH);
return true;
}
}
file.close();
cout << "未找到此书~~" << endl;
return false;
}
char *CBook::GetName()
{
return m_sName;
}
/*! @file
/********************************************************************************
模块名 : CFinalMana 类定义文件
文件名 : finalMana.cpp
相关文件 : finalMana.h
文件实现功能 : CFinalMana类中函数及数据的定义
作者 : 任震宇
版本 : 1.0
--------------------------------------------------------------------------------
备注 :
--------------------------------------------------------------------------------
修改记录 :
日 期 版本 修改人 修改内容
2011/6/10 1.0 任震宇 创建
*******************************************************************************/
#include <iostream>
#include <iomanip>
#include <stdlib .h>
#include <conio .h>
#include "style.h"
#include "finalMana.h"
#include "reader.h"
#include "administrator.h"
#include "AdminManager.h"
using namespace std;
const string CFinalMana::LIST[] = {
"* 0 读者登录 *",
"* 1 管理员登录 *",
"* 2 系统重置 *",
" 登录",
"用户名: ",
"密 码: ",
"重置密码(初始密码为1111):",
"************系统重置**********",
"* 1 清空读者卡 *",
"* 2 清空借书记录 *",
"* 3 清空管理员 *",
"* 4 清空书 籍 *",
"* 5 清空所 有 *",
"* 6 修改重置密码 *",
};
void CFinalMana::Solve()
{
CPerson *p;
CReader reader;
CAdmin admin;
do
{
ShowList();
GetKey();
switch( m_chKey )
{
case '0' :
p=&reader;
break;
case '1' :
p=&admin;
break;
case '2':
Reset();
continue;
case 'B':
exit(0);
case 'E' :
exit(0);
default :
ShowError();
continue;
}
ShowLogin();
if( p->Login(m_sUserName, m_sPassword) )
{
p->Solve();
}
}while( m_chKey != 'B' );
}
//显示菜单
void CFinalMana::ShowList()
{
ShowHeader();
PutLine();
int i;
for(i=0;i<3;i++)
{
cout < < setw( WID2 ) << LIST[i] << endl;
}
ShowChoice();
}
void CFinalMana::ShowList2()
{
ShowHeader();
int i;
for( i = 7; i < 14 ; i++ )
{
cout << setw( WID2 ) << LIST[ i ] << endl;
}
ShowChoice();
}
//系统重置
void CFinalMana::Reset()
{
cout << setw( WID3 ) << LIST[ 6 ];
char password[ PASSWORD_LENGTH ];
char pass[ PASSWORD_LENGTH ] = "1111";
GetPassword(password);
fstream file( PROGRAMDATA, ios::in );
if(!file.fail())
{
file.seekp(sizeof(int));
file.read(pass,sizeof(pass));
file.close();
}else
{
fstream file1( PROGRAMDATA, ios::out);
int b=1000;
file1.write((char*)&b,sizeof(int));
file1.write(pass,sizeof(pass));
file1.close();
}
if( strcmp( password, pass ) )
{
cout << "密码错误!" << endl;
system("pause");
return;
}
do
{
ShowList2();
GetKey();
switch( m_chKey )
{
case '1':
if( !ShowAsk("读者卡") )break;
ClearReaderCard();
ClearReaderRecord();
break;
case '2':
if( !ShowAsk("借书记录") )break;
ClearReaderRecord();
ClearRecord();
break;
case '3':
if( !ShowAsk("管理员") )break;
ClearAdmin();
break;
case '4':
if( !ShowAsk("书籍") )break;
ClearBook();
break;
case '5':
if( !ShowAsk("所有") )break;
ClearReaderCard();
ClearReaderRecord();
ClearRecord();
ClearBook();
ClearAdmin();
break;
case '6':
ResetPassword();
break;
case 'B':
m_chKey = 'A';
return;
case 'E':
exit(0);
default:
ShowError();
}
}while( m_chKey != 'B' );
}
void CFinalMana::ResetPassword()
{
char pass[ PASSWORD_LENGTH ],pass2[ PASSWORD_LENGTH ];
cout << setw( WID3 ) << "请输入密码:";
GetPassword(pass);
cout << setw( WID3 ) << "请确认密码:";
GetPassword(pass2);
if( strcmp( pass, pass2 ) )
{
cout << "两次密码输入不一致!";
return;
}
fstream file( PROGRAMDATA, ios::out|ios::in );
file.seekp(sizeof(int));
file.write( pass,sizeof(pass));
file.close();
}
void CFinalMana::GetKey()
{
cin >> m_chKey;
cin.clear();
}
void CFinalMana::ShowLogin()
{
ShowHeader();
cout < < setw( WID4 ) << LIST[ 3 ] << endl << endl;
cout << setw( WID4 ) << LIST[ 4 ]; cin >> m_sUserName;
cout < < setw( WID4 ) << LIST[ 5 ];
GetPassword( m_sPassword );
}
void CFinalMana::ClearReaderCard()
{
char path[ PATH_LENGTH ] = "del ";
strcat( path, USERINF );
system(path);
fstream file(PROGRAMDATA,ios::out|ios::in);
int b=1000;
file.write((char*)&b,sizeof(int));
file.close();
}
void CFinalMana::ClearReaderRecord()
{
char path[ PATH_LENGTH ] = "del ";
strcat( path, LENDPATH );
strcat( path, "file*.dat" );
system( path );
}
void CFinalMana::ClearAdmin()
{
char path[ PATH_LENGTH ] = "del ";
strcat( path, ADMININF );
system(path);
cout << setw( WID3 ) << "请建立一个管理员:" << endl;
CAdminManage adminMana;
adminMana.AddAdmin();
}
void CFinalMana::ClearRecord()
{
char path[ PATH_LENGTH ] = "del ";
strcat( path, LENDRECORD );
system( path );
}
void CFinalMana::ClearBook()
{
char path[ PATH_LENGTH ] ="del ";
strcat( path, BOOKINFPATH );
system( path );
}
bool CFinalMana::ShowAsk(char *data)
{
char path[ PATH_LENGTH ] = "您确定要清空";
strcat(path, data);
strcat(path,"吗?Y/N :");
cout << setw( WID3 ) << path;
GetKey();
while( m_chKey != 'Y' && m_chKey != 'N' )
{
ShowError();
GetKey();
}
if( m_chKey == 'N' )return false;
return true;
}
/*! @file
/********************************************************************************
模块名 : CLendManage 类定义文件
文件名 : LendManager.cpp
相关文件 : LendManager.h
文件实现功能 : CLendManage类中函数及数据的定义
作者 : 任震宇
版本 : 1.0
--------------------------------------------------------------------------------
备注 :
--------------------------------------------------------------------------------
修改记录 :
日 期 版本 修改人 修改内容
2011/6/10 1.0 任震宇 创建
*******************************************************************************/
#include <time .h>
#include <iostream>
#include <iomanip>
#include "LendManager.h"
#include "style.h"
#include "BookManager.h"
#include "BOOKS.H"
#include "reader.h"
using namespace std;
const string CLendManage::LIST[] = {
"************借阅管理**********",
"* 1 查找图书 *",
"* 2 借阅图书 *",
"* 3 归还图书 *",
"* 4 借阅图书统计 *",
"* 5 到期图书统计 *",
"* 6 罚款统计 *",
"* 0 按照图书名 *",
"* 1 按照ISBN号码 *",
"请输入图书名 :",
"请输入ISBN号码:",
"图书名",
"ISBN号码",
"库存数量",
"借出数量",
"总数",
"************归还图书**********",
"************借阅图书**********",
"************查找图书**********",
};
void CLendManage::Solve()
{
do
{
ShowList1();
GetKey();
CBook book;
switch( m_chKey )
{
case '1':
cout < < setw( WID2 ) << LIST[18] << endl;
FindBook(book);
break;
case '2':
LendBook();
break;
case '3':
ReturnBook();
break;
case '4':
GatherLendStatistics();
break;
case '5':
ExpireBook();
break;
case '6':
GatherFineInf();
break;
case 'B':
break;
case 'E':
exit(0);
default:
ShowError();
}
}while( m_chKey != 'B' );
}
//查找图书
bool CLendManage::FindBook(CBook &book)
{
CBookManager bookMana;
if( bookMana.FindBook(book) )
{
book.ADisplay();
system("pause");
return true;
}
return false;
}
//借阅图书
void CLendManage::LendBook()
{
CRecord record;
if(record.SetRecord())
{
cout << "借阅成功!" << endl;
system("pause");
}
}
//归还图书
void CLendManage::ReturnBook()
{
CRecord record;
if(record.ReturnBook())
{
cout << "归还成功!" << endl;
system("pause");
}
}
//借阅图书统计
void CLendManage::GatherLendStatistics()
{
CRecord record;
tm date;
cout << "请输入要查询的日期:" << endl;
cout << setw( WID3 ) << "年:";
cin >> date.tm_year;
date.tm_year -= 1900;
cout < < setw( WID3 ) << "月:";
cin >> date.tm_mon;
date.tm_mon--;
cout < < setw( WID3 ) << "日:";
cin >> date.tm_mday;
fstream file(LENDRECORD,ios::in);
if(!file)
{
cout < < "0条记录" << endl;
return;
}
CRecord::ShowLine();
int totRecord = 0;
while(file.read((char *)&record,sizeof(CRecord)))
{
time_t ti = record.GetBorrowTime();
tm tp = *localtime( &ti );
if(tp.tm_year == date.tm_year && tp.tm_mon == date.tm_mon && tp.tm_mday == date.tm_mday)
{
record.ShowRecord();
totRecord++;
}
}
cout << "共" << totRecord << "条记录" << endl;
system("pause");
}
//到期图书统计
void CLendManage::ExpireBook()
{
CRecord record;
fstream file(LENDRECORD,ios::in);
record.ShowLine();
while(file.read((char*)&record,sizeof(record)))
{
if(!record.IsReturn() && record.GetDeadline() < time(NULL))
{
record.ShowRecord();
}
}
file.close();
system("pause");
}
//罚款统计
void CLendManage::GatherFineInf()
{
CRecord record;
fstream file(LENDRECORD,ios::in);
record.ShowLine();
while(file.read((char*)&record,sizeof(record)))
{
if(record.GetFine()>0)
{
record.ShowRecord();
}
}
file.close();
system("pause");
}
void CLendManage::ShowList1()
{
ShowHeader();
for( int i = 0 ; i < 7 ; i++ )
{
cout << setw( WID2 ) << LIST[i] << endl;
}
ShowChoice();
}
void CLendManage::GetKey()
{
cin >> m_chKey;
cin.clear();
}
</iomanip></iostream></time></pre>
<pre lang="CPP" line="1" colla="-">
#include <iostream>
#include <fstream>
#include "finalMana.h"
using namespace std;
int main()
{
CFinalMana finalMana;
finalMana.Solve();
return true;
}
/*! @file
/********************************************************************************
模块名 : CReader 类定义文件
文件名 : reader.cpp
相关文件 : Person.h
reader.h
文件实现功能 : CReader类中函数及数据的定义
作者 : 任震宇
版本 : 1.0
--------------------------------------------------------------------------------
备注 :
--------------------------------------------------------------------------------
修改记录 :
日 期 版本 修改人 修改内容
2011/6/10 1.0 任震宇 创建
*******************************************************************************/
#include <iostream>
#include "reader.h"
#include "BOOKS.H"
#include "record.h"
#include "BookManager.h"
#include <string .h>
using namespace std;
const string READERLIST[]={
"请输入读者名:",
"请输入密码 :",
"请再次输入以确认您的密码:",
"两次输入不一致,请重新输入!",
"您的卡号是:",
"请牢记您的卡号!",
"************读者登录**********",
"* 1 查找图书 *",
"* 2 借阅查询 *",
"* 3 修改信息 *",
"************查找图书**********",
"卡号",
"用户名",
"************修改信息**********",
"* 1 修改用户名 *",
"* 2 修改密码 *",
};
bool CReader::Login(char* username,char* password)
{
fstream file(USERINF,ios::in);
if(!file)
{
cout < < "当前用户个数为0" << endl;
return false;
}
bool IsExist = false;
while(file.read((char*)this,sizeof(CReader)))
{
if( m_chTag == '#' && !strcmp( m_sUserName, username ) )
{
IsExist = true;
if( !strcmp( m_sPassword, password ))
{
cout << "登录成功!" << endl;
file.close();
system("pause");
return true;
}
}
}
file.close();
if( IsExist )
{
cout << "密码输入错误,请重试!" << endl;
}
else
{
cout << "用户名不存在!" << endl;
}
system("pause");
return false;
}
void CReader::Solve()
{
do
{
ShowList();
GetKey();
CBookManager bookMana;
CBook book;
switch(m_chKey)
{
case '1':
cout << setw( WID2 ) << READERLIST[ 10 ] << endl;
bookMana.FindBook(book);
book.Display();
system("pause");
break;
case '2':
GetBorrowInf();
system("pause");
break;
case '3':
Find(m_nCardNum,true);
Modify();
break;
case 'B':
break;
case 'E':
exit(0);
default:
ShowError();
}
}while( m_chKey != 'B' );
}
void CReader::ShowList()
{
ShowHeader();
for(int i = 6 ; i < 10 ; i++ )
{
cout << setw( WID2 ) << READERLIST[ i ] << endl;
}
ShowChoice();
}
bool CReader::Find(int num,bool IsErase)
{
fstream file(USERINF,ios::in | ios::out);
while(file.read((char*)this,sizeof(CReader)))
{
if( m_chTag == '#' && m_nCardNum == num)
{
if(IsErase)
{
file.seekp(-sizeof(CReader)+4,ios::cur);
file.put('*');
}
file.close();
return true;
}
}
file.close();
return false;
}
int CReader::Display()
{
if(m_chTag == '#')
{
cout << setw( WID6 ) << m_nCardNum;
cout << setw( WID6 ) << m_sUserName;
cout << endl;
return 1;
}
return 0;
}
void CReader::BorrowBook(CRecord record)
{
char path[ PATH_LENGTH ];
sprintf(path, "%sfile%d.dat",LENDPATH,m_nCardNum);
fstream file(path,ios::out | ios::app);
file.write((char*)&record,sizeof(record));
file.close();
}
void CReader::NewReader(int cardNum)
{
m_chTag = '#';
cout << setw( WID3 ) << READERLIST[ 0 ];
cin >> m_sUserName;
NewPassword();
cout < < setw( WID3 ) << READERLIST[ 4 ] << cardNum << endl;
cout << setw( WID3 ) << READERLIST[ 5 ] << endl;
m_nCardNum = cardNum;
AppToFile();
system("pause");
}
void CReader::AppToFile()
{
fstream file(USERINF,ios::app | ios::out);
file.write((char*)this,sizeof(CReader) );
file.close();
}
void CReader::GetBorrowInf()
{
char path[ PATH_LENGTH ];
sprintf(path, "%sfile%d.dat",LENDPATH,m_nCardNum);
fstream file(path,ios::in);
CRecord record;
CRecord::ShowLine();
while(file.read((char*)&record,sizeof(record)))
{
record.ShowRecord();
}
file.close();
}
void CReader::ShowList2()
{
for(int i= 13;i<16;i++)
{
cout << setw( WID2 ) << READERLIST[ i ] << endl;
}
ShowChoice();
}
void CReader::Modify()
{
ShowList2();
GetKey();
switch(m_chKey)
{
case '1':
cout << setw( WID3 ) << READERLIST[ 0 ];
cin >> m_sUserName;
break;
case '2':
NewPassword();
case 'B':
break;
case 'E':
AppToFile();
exit(0);
default:
ShowError();
}
AppToFile();
}
bool CReader::ReturnBook(CRecord record)
{
char path[ PATH_LENGTH ];
sprintf(path, "%sfile%d.dat",LENDPATH,m_nCardNum);
fstream file(path, ios::in | ios::out);
CRecord rec;
while(file.read((char*)&rec,sizeof(rec)))
{
if( !strcmp( rec.GetISBN(), record.GetISBN()) && !rec.IsReturn() )
{
file.seekp(-sizeof(rec),ios::cur);
rec.Copy(record);
file.write((char*)&rec,sizeof(rec));
file.close();
return true;
}
}
file.close();
cout < < "未找到此书~~" << endl;
return false;
}
void CReader::ShowHead()
{
cout << setw( WID6 ) << READERLIST[ 11 ];
cout << setw( WID6 ) << READERLIST[ 12 ];
cout << endl;
}
/*! @file
/********************************************************************************
模块名 : CReaderManage 类定义文件
文件名 : ReaderManager.cpp
相关文件 : ReaderManager.h
reader.h
文件实现功能 : CReaderManage类中函数及数据的定义
作者 : 任震宇
版本 : 1.0
--------------------------------------------------------------------------------
备注 :
--------------------------------------------------------------------------------
修改记录 :
日 期 版本 修改人 修改内容
2011/6/10 1.0 任震宇 创建
*******************************************************************************/
#include <iostream>
#include "ReaderManager.h"
#include <string>
#include <iomanip>
#include "style.h"
#include "reader.h"
using namespace std;
const string CReaderManage::LIST[]={
"************读者管理**********",
"* 1 申请读者卡 *",
"* 2 删除读者卡 *",
"* 3 修改读者卡 *",
"* 4 借书统计 *",
"* 5 卡号统计 *",
"请输入要删除的读者卡号:",
"请输入要查找的读者卡号:",
"请输入要修改的读者卡号:",
"删除成功!",
"未找到此卡号!",
};
int CReaderManage::s_nCardNum = CARD_NUM_START;
void CReaderManage::ShowList()
{
ShowHeader();
for( int i = 0 ; i < 6 ; i++ )
{
cout << setw( WID2 ) << LIST[i] << endl;
}
ShowChoice();
}
void CReaderManage::Sovle()
{
do
{
ShowList();
GetKey();
switch( m_chKey )
{
case '1':
ApplyReaderCard();
break;
case '2':
DeleteReaderCard();
break;
case '3':
ModifyReaderCard();
break;
case '4':
GatherReaderLendInf();
break;
case '5':
GatherCardInf();
break;
case 'B':
break;
case 'E':
exit(0);
default:
ShowError();
}
}while( m_chKey != 'B' );
}
//申请读者卡
void CReaderManage::ApplyReaderCard()
{
CReader reader;
fstream file(PROGRAMDATA,ios::in|ios::out);
file.read((char*)&s_nCardNum,sizeof(int));
reader.NewReader(s_nCardNum);
s_nCardNum++;
file.seekp(-sizeof(int),ios::cur);
file.write((char*)&s_nCardNum,sizeof(int));
file.close();
}
//删除读者卡
void CReaderManage::DeleteReaderCard()
{
cout << LIST[ 6 ];
int num;
cin >> num;
CReader reader;
if(reader.Find(num,true))
{
cout < < LIST[ 9 ] << endl;
}else
{
cout << LIST[ 10 ] << endl;
}
system("pause");
}
//修改读者卡
void CReaderManage::ModifyReaderCard()
{
cout << LIST[ 8 ];
int num;
cin >> num;
CReader reader;
if(reader.Find(num,true))
{
reader.Modify();
}else
{
cout < < LIST[ 8 ] << endl;
system("pause");
}
}
//某人借书统计
void CReaderManage::GatherReaderLendInf()
{
cout << LIST[ 7 ];
int num;
cin >> num;
CReader reader;
if(reader.Find(num))
{
reader.GetBorrowInf();
}else
{
cout < < LIST[ 10 ] << endl;
}
system("pause");
}
//卡号统计
void CReaderManage::GatherCardInf()
{
fstream file(USERINF,ios::in);
CReader reader;
reader.ShowHead();
int total = 0;
while(file.read((char*)&reader,sizeof(reader)))
{
total += reader.Display();
}
cout << endl;
cout << " 共 " << total << " 个读者" << endl;
system("pause");
}
void CReaderManage::GetKey()
{
cin >> m_chKey;
cin.clear();
}
/*! @file
/********************************************************************************
模块名 : CRecord 类定义文件
文件名 : record.cpp
相关文件 : record.h
文件实现功能 : CRecord类中函数及数据的定义
作者 : 任震宇
版本 : 1.0
--------------------------------------------------------------------------------
备注 :
--------------------------------------------------------------------------------
修改记录 :
日 期 版本 修改人 修改内容
2011/6/10 1.0 任震宇 创建
*******************************************************************************/
#include "record.h"
#include "reader.h"
#include "BookManager.h"
#include "BOOKS.H"
#include "style.h"
#include <iomanip>
#include <string .h>
#include <iomanip>
#include <time .h>
using namespace std;
const string RECORDLIST[]={
"书名",
"ISBN号码",
"借书人",
"借出日期",
"截止日期",
"归还日期",
"罚款",
"是否支付",
"未归还",
"未支付",
"已支付",
"************借阅图书**********",
"************归还图书**********",
};
double CRecord::GetFine()
{
int day;
time_t sec;
if( m_bReturn )
{
sec = m_dReturnTime;
}else
{
sec = time(NULL);
}
if( sec < = m_dDeadline ) return 0;
day = ( sec - m_dDeadline ) / ( 60 * 60 * 24 );
return day * 0.1;
}
void CRecord::ShowLine()
{
for( int i = 0 ; i < 8 ; i ++ )
{
cout << setw( WID6 ) << RECORDLIST[ i ];
}
cout << endl;
}
bool CRecord::SetRecord()
{
cout << setw( WID3 ) << "请输入读者卡号:";
cin >> m_nNum;
CReader reader;
if( !reader.Find(m_nNum) )return false;
reader.ShowHead();
reader.Display();
CBook book;
CBookManager bookMana;
m_bReturn = false;
m_bReturnFine = false;
cout < < setw( WID2 ) << RECORDLIST[11] << endl;
if( !bookMana.FindBook(book,true) ) return false;
book.ADisplay();
strcpy(m_sISBN,book.GetISBN());
m_dBorrowTime = time(NULL);
m_dDeadline = m_dBorrowTime + 60 * 60 * 24 * 30;
reader.BorrowBook(*this);
book.Lend(*this);
return true;
}
bool CRecord::ReturnBook()
{
cout << setw( WID3 ) << "请输入读者卡号:";
cin >> m_nNum;
CReader reader;
if( !reader.Find(m_nNum) )return false;
reader.ShowHead();
reader.Display();
CBook book;
CBookManager bookMana;
m_bReturn = true;
cout < < setw( WID2 ) << RECORDLIST[12] << endl;
if( !bookMana.FindBook(book,true) ) return false;
book.ADisplay();
strcpy(m_sISBN,book.GetISBN());
m_bReturn = true;
m_dReturnTime = time( NULL );
if(reader.ReturnBook(*this))
{
book.Return(*this);
return true;
}
return false;
}
void CRecord::Copy(CRecord b)
{
m_bReturn = b.m_bReturn;
m_bReturnFine = b.m_bReturnFine;
m_dReturnTime = b.m_dReturnTime;
}
int CRecord::GetNum()
{
return m_nNum;
}
char*CRecord::GetISBN()
{
return m_sISBN;
}
bool CRecord::IsReturn()
{
return m_bReturn;
}
void CRecord::ShowRecord()
{
CBookManager bookMana;
CBook book;
CReader reader;
bookMana.FindBook( m_sISBN, book);
reader.Find(m_nNum);
cout << setw( WID6 ) << book.GetName();
cout << setw( WID6 ) << book.GetISBN();
cout << setw( WID6 ) << reader.GetName();
char *ti = ctime(&m_dBorrowTime);
ti[strlen(ti)-1] = '\0';
cout << setw( WID6 ) << ti;
ti = ctime(&m_dDeadline);
ti[strlen(ti)-1] = '\0';
cout << setw( WID6 ) << ti;
if( m_bReturn )
{
char *ti = ctime(&m_dReturnTime);
ti[strlen(ti)-1] = '\0';
cout << setw( WID6 ) << ti;
}
else
{
cout << setw( WID6 ) << RECORDLIST[ 8 ];
}
cout << setw( WID6 ) << GetFine();
int i = 9;
if( m_bReturnFine ) i++;
cout << setw( WID6 ) << RECORDLIST[ i ];
cout << endl;
}
time_t CRecord::GetBorrowTime()
{
return m_dBorrowTime;
}
time_t CRecord::GetDeadline()
{
return m_dDeadline;
}
/*! @file
/********************************************************************************
模块名 : 格式控制及公用函数定义
文件名 : style.cpp
相关文件 : style.h
文件实现功能 : 输出控制及一些公用函数的定义
作者 : 任震宇
版本 : 1.0
--------------------------------------------------------------------------------
备注 :
--------------------------------------------------------------------------------
修改记录 :
日 期 版本 修改人 修改内容
2011/6/10 1.0 任震宇 创建
*******************************************************************************/
#include "style.h"
#include <iostream>
#include <iomanip>
#include <conio .h>
using namespace std;
const int WID1 = 30;
const int WID2 = 40;
const int WID3 = 20;
const int WID4 = 25;
const int WID5 = 50;
const int WID6 = 30;
const int LENGTH0 = 5;
const int LENGTH1_1 = 10;
const int LENGTH1_2 = 30;
const int LENGTH3 = 50;
const int CARD_NUM_START = 1000;
char *BOOKINFPATH = "DATA\\book.dat";
char *LENDPATH = "DATA\\";
char *LENDRECORD = "DATA\\lend.dat";
char *USERINF = "DATA\\userInf.dat";
char *ADMININF = "DATA\\adminInf.dat";
char *PROGRAMDATA = "DATA\\program.dat";
//将字符ch输出length次
void MyPut(const char ch,const int length)
{
cout < < setfill( ch ) << setw( length ) << ch << setfill(' ');
}
void ShowError()
{
cerr << "输入错误!请重新输入!" << endl;
system("pause");
}
void PutLine()
{
MyPut(' ', LENGTH1_1);
MyPut('*', LENGTH1_2);
cout << endl;
}
void ShowChoice()
{
cout << setw( WID2 ) << "* B 返回 *" << endl;
cout << setw( WID2 ) << "* E 退出 *" << endl;
PutLine();
cout << endl;
cout << setw( WID3 ) << "请输入你的选择:";
}
//显示表头
void ShowHeader()
{
system("cls");
MyPut('\n',LENGTH0 );
MyPut('#',LENGTH3);
cout << endl << endl;
cout << setw( WID1 ) << "图书管理系统" << endl;
cout << endl;
MyPut('#',LENGTH3);
cout << endl << endl;
}
void GetPassword(char *pass)
{
char password;
int i = 0;
while( (password = getch()) != '\r' )
{
pass[ i++ ] = password;
putchar('*');
}
pass[ i ] = '\0';
cout << endl;
}