#ifndef ADT_H
#define ADT_H
namespace Banking
{
class InsufficientFunds{};
class Account
{
public:
Account();
int Id() const;
double Balance() const;
virtual void Deposit(double) = 0;
virtual void Withdraw(double) throw (InsufficientFunds) = 0;
void Transfer(double, Account*) throw (InsufficientFunds);
virtual ~Account(){};
protected:
double balance;
private:
int id;
friend Account* OpenAccount(double, bool);
};
#endif
Adt.cpp
#include "adt.h"
#include <ctime>
namespace Banking
{
Account::Account()
{
id = 0;
balance = 0;
}
SavingsAccount::SavingsAccount()
{
balance = 5000;
}
balance -= amount;
}
balance += interest;
return interest;
}
balance += amount;
}
if(savings)
acc = new SavingsAccount;
else
acc = new CurrentAccount;
acc->id = nextid++;
acc->Deposit(amount);
return acc;
}
Adttest.cpp
#include "adt.h"
#include <iostream>
int main(void)
{
using namespace Banking;
double amt;
cout << "Amount to transfer: ";
cin >> amt;
try
{
cust->Transfer(amt, vend);
cout << "Transfer succeeded." << endl;
}
catch(InsufficientFunds)
{
cout << "Transfer failed due to lack of funds! " << endl;
}
CloseAccount(vend);
CloseAccount(cust);
}