Example #1
0
void Bank::Transfer(const Transaction& tr)
{
	Account info;
	Account* from = NULL;
	Account* to = NULL;
	string acc = tr.GetAccount();
	string num = acc.substr(0, acc.length() - 1);
	info.SetNumber(num);

	if (!tree.Retrieve(info, from))
	{
		cerr << "ERROR: Account " << num
			<< " not found. Transferal refused." << endl;
		return;
	}

	string acc2 = tr.GetAccount2();
	string num2 = acc2.substr(0, acc2.length() - 1);
	info.SetNumber(num2);

	if (!tree.Retrieve(info, to))
	{
		cerr << "ERROR: Account " << num2
			<< " not found. Transferal refused." << endl;
		return;
	}

	if (from->Transfer(tr, true))
	{
		to->Transfer(tr, false);
	}
}