📄 reader.cpp
字号:
#include "Reader.h"
#include<string>
#include<iomanip.h>
#include <fstream.h>
#include "UserDB.h"
#include "StackRoom.h"
#define max 100
int iMember_menu();
void iMemberID(char *p);
CReader::CReader() //初始化
{
iBorrowNum = 0;
iID = 0;
}
void CReader::SetInf( char phone[], char name[], char password[], bool sex )//赋值
{
strcpy(sPhone, phone);
strcpy(sName, name);
strcpy(sPassword, password);
bSex = sex;
}
int CReader::Checksname( char name[] ){ //检查帐号
//CUserDB user;
int exist=-1;
exist=Udb.CheckName(name);
if(exist==-1)
{cout<<"\t你不是会员,请先注册!!!"<<endl;return 0;
}
else
{cout<<"\t你是会员!!!"<<endl;return 1;}
}
int CReader::Match_password(char *pas,char name[])//const //检测密码
{
//CUserDB user;
int success=-1;
success=Udb.Checkpassword(pas,name);
if(success==-1 )
{ cout<<endl<<"\t密码错误,重新选择输入!!!"<<endl;return 0;}
else
{
cout<<endl<<"\t密码正确!!!"<<endl;
// user.Get_reader(success);
return success;
}
}
bool CReader::Borrow_book(CBook book){ //借书成功true,失败false
if(iBorrowNum == 10){
cout<<"借书已满,请先还书!!!";
return false;
}
else{
book.Lend();
BookOnHand[iBorrowNum] = book;
iBorrowNum++;
return true;
}
}
bool CReader::Reback_book(CBook book){ //还书
book.Retu();
iBorrowNum--;
return true;
}
int CReader::Login() //登录
{
char pass[20];
int i=0,s=0;
int m=0;
char name[20];
system("cls");
cout<<"\t输入你的用户名:";
cin>>name;
s=Checksname(name);
if(s)
{
while(i<=3)
{
++i;
// cout<<"input your password:";
iMemberID(pass);
m=Match_password(pass,name);
if(m)
{
return m;
break;
}
}
}
return -1;
}
bool CReader::Consult() //读者查询借阅情况
{
cout<<"\t你已借";
cout<<iBorrowNum<<"本书!!"<<endl;
cout<<"借了以下这些书:"<<endl;
cout<<"\n\t■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■\n";
cout<<setw(14)<< "ID" <<setw(10)<< "书名" << setw(14) << "作者"
<<setw(20)<< "出版社";
for ( int i=0; i<iBorrowNum; i++){
cout<<endl<<BookOnHand[i];
}
cout<<"\n\t■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■\n";
return true;
}
void CReader::Choice(int i) //读者选择功能 //未完成
{
CBook book;
CStackRoom st;
switch(i){
case 1:
{
int id,n;
bool s=false;
cout<<"\t请输入要借的书(必须是书的编号):";
cin>>id;
n=st.Check_bookId(id);
if(n!=-1&&n!=0){
book=st.Get_book(n);
s=Borrow_book(book);
if(s)
cout<<"\t借书成功!!!"<<endl;
else
cout<<"\t借书不成功,该书已被借出!!!"<<endl;}
else
cout<<"\t该书不存在!!!"<<endl;
break;
}
case 2:
{
bool su=false;
int n;
int iid;
cout<<"\t请输入要还的书(必须是书的编号):";
cin>>iid;
n=st.Check_bookId(iid);
if(n!=-1&&n!=0){
book=st.Get_book(n);
su=Reback_book(book);
if(su)
cout<<"\t还书成功!!!"<<endl;
else
cout<<"\t还书不成功!!!"<<endl;}
break;
}
case 3:
{
CStackRoom sta;
sta.Search();
break;
}
case 4:
{
Consult();
break;
}
default:break;
}
}
ostream& operator << ( ostream& os,const CReader& reader ){ //重载操作符
// 格式: <occurs> word
os <<setw(14)<< reader.iID <<setw(20)<<reader.sName;
if ( reader.bSex == true )
os << setw(6) <<"男";
else os << setw(6) <<"女";
os <<setw(20)<<reader.sPhone<<setw(8)<<reader.iBorrowNum;
return os;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -