📄 bank.cpp
字号:
// Bank.cpp: implementation of the Bank class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Bank.h"
#include "AccountStandard.h"
#include "AccountVIP.h"
#include "ErrorCode.h"
#include "Error.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
Bank::Bank()
{
m_iAccountNum = 53100001; //随便取的一个大数,作为帐号的开头
}
Bank::~Bank()
{
int iCount=m_AccountList.GetCount();
for(int i=0;i<iCount;i++){
Account *pAccount = (Account *)m_AccountList.RemoveHead();
delete pAccount;
}
}
int Bank::NewAccount(int Type, int *pID)
{
Account *pAccount=NULL;
switch(Type){
case 1:
pAccount = new AccountStandard();
break;
case 2:
pAccount = new AccountVIP();
break;
default:
Error::SetLastError("Error account type.");
return PARAMERROR; //参数错误
}
pAccount->SetID(m_iAccountNum++); //生成ID
*pID=pAccount->GetID();
m_AccountList.AddAccount(pAccount); //加入列表当中
return NOERROR;
}
int Bank::GetBalance(int id, double *Balance)
{
Account *pAccount = m_AccountList.GetAccountByID(id);
if(pAccount==NULL){
Error::SetLastError("No such account id.");
return NOSUCHACCOUNT; //返回错误代码:没有该用户
}
*Balance=pAccount->GetBalance();
return NOERROR;
}
int Bank::Save(int id, double Amount)
{
Account *pAccount = m_AccountList.GetAccountByID(id);
if(pAccount==NULL){
Error::SetLastError("No such account id.");
return NOSUCHACCOUNT; //返回错误代码:没有该用户
}
return pAccount->Save(Amount);
}
int Bank::Withdraw(int id, double Amount)
{
Account *pAccount = m_AccountList.GetAccountByID(id);
if(pAccount==NULL){
Error::SetLastError("No such account id.");
return NOSUCHACCOUNT; //返回错误代码:没有该用户
}
return pAccount->Withdraw(Amount);
}
int Bank::Transfer(int idfrom, int idto, double Amount)
{
int iRet;
Account *pAccountFrom = m_AccountList.GetAccountByID(idfrom);
if(pAccountFrom==NULL){
Error::SetLastError("No such account id.");
return NOSUCHACCOUNT; //返回错误代码:没有该用户
}
iRet = pAccountFrom->Withdraw(Amount);
if(iRet!=0){
return iRet; //返回在取钱过程中的错误
}
Account *pAccountTo = m_AccountList.GetAccountByID(idto);
if(pAccountTo==NULL){
Error::SetLastError("No such account id.");
return NOSUCHACCOUNT; //返回错误代码:没有该用户
}
iRet = pAccountTo->Save(Amount);
return iRet;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -