Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Help. Please read and follow ALL directions. Please include Comments! Please

ID: 3747426 • Letter: C

Question

C++ Help. Please read and follow ALL directions. Please include Comments! Please include screenshots as well so I know how to set up in Visual Studio. Thank you.

Solve problem 5 on page 891 using the following modifications:

Assume

SavingsAccount: Assume an Interest Rate of 0.03

HighInterestSavings: Assume an Interest Rate of 0.05, Minimum Balance = $2500

NoServiceChargeChecking: Assume an Interest Rate = 0.02, Minimum of Balance = $1000

ServiceChargeChecking – Assume account service charge = $10, Maximum number of checks = 5, Service Charge if customer exceeds the maximum number of checks = $5.

NoServicechargeChecking: Assume an interest rate = 0.02, Minimum Balance = $1000

HighInterestChecking: Assume an interest rate = 0.05, Minimum Balance = $5000

CertificateOfDepsit: Assume an interest rate = 0.05, Initial Number of Maturity Months = 6

    

Capitalize the first letter of the derived class names.

Use the following driver to validate your program:

#include <iostream>

#include <iomanip>

#include <vector>

#include "BankAccount.h"

#include "SavingsAccount.h"

#include "HighInterestSavings.h"

#include "NoServiceChargeChecking.h"

#include "ServiceChargeChecking.h"

#include "HighInterestChecking.h"

#include "CertificateOfDeposit.h"

#include "checkingAccount.h"

using namespace std;

int main()

{

    vector<BankAccount *> accountsList;

       //SavingsAccount( Name, Account number, Balance ) - Assume an interest rate = 0.03

    accountsList.push_back(new SavingsAccount("Bill", 10200, 2500));

       //HighInterestSavings(Name, Account Number, Balance) -- Assume an interest rate = 0.05, Minimum balance = $2500

    accountsList.push_back(new HighInterestSavings("Susan", 10210, 2000));

       //NoServiceChargeChecking(Name, Account Number, Balance) -- Assume an interest rate = 0.02, Minimum balance = $1000

    accountsList.push_back(new NoServiceChargeChecking("John", 20100,

                                                    3500));

       //ServiceChargeChecking(Name, Account Number, Balance) -- Assume account service charge = $10, Maximum number of checks = 5, Service Charee Excess Number of Checks = $5

    accountsList.push_back(new ServiceChargeChecking("Ravi", 30100, 1800));

       //HighIntererestChecking(Name, Account Number, Balance) - Assume an inerest rate = 0.05, Minimum balance = $5000

    accountsList.push_back(new HighInterestChecking("Sheila", 20200, 6000));

       //Certificate(name, Account Number, Balance, Interest Rate, Number of Months) - Assume an initial interest rate = 0.05, Initial Number of Maturity Months = 6

    accountsList.push_back(new CertificateOfDeposit("Hamid", 51001, 18000,

                                                0.075, 18));

    cout << "January: -------------" << endl;

    for (int i = 0; i < accountsList.size(); i++)

    {

        accountsList[i]->createMonthlyStatement();

        accountsList[i]->print();

        cout << endl;

    }

    cout << " February: -------------" << endl;

    for (int i = 0; i < accountsList.size(); i++)

    {

        accountsList[i]->createMonthlyStatement();

        accountsList[i]->print();

        cout << endl;

    }

    for (int i = 0; i < accountsList.size(); i++)

    {

         accountsList[i]->withdraw(500);

    }

    cout << " March: -------------" << endl;

    for (int i = 0; i < accountsList.size(); i++)

    {

        accountsList[i]->createMonthlyStatement();

        accountsList[i]->print();

        cout << endl;

    }

    System(“pause”);

    return 0;

}

..............................................................................

Problem 5 on pg 891

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 accounts: one with a monthly service charge, limited check writing, no 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. The penalty for early withdrawal is stiff. Figure 12-22 shows the inheritance hierarchy of these bank accounts.

Figure 12-22

Inheritance hierarchy of banking accounts

Note that the classes bankAccount and checkingAccount are abstract. That is, we cannot instantiate objects of these classes. The other classes in Figure 12-22 are not abstract.

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’s name, account number, and account balance; make deposits; withdraw money; and create monthly statements. So include functions to implement these operations. Some of these functions will be pure virtual.

checkingAccount: A checking account is a bank account. Therefore, it inherits all the properties of a bank account. Because one of the objectives of a checking account is to be able to write checks, include the pure virtual function writeCheck to write a check.

serviceChargeChecking: A service charge checking account is a checking account. Therefore, it inherits all the properties of a checking account. For simplicity, assume that this type of account does not pay any interest, allows the account holder to write a limited number of checks each month, and does not require any minimum balance. Include appropriate named constants, instance variables, and functions in this class.

noServiceChargeChecking: A checking account with no monthly service charge is a checking account. Therefore, it inherits all the properties of a checking account. Furthermore, this type of account pays interest, allows the account holder to write checks, and requires a minimum balance.

highInterestChecking: A checking account with high interest is a checking account with no monthly service charge. Therefore, it inherits all the properties of a no service charge checking account. Furthermore, this type of account pays higher interest and requires a higher minimum balance than the no service charge checking account.

savingsAccount: A savings account is a bank account. Therefore, it inherits all the properties of a bank account. Furthermore, a savings account also pays interest.

highInterestSavings: A high-interest savings account is a savings account. Therefore, it inherits all the properties of a savings account. It also requires a minimum balance.

certificateOfDeposit: A certificate of deposit account is a bank account. Therefore, it inherits all the properties of a bank account. In addition, it has instance variables to store the number of CD maturity months, interest rate, and the current CD month.

Write the definitions of the classes described in this programming exercise and a program to test your classes.

Explanation / Answer

#ifndef BANKACCOUNT_H
#define BANKACCOUNT_H

#include <iostream>

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 */


#include "BankAccount.h"
#include <iostream>
#include <sstream>
#include <iomanip>

using namespace std;

unsigned int BankAccount::nextAccountNumber = 1;


BankAccount::BankAccount(string name, double initialBalance)
{
stringstream output;

this->name = name;
balance = initialBalance;
accountNumber = nextAccountNumber++;
output << setw(60) << left << "Transaction" << setw(10) << "Amount" << " " << "Balance" << endl;
statementString = output.str();
addStatementLine("Initial Deposit", initialBalance);
}

string BankAccount::getName()
{
return name;
}

unsigned int BankAccount::getAccountNumber()
{
return accountNumber;
}

double BankAccount::getBalance()
{
return balance;
}

void BankAccount::addStatementLine(string statement, double amount)
{
stringstream output;

output << setw(60) << left << statement << setw(10) << amount << " " << getBalance() << endl;
//.append(statement);
statementString.append(output.str());
}

void BankAccount::deposit(double amount)
{
deposit(amount, "Deposit");
}

void BankAccount::deposit(double amount, string statement)
{
balance += amount;
addStatementLine(statement, amount);
}

void BankAccount::withdraw(double amount)
{
withdraw(amount, "Withdrawal");
}

void BankAccount::withdraw(double amount, string statement)
{
if (balance >= amount)
{
balance -= amount;
addStatementLine(statement, amount);
}
else
{
addStatementLine(statement.append(" Overdraft"), amount);
}
}

string BankAccount::getStatementString()
{
return statementString;
}

#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 */


#include "CertificateOfDeposit.h"

CertificateOfDeposit::CertificateOfDeposit(string name, double initialBalance, int maturityMonths) : BankAccount(name, initialBalance)
{
this->maturityMonths = maturityMonths;
interestRate = 0.05;
currentCDMonth = 0;
withdrawalPenaltyMonths = 3;
}

CertificateOfDeposit::CertificateOfDeposit(string name, double initialBalance) : BankAccount(name, initialBalance)
{
maturityMonths = 6;
interestRate = 0.05;
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;
}

#ifndef HIGHINTERESTCHECKING_H
#define HIGHINTERESTCHECKING_H

#include "NoServiceChargeChecking.h"

#include <iostream>

using namespace std;

class HighInterestChecking : public NoServiceChargeChecking {
public:
HighInterestChecking(string name, double initialBalance);
void printStatement();
private:
};

#endif /* HIGHINTERESTCHECKING_H */

#include "HighInterestChecking.h"

HighInterestChecking::HighInterestChecking(string name, double initialBalance) : NoServiceChargeChecking(name, initialBalance, 5000, 0.05)
{

}

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;
}

  
#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 */

#include "HighInterestSavings.h"


HighInterestSavings::HighInterestSavings(string name, double initialBalance) : SavingsAccount(name, initialBalance, 0.05)
{
minimumBalance = 2500;
}

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;
}

#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 */

#include "NoServiceChargeChecking.h"
#include <iostream>
#include <iomanip>

NoServiceChargeChecking::NoServiceChargeChecking(string name, double initialBalance) : checkingAccount(name, initialBalance)
{
minimumBalance = 1000;
this->interestRate = 0.02;
}

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;
}

#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 */


#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 = 5;
static const int SERVICE_CHARGE = 10;
};

#endif /* SERVICECHARGECHECKING_H */


#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;
}

source : http://www.cplusplus.com/forum/general/207659/