?? atm.h
字號:
//ATM.h
#include "Bank.h"
#include "UserInterface.h"
class ATM {
public :
ATM (Bank* ,UserInterface* ,float avail,float limit);
void startService();
private:
Bank* bank;
UserInterface* ui;
float avail;
float limit;
};
ATM::ATM(Bank* b,UserInterface* u,float a,float lmt){
bank=b;
ui=u;
avail=a;
limit=lmt;
}
void ATM::startService(){
//Main Interface to the customer
int id=0,pin=0;
ui->welcome();
id=ui->getUserId();
pin=ui->getUserCode();
while(!((id==0)&&(pin==1))) // stopped by a special account ID(0) and pin(1).
{
if(bank->validate(id,pin))// Check whether Id and Pin are both legal!
{
Account* current=bank->getAccount(id);//Get the information of this current valid account
ui->showMenu();
int select=ui->getUserSelection();
while(select!=5)//....... operate on the account of the customer
{
switch(select)
{
case 1: //Deposit
{
float amount=ui->getUserAmount(); // get the amount user deposit
DepTransaction* trans=new DepTransaction(id,pin,amount);
trans->Transaction::setAcct(current);// Deposit amount to current account
bank->processTrans(trans); // Finish Deposit operation
delete trans;
float b=current->getBalance();// Show the current Balance
ui->showBalance(b);
ui->showMenu();
select=ui->getUserSelection();
}
break;
case 2: // Balance
{
float b=current->getBalance();
ui->showBalance(b);
//Finish Balance operation
ui->showMenu();
select=ui->getUserSelection();
}
break;
case 3: // Withdraw
{
try {
float amount=ui->getUserAmount();// get the amount user withdraw
float balance=current->getBalance(),overdraft=current->getOverdraft();
if(amount-balance>overdraft)
{
char msg[]="Sorry, You have no sufficient funds!";
throw msg;
}
WithTransaction* trans=new WithTransaction(id,pin,amount);
trans->Transaction::setAcct(current);// Withdraw amount to current account
bank->processTrans(trans); // Finish Withdraw Transaction
delete trans;
float b=current->getBalance();// Show the current Balance
ui->showBalance(b);
ui->showMenu();
select=ui->getUserSelection();
}
catch (char* msg){
cerr<<msg<<endl;
ui->showMenu();
select=ui->getUserSelection();
}
}
break;
case 4: // Transfer
{
try{
float amount=ui->getUserAmount();// get the amount user transfer
float balance=current->getBalance(),overdraft=current->getOverdraft();
if(amount-balance>overdraft) //Throw a error message while transfering
{ // money from current accoutn without sufficient funds
char msg[]="Sorry, You have no sufficient funds to transfer!";
throw msg;
}
int nextID=ui->getTransferAcct(); // get the transfered account
Account* Tacct=bank->getAccount(nextID);//Create a pointer to transfer account
try{ // Throw a integer as a signature when the transfer account
if(Tacct==0) // does not exist.
{
throw 1;
}
TranTransaction* trans=new TranTransaction(id,pin,amount);
trans->Transaction::setAcct(current);// Transfer amount from current account
trans->Transaction::setTacct(Tacct); // to another account
bank->processTrans(trans); // Finish Transfer Transaction
delete trans;
float b=current->getBalance();// Show the current Balance
ui->showBalance(b);
ui->showMenu();
select=ui->getUserSelection();}
catch (int i) // Catch a integer signature when transfer account doesn't exist.
{
cerr<<"Sorry,The transfered Account does not exist!"<<endl;
ui->showMenu();
select=ui->getUserSelection();
}
}
catch (char* msg){ // Catch a pointer to char while tranfering money
cerr<<msg<<endl;// at current account without sufficient funds
ui->showMenu();
select=ui->getUserSelection();
}
}
break;
default:
select=ui->getUserSelection();
break;
}
}
ui->bye();
ui->welcome();
}
else// if the id and pin are not valid
{
ui->showError();
}
id=ui->getUserId();
pin=ui->getUserCode();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -