- Engineering
- Computer Science
- please read entire question for c codes used below bankaccountcpp...
Question: please read entire question for c codes used below bankaccountcpp...
Question details
Please read entire question
For C++
Codes used below
bankAccount.cpp
#include "bankAccount.h"
//bankAccount::bankAccount()
//{
//}
bankAccount::bankAccount(string acctNum, double startBal)
{
accountNumber = acctNum;
balance = startBal;
}
//bankAccount::~bankAccount()
//{
//}
double bankAccount::deposit(double depositAmt)
{
balance += depositAmt;
return balance;
}
string bankAccount::getAccountNumber()
{
return accountNumber;
}
double bankAccount::getBalance()
{
return balance;
}
void bankAccount::print()
{
cout << "Your account Number: " <<
getAccountNumber() << endl;
cout << "Your current balance: $" <<
getBalance() << endl;
}
void bankAccount::setAccountNumber(string acctNum)
{
accountNumber = acctNum;
}
double bankAccount::withdraw(double withdrawalAmt)
{
balance -= withdrawalAmt;
return balance;
}
ba nkAccount.h
#ifndef BANKACCOUNT_H
#define BANKACCOUNT_H
#include
#include
using namespace std;
class bankAccount
{
protected:
string accountNumber;
double balance;
public:
//bankAccount();
bankAccount(string acctNum, double startBal);
//~bankAccount();
double deposit(double depositAmt);
string getAccountNumber();
double getBalance();
void print();
void setAccountNumber(string acctNum);
double withdraw(double withdrawalAmt);
};
#endif // !BANKACCOUNT_H
checkingAccount.cpp
#include "checkingAccount.h"
//checkingAccount::checkingAccount()
//{
//}
checkingAccount::checkingAccount(string acctNum, double
startBal,
double intRate, double minBalance, double srvCharge) :
bankAccount(acctNum, startBal)
{
//bankAccount::accountNumber = acctNum;
//bankAccount::balance = startBal;
interestRate = intRate;
minimumBalance = minBalance;
serviceCharge = srvCharge;
}
//checkingAccount::~checkingAccount()
//{
//}
double checkingAccount::getInterestRate()
{
return interestRate;
}
double checkingAccount::getMinimumBalance()
{
return minimumBalance;
}
double checkingAccount::getServiceCharge()
{
return serviceCharge;
}
// Multiplies balance times interest rate (as percentage)
divided by 100, adds interest to balance,
// and returns interest gained
double checkingAccount::postInterest()
{
if (balance <= 0)
{
return 0;
}
double interest = 0;
interest = bankAccount::balance * (interestRate /
100);
bankAccount::balance += interest;
return interest;
}
void checkingAccount::print()
{
cout << endl << "Your account Number: "
<< getAccountNumber() << endl;
cout << "Your current balance: $" <<
getBalance() << endl;
cout << "Your interest rate: %" <<
getInterestRate() << endl;
cout << "Your minimum balance: $" <<
getMinimumBalance() << endl;
cout << "Your service charge: $" <<
getServiceCharge() << endl;
}
void checkingAccount::setInterestRate(double intRate)
{
interestRate = intRate;
}
void checkingAccount::setMinimumBalance(double minBalance)
{
minimumBalance = minBalance;
}
void checkingAccount::setServiceCharge(double srvCharge)
{
serviceCharge = srvCharge;
}
// returns true if balance is below minimum balance
bool checkingAccount::verifyMinimumBalance()
{
bool balanceBelow = false;
if (bankAccount::balance < minimumBalance)
balanceBelow = true;
return balanceBelow;
}
double checkingAccount::withdraw(double withdrawalAmt)
{
//check if enough balance
if ((bankAccount::balance - withdrawalAmt) <
0)
{
cout << endl << "This
will overdraw your account! Can not withdraw." << endl;
}
else
{
bankAccount::balance -=
withdrawalAmt;
if (verifyMinimumBalance())
{
balance -=
getServiceCharge();
cout <<
"You've dropped below your minimum balacnce!" << endl;
cout <<
"You've been charged a fee of $" << getServiceCharge()
<< endl;
}
}
return bankAccount::balance;
}
void checkingAccount::writeCheck(string recipient, double
checkAmount)
{
if ((balance - checkAmount) < 0)
{
cout << "Insufficient funds"
<< endl;
return;
}
withdraw(checkAmount);
//check min balance and charge if below min
balance
if (verifyMinimumBalance())
{
balance -=
getServiceCharge();
cout << "You've dropped below
your minimum balacnce!" << endl;
cout << "You've been charged
a fee of $" << getServiceCharge();
}
cout << endl << "Check sent to " <<
recipient << " for $" << checkAmount <<
endl;
cout << "Your current balance is $" <<
getBalance() << endl;
}
checkingAccount.h
#include
#include
using namespace std;
class checkingAccount :
public bankAccount
{
private:
double interestRate;
double minimumBalance;
double serviceCharge;
public:
//checkingAccount();
checkingAccount(string acctNum, double startBal,
double intRate, double minBalance, double srvCharge);
//~checkingAccount();
double getInterestRate();
double getMinimumBalance();
double getServiceCharge();
double postInterest();
void print();
void setInterestRate(double intRate);
void setMinimumBalance(double minBalance);
void setServiceCharge(double srvCharge);
bool verifyMinimumBalance();
double withdraw(double withdrawalAmt);
void writeCheck(string recipient, double
checkAmount);
};
#endif
savingsAccount.cpp
#include "savingsAccount.h"
//savingsAccount::savingsAccount()
//{
//}
savingsAccount::savingsAccount(string acctNum,
double startBal, double intRate) :
bankAccount(acctNum, startBal)
{
accountNumber = acctNum;
//balance = startBal;
//interestRate = intRate;
}
//savingsAccount::~savingsAccount()
//{
//}
double savingsAccount::getInterestRate()
{
return interestRate;
}
double savingsAccount::postInterest()
{
double interest = 0;
interest = bankAccount::balance * (interestRate /
100);
bankAccount::balance += interest;
return interest;
}
void savingsAccount::print()
{
cout << endl << "Your account Number: "
<< getAccountNumber() << endl;
cout << "Your current balance: $" <<
getBalance() << endl;
cout << "Your interest rate: %" <<
getInterestRate() << endl;
}
void savingsAccount::setInterestRate(double intRate)
{
interestRate = intRate;
}
double savingsAccount::withdraw(double withdrawalAmt)
{
//verify there's enough money in account
if ((bankAccount::balance - withdrawalAmt) <
0)
{
cout << endl <<
"Insufficient funds for withdrawal." << endl;
}
else
{
bankAccount::balance -=
withdrawalAmt;
}
return bankAccount::balance;
}
savingsAccount.h
#ifndef SAVINGSACCOUNT_H
#define SAVINGSACCOUNT_H
#include
#include
#include "bankAccount.h"
using namespace std;
class savingsAccount :
public bankAccount
{
private:
double interestRate;
public:
//savingsAccount();
savingsAccount(string acctNum, double startBal, double
intRate);
//~savingsAccount();
double getInterestRate();
double postInterest();
void print();
void setInterestRate(double intRate);
double withdraw(double withdrawalAmt);
};
#endif
bankAccountTest.cpp
#include
#include
#include "savingsAccount.h"
#include "checkingAccount.h"
using namespace std;
int main()
{
bankAccount *accountsList[6];
accountsList[0] = new checkingAccount("Bill", 10200, 25000,100,0.012,10.00);
accountsList[1] = new checkingAccount("Bob", 10210, 10000,100,0.0099,15.00);
accountsList[2] = new savingsAccount("Susan", 90001, 20000,0.031);
accountsList[3] = new savingsAccount("Steve", 90002, 50000,0.041);
accountsList[4] = new checkingAccount("Sally", 10220, 4999,100,0.0079,20.00);
accountsList[5] = new savingsAccount("Frad", 90003, 2000,0.011);
cout << "January: -------------" << endl;
for (int i = 0; i < 6; i++)
{
accountsList[i]->createMonthlyStatement();
accountsList[i]->print();
cout << endl;
}
cout << " February: -------------" << endl;
for (int i = 0; i < 6; i++)
{
accountsList[i]->createMonthlyStatement();
accountsList[i]->print();
cout << endl;
}
for (int i = 0; i < 6; i++)
{
accountsList[i]->withdraw(500);
}
cout << " March: -------------" << endl;
for (int i = 0; i < 6; i++)
{
accountsList[i]->createMonthlyStatement();
accountsList[i]->print();
cout << endl;
}
return 0;
}
Solution by an expert tutor
