Please help me on c++ using code blocks Banks offer various types of accounts, s
ID: 652023 • Letter: P
Question
Please help me on c++ using code blocks
Banks offer various types of accounts, such as savings, checking, certificate of deposits, and money market, to attract customers as well as meet with their specific needs. Two of the most commonly used accounts are savings and checking. Each of these accounts has various options. For example, you may have a savings account that requires no minimum balance but has a lower interest rate. Similarly, you may have a checking account that limits the number of checks you may write. Another type of account that is used to save money for the long term is certificate of deposit (CD).
In this programming exercise, you use abstract classes and pure virtual functions to design classes to manipulate various types of accounts. For simplicity, assume that the bank offers three types of accounts: savings, checking, and certificate of deposit, as described next.
Savings accounts: Suppose that the bank offers two types of savings accounts: one that has no minimum balance and a lower interest rate and another that requires a minimum balance and has a higher interest rate.
Checking accounts: Suppose that the bank offers three types of checking minimum balance, and no interest; another with no monthly service charge, a minimum balance requirement, unlimited check writing and lower interest; and a third with no monthly service charge, a higher minimum requirement, a higher interest rate, and unlimited check writing.
Certificate of deposit (CD): In an account of this type, money is left for some time, and these accounts draw higher interest rates than savings or checking accounts. Suppose that you purchase a CD for six months. Then we say that the CD will mature in six months. Penalty for early withdrawal is stiff.
The figure, on next page, shows the inheritance hierarchy of these bank accounts. Note that the classes bankAccount and checkingAccount are abstract. That is, we cannot instantiate objects of these classes. The other classes in the next figure are not abstract. Next we describe each of the classes:
bankAccount: Every bank account has an account number, the name of the owner, and a balance. Therefore, instance variables such as name, accountNumber, and balance should be declared in the abstract class bankAccount. Some operations common to all types of accounts are retrieve account owner
Explanation / Answer
bankAccount.cpp
bankAccount.h
#ifndef BANKACCOUNT_H
#define BANKACCOUNT_H
#include <String>
using namespace std;
class bankAccount {
public:
bankAccount(string name, double initialBalance);
string getName();
unsigned int getAccountNumber();
double getBalance();
double getInterestRate();
string getStatementString();
void deposit(double amount);
void deposit(double amount, string statement);
void withdraw(double amount);
void withdraw(double amount, string statement);
virtual void printStatement() = 0;
protected:
void addStatementLine(string statement, double amount);
private:
string name;
unsigned int accountNumber;
double balance;
static unsigned int nextAccountNumber;
string statementString;
};
#endif /* BANKACCOUNT_H */
certificateOfDeposit.cpp
#include "certificateOfDeposit.h"
certificateOfDeposit::certificateOfDeposit(string name, double initialBalance, int maturityMonths) : bankAccount(name, initialBalance)
{
this->maturityMonths = maturityMonths;
interestRate = 0.03;
currentCDMonth = 0;
withdrawalPenaltyMonths = 3;
}
certificateOfDeposit::certificateOfDeposit(string name, double initialBalance) : bankAccount(name, initialBalance)
{
maturityMonths = 6;
interestRate = 0.03;
currentCDMonth = 0;
withdrawalPenaltyMonths = 3;
}
int certificateOfDeposit::getCurrentCDMonth()
{
return currentCDMonth;
}
double certificateOfDeposit::getInterestRate()
{
return interestRate;
}
int certificateOfDeposit::getWithdrawalPenaltyMonths()
{
return withdrawalPenaltyMonths;
}
int certificateOfDeposit::getMaturityMonths()
{
return maturityMonths;
}
void certificateOfDeposit::withdraw()
{
if (getCurrentCDMonth() < getMaturityMonths())
bankAccount::withdraw(getBalance()*getInterestRate()*getWithdrawalPenaltyMonths(), "Early Withdrawal Penalty");
bankAccount::withdraw(getBalance(), "Close Account");
}
void certificateOfDeposit::incrementMonth()
{
bankAccount::deposit(getBalance()*getInterestRate(), "Monthly Interest");
if (getCurrentCDMonth() < getMaturityMonths())
{
currentCDMonth++;
}
else
withdraw();
}
void certificateOfDeposit::printStatement()
{
cout << "Certificate of Deposit Statement" << endl;
cout << "Name: " << getName() << endl;
cout << "Account Number: " << getAccountNumber() << endl;
cout << "Interest Rate: " << getInterestRate() * 100 << "%" << endl;
cout << "Maturity Month: " << getMaturityMonths() << ", Current Month: " << getCurrentCDMonth() << endl;
cout << "Early Withdrawal Penalty: " << getWithdrawalPenaltyMonths() << " (months)" << endl << endl;
cout << getStatementString() << endl;
cout << "Final Balance: " << getBalance() << endl << endl;
}
certificateOfDeposit.h
#ifndef CERTIFICATEOFDEPOSIT_H
#define CERTIFICATEOFDEPOSIT_H
#include "bankAccount.h"
#include <iostream>
using namespace std;
class certificateOfDeposit : public bankAccount{
public:
certificateOfDeposit(string name, double initialBalance, int maturityMonths);
certificateOfDeposit(string name, double initialBalance);
int getMaturityMonths();
double getInterestRate();
int getCurrentCDMonth();
int getWithdrawalPenaltyMonths();
void withdraw();
void incrementMonth();
void printStatement();
private:
int maturityMonths;
double interestRate;
int currentCDMonth;
int withdrawalPenaltyMonths;
void withdraw(double amount);
void withdraw(double amount, string statement);
void deposit(double amount);
};
#endif /* CERTIFICATEOFDEPOSIT_H */
checkingAccount.cpp
#include "checkingAccount.h"
checkingAccount::checkingAccount(string name, double initialBalance) : bankAccount(name, initialBalance)
{
}
checkingAccount.h
#ifndef CHECKINGACCOUNT_H
#define CHECKINGACCOUNT_H
#include "bankAccount.h"
class checkingAccount : public bankAccount {
public:
checkingAccount(string name, double initialBalance);
virtual void writeCheck(double amount, int checkNumber) = 0;
private:
};
#endif /* CHECKINGACCOUNT_H */
highInterestChecking.cpp
#include "highInterestChecking.h"
highInterestChecking::highInterestChecking(string name, double initialBalance) : noServiceChargeChecking(name, initialBalance, 2000, 0.01)
{
}
void highInterestChecking::printStatement()
{
bankAccount::deposit(getBalance() * getInterestRate(), "Interest");
cout << "High Interest Checking Statement" << endl;
cout << "Name: " << getName() << endl;
cout << "Account Number: " << getAccountNumber() << endl;
cout << "Interest Rate: " << getInterestRate() * 100 << "%" << endl;
cout << "Minimum Balance: " << getMinimumBalance() << endl << endl;
cout << getStatementString() << endl;
cout << "Final Balance: " << getBalance() << endl << endl;
}
highInterestChecking.h
#ifndef HIGHINTERESTCHECKING_H
#define HIGHINTERESTCHECKING_H
#include "noServiceChargeChecking.h"
#include <string>
using namespace std;
class highInterestChecking : public noServiceChargeChecking {
public:
highInterestChecking(string name, double initialBalance);
void printStatement();
private:
};
#endif /* HIGHINTERESTCHECKING_H */
highInterestChecking.h
#ifndef HIGHINTERESTCHECKING_H
#define HIGHINTERESTCHECKING_H
#include "noServiceChargeChecking.h"
#include <string>
using namespace std;
class highInterestChecking : public noServiceChargeChecking {
public:
highInterestChecking(string name, double initialBalance);
void printStatement();
private:
};
#endif /* HIGHINTERESTCHECKING_H */
highInterestSavings.cpp
#include "highInterestSavings.h"
highInterestSavings::highInterestSavings(string name, double initialBalance) : savingsAccount(name, initialBalance, 0.02)
{
minimumBalance = 5000;
}
int highInterestSavings::getMinimumBalance()
{
return minimumBalance;
}
void highInterestSavings::withdraw(double amount, string statement)
{
if (amount + getMinimumBalance() <= getBalance())
{
bankAccount::withdraw(amount, statement);
}
else
{
addStatementLine(statement.append(" Overdraft. Below Minimum Balance."), amount);
}
}
void highInterestSavings::withdraw(double amount)
{
withdraw(amount, "Withdrawal");
}
void highInterestSavings::printStatement()
{
bankAccount::deposit(getBalance() * getInterestRate(), "Interest");
cout << "High Interest Savings Account Statement" << endl;
cout << "Name: " << getName() << endl;
cout << "Account Number: " << getAccountNumber() << endl;
cout << "Minimum Balance: " << getMinimumBalance() << endl;
cout << "Interest Rate: " << getInterestRate() * 100 << "%" << endl << endl;
cout << getStatementString() << endl;
cout << "Final Balance: " << getBalance() << endl << endl;
}
highInterestSavings.h
#ifndef HIGHINTERESTSAVINGS_H
#define HIGHINTERESTSAVINGS_H
#include "savingsAccount.h"
#include <iostream>
using namespace std;
class highInterestSavings : public savingsAccount{
public:
highInterestSavings(string name, double initialBalance);
int getMinimumBalance();
void printStatement();
void withdraw(double amount, string statement);
void withdraw(double amount);
private:
int minimumBalance;
};
#endif /* HIGHINTERESTSAVINGS_H */
noServiceChargeChecking.cpp
#include "noServiceChargeChecking.h"
#include <sstream>
#include <iostream>
noServiceChargeChecking::noServiceChargeChecking(string name, double initialBalance) : checkingAccount(name, initialBalance)
{
minimumBalance = 500;
this->interestRate = 0.001;
}
noServiceChargeChecking::noServiceChargeChecking(string name, double initialBalance, int minBalance, double interestRate) : checkingAccount(name, initialBalance)
{
minimumBalance = minBalance;
this->interestRate = interestRate;
}
void noServiceChargeChecking::writeCheck(double amount, int checkNumber)
{
stringstream output;
output << "Check #" << checkNumber;
withdraw(amount, output.str());
}
void noServiceChargeChecking::withdraw(double amount, string statement)
{
if (amount + getMinimumBalance() <= getBalance())
{
bankAccount::withdraw(amount, statement);
}
else
{
addStatementLine(statement.append(" Overdraft. Below Minimum Balance."), amount);
}
}
void noServiceChargeChecking::withdraw(double amount)
{
withdraw(amount, "Withdrawal");
}
void noServiceChargeChecking::printStatement()
{
bankAccount::deposit(getBalance() * getInterestRate(), "Interest");
cout << "No Service Charge Checking Statement" << endl;
cout << "Name: " << getName() << endl;
cout << "Account Number: " << getAccountNumber() << endl;
cout << "Interest Rate: " << getInterestRate() * 100 << "%" << endl;
cout << "Minimum Balance: " << getMinimumBalance() << endl << endl;
cout << getStatementString() << endl;
cout << "Final Balance: " << getBalance() << endl << endl;
}
int noServiceChargeChecking::getMinimumBalance()
{
return minimumBalance;
}
double noServiceChargeChecking::getInterestRate()
{
return interestRate;
}
noServiceChargeChecking.h
#ifndef NOSERVICECHARGECHECKING_H
#define NOSERVICECHARGECHECKING_H
#include "checkingAccount.h"
#include <iostream>
using namespace std;
class noServiceChargeChecking : public checkingAccount {
public:
noServiceChargeChecking(string name, double initialBalance);
void writeCheck(double amount, int checkNumber);
void printStatement();
void withdraw(double amount, string statement);
void withdraw(double amount);
double getInterestRate();
int getMinimumBalance();
protected:
noServiceChargeChecking(string name, double initialBalance, int minBalance, double interestRate);
private:
double interestRate;
int minimumBalance;
};
#endif /* NOSERVICECHARGECHECKING_H */
savingsAccount.cpp
#include "savingsAccount.h"
savingsAccount::savingsAccount(string name, double initialBalance) : bankAccount(name, initialBalance)
{
interestRate = .005;
}
savingsAccount::savingsAccount(string name, double initialBalance, double interestRate) : bankAccount(name, initialBalance)
{
this->interestRate = interestRate;
}
double savingsAccount::getInterestRate()
{
return interestRate;
}
void savingsAccount::printStatement()
{
bankAccount::deposit(getBalance() * getInterestRate(), "Interest");
cout << "Savings Account Statement" << endl;
cout << "Name: " << getName() << endl;
cout << "Account Number: " << getAccountNumber() << endl;
cout << "Interest Rate: " << getInterestRate() * 100 << "%" << endl << endl;
cout << getStatementString() << endl;
cout << "Final Balance: " << getBalance() << endl << endl;
}
savingsAccount.h
#ifndef SAVINGSACCOUNT_H
#define SAVINGSACCOUNT_H
#include "bankAccount.h"
#include <iostream>
using namespace std;
class savingsAccount : public bankAccount {
public:
savingsAccount(string name, double initialBalance);
double getInterestRate();
void printStatement();
protected:
savingsAccount(string name, double initialBalance, double interestRate);
private:
double interestRate;
};
#endif /* SAVINGSACCOUNT_H */
serviceChargeChecking.cpp
#include "serviceChargeChecking.h"
#include <sstream>
#include <iostream>
using namespace std;
serviceChargeChecking::serviceChargeChecking(string name, double initialBalance) : checkingAccount(name, initialBalance)
{
bankAccount::withdraw(SERVICE_CHARGE, "Service Charge");
checksWritten = 0;
}
void serviceChargeChecking::writeCheck(double amount, int checkNumber)
{
stringstream output;
if (++checksWritten <= CHECK_LIMIT)
{
output << "Check #" << checkNumber;
bankAccount::withdraw(amount, output.str());
}
else
{
output << "Maximum Limit of Checks Reached. Check # " << checkNumber << " bounced";
addStatementLine(output.str(), amount);
}
}
void serviceChargeChecking::printStatement()
{
cout << "Service Charge Checking Statement" << endl;
cout << "Name: " << getName() << endl;
cout << "Account Number: " << getAccountNumber() << endl << endl;
cout << getStatementString() << endl;
cout << "Final Balance: " << getBalance() << endl << endl;
}
serviceChargeChecking.h
#ifndef SERVICECHARGECHECKING_H
#define SERVICECHARGECHECKING_H
#include "checkingAccount.h"
#include <String>
using namespace std;
class serviceChargeChecking : public checkingAccount {
public:
serviceChargeChecking(string name, double initialBalance);
void writeCheck(double amount, int checkNumber);
void printStatement();
private:
int checksWritten;
static const int CHECK_LIMIT = 6;
static const int SERVICE_CHARGE = 5;
};
#endif /* SERVICECHARGECHECKING_H */