I had seen this code posted before, but the resolution to the BankAccount.h was not posted. Can someone supply the finished work, I am not able to figure out where the guards were needing to be moved to.
/tester.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
#include <iostream>
#include <iomanip>
#include "SavingsAccount.h"
#include "CheckingAccount.h"
using namespace std;
int main()
{
CheckingAccount jackAccount(1000);
CheckingAccount lisaAccount(450);
SavingsAccount samirAccount(9300);
SavingsAccount ritaAccount(32);
jackAccount.deposit(1000);
lisaAccount.deposit(2300);
samirAccount.deposit(800);
ritaAccount.deposit(500);
jackAccount.postInterest();
lisaAccount.postInterest();
samirAccount.postInterest();
ritaAccount.postInterest();
cout << "***********************************" << endl;
jackAccount.print();
lisaAccount.print();
samirAccount.print();
ritaAccount.print();
cout << "***********************************" << endl << endl;
jackAccount.writeCheck(250);
lisaAccount.writeCheck(350);
samirAccount.withdraw(120);
ritaAccount.withdraw(290);
cout << "********After withdrawals ***************" << endl;
jackAccount.print();
lisaAccount.print();
samirAccount.print();
ritaAccount.print();
cout << "***********************************" << endl << endl;
system("pause");
return 0;
}
| |
//BankAccount.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
#include <iostream>
#include <iomanip>
using namespace std;
class BankAccount{
public:
BankAccount();
BankAccount(double balance);
int get_actNumber();
void deposit(double amount);
void withdrawl(double amount);
double get_balance();
void printInfo();
protected:
double _balance;
static int _number;
};
BankAccount::BankAccount()
{
_balance = 0.0;
}
BankAccount::BankAccount(double balance)
{
_balance = balance;
}
int BankAccount::get_actNumber()
{
return _number = _number + 100;
}
void BankAccount::deposit(double amount)
{
_balance = _balance + amount;
}
void BankAccount::withdrawl(double amount)
{
_balance = _balance - amount;
}
double BankAccount::get_balance()
{
return _balance;
}
int BankAccount::_number = 1000;
| |
//SavingsAccount.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
#include <iostream>
#include <iomanip>
#include "BankAccount.h"
#ifndef SAVINGACCOUNT_H
#define SAVINGACCOUNT_H
using namespace std;
class SavingAccount : public BankAccount
{
public:
SavingAccount(double balance);
void set_interestRate(double rate);
double get_interestRate();
void postInterest();
void withdrawl(double amount);
void printInfo();
protected:
double _rate;
};
#endif
SavingAccount::SavingAccount(double balance)//Since the tester that was provided doesnt set the rate, min balance or fee I just set it here
: BankAccount(balance)
{
_rate = .06;
}
void SavingAccount::set_interestRate(double rate)
{
_rate = rate;
}
double SavingAccount::get_interestRate()
{
return _rate;
}
void SavingAccount::postInterest()
{
_balance += (_balance * _rate);
}
void SavingAccount::withdrawl(double amount)
{
if (_balance >= amount)
{
_balance = _balance - amount;
}
else
{
cout << "Insufficient funds. Withdrawl transaction rejected, balance remains the same" << endl;
}
}
void SavingAccount::printInfo()
{
cout << "Interest Saving ACCT#:" << get_actNumber() << " Balance: $" << setprecision(2) << fixed << get_balance() << endl;
}
| |
//CheckingAccount.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
#include <iostream>
#include <iomanip>
#include "BankAccount.h"
// using namespace std; // *** don't have this in a header file
CheckingAccount::CheckingAccount(double balance)//Since the tester that was provided doesnt set the rate, min balance or fee I just set it here
: BankAccount(balance)
{
//_number = get_actNumber();
_fee = 15;
_minBalance = 200;
_rate = 0.04;
}
void CheckingAccount::set_interestRate(double rate)
{
_rate = rate;
}
double CheckingAccount::get_interestRate()
{
return _rate;
}
void CheckingAccount::set_minBalance(double minBal)
{
_minBalance = minBal;
}
double CheckingAccount::get_minBalance()
{
return _minBalance;
}
bool CheckingAccount::checkMin()
{
if (_balance >= _minBalance)
{
return true;
}
else
return false;
}
void CheckingAccount::set_fee(double fee)
{
_fee = fee;
}
double CheckingAccount::get_fee()
{
return _fee;
}
void CheckingAccount::postInterest()
{
_balance += (_balance * _rate);
}
void CheckingAccount::withdrawl(double amount)
{
if (_balance < amount)
{
cout << "insufficient funds. Withdrawl rejected, does not affect balance." << endl;
}
else//I assume the bank will allow a withdrawl as long as the balance is greater than the amount even if the fee drops the account into the negative
{
if (_balance - amount >= _minBalance)
{
_balance = _balance - amount;
}
else
{
_balance -= (amount + _fee);
}
}
}
void CheckingAccount::writeCheck(double amount)
{
withdrawl(amount);
}
void CheckingAccount::printInfo()
{
cout << "Interest Checking ACCT#:" << get_actNumber() << " Balance: $" << setprecision(2) << fixed << get_balance() << endl;
}
| |
Output should look like,
***********************************
Interest Checking ACCT#: 1100 Balance: $2080.00
Interest Checking ACCT#: 1200 Balance: $2860.00
Savings ACCT#: 1300 Balance: $10706.00
Savings ACCT#: 1400 Balance: $563.92
***********************************
********After withdrawals ***************
Interest Checking ACCT#: 1100 Balance: $1830.00
Interest Checking ACCT#: 1200 Balance: $2510.00
Savings ACCT#: 1300 Balance: $10586.00
Savings ACCT#: 1400 Balance: $273.92
***********************************
Press any key to continue . . .