108k views
5 votes
Banks have many different types of accounts often with different rules for fees associated with transactions such as withdrawals. Customers can transfer funds between accounts incurring the appropriate fees associated with withdrawal of funds from one account.Write a program with a base class for a bank account and two derived classes as described belowrepresenting accounts with different rules for withdrawing funds. Also write a function that transfers funds from one account of any type to anotheraccount of any type.A transfer is a withdrawal from one accountand a deposit into the other.

1 Answer

4 votes

Answer:

See explaination

Step-by-step explanation:

// Defination of MoneyMarketAccount CLASS

MoneyMarketAccount::MoneyMarketAccount(string name, double balance)

{

acctName = name;

acctBalance = balance;

}

int MoneyMarketAccount::getNumWithdrawals() const

{

return numWithdrawals;

}

int MoneyMarketAccount::withdraw(double amt)

{

if (amt < 0)

{

cout << "Attempt to withdraw negative amount - program terminated."<< endl;

exit(1);

}

if((numWithdrawals < FREE_WITHDRAWALS) && (amt <= acctBalance)){

acctBalance = acctBalance - amt;

return OK;

}

if((numWithdrawals >= FREE_WITHDRAWALS) &&((amt + WITHDRAWAL_FEE) <= acctBalance)){

acctBalance = acctBalance - (amt + WITHDRAWAL_FEE);

return OK;

}

return INSUFFICIENT_FUNDS;

}

// Defination of CDAccount CLASS

CDAccount::CDAccount(string name, double balance, double rate)

{

acctName = name;

acctBalance = balance;

interestRate = rate/100.0;

}

int CDAccount::withdraw(double amt)

{

if (amt < 0)

{

cout << "Attempt to withdraw negative amount - program terminated."<< endl;

exit(1);

}

double penalty = (PENALTY*interestRate*acctBalance);

if((amt + penalty) <= acctBalance){

acctBalance = acctBalance - (amt + penalty);

return OK:

}

else

return INSUFFICIENT_FUNDS;

}

void transfer (double amt, BankAccount& fromAcct, BankAccount& toAcct)

{

if (amt < 0 || fromAcct.acctBalance < 0 || toAcct < 0)

{

cout << "Attempt to transfer negative amount - program terminated."<< endl;

exit(1);

}

if(fromAcct.withdraw(amt) == OK){ // if withdraw function on fromAcct return OK, then me can withdraw amt from fromAcct

// and deposit in toAcct

toAcct.acctBalance = toAcct.acctBalance + amt;

}

}

User WeirdlyCheezy
by
4.8k points