In: Computer Science
Building a console application in C++ and add features for specific types of accounts that exist in a real Bank. Savings accounts, for instance, earn interest on the money they hold. Checking accounts, on the other hand, charge a fee per transaction (i.e., credit or debit).
a. Create an Inheritance hierarchy using base class Account and derived classes Savings-Account and CheckingAccount.
b. Derived class SavingsAccount should inherit the functionality of an Account, but also include a data member indicating the interest rate (percentage) assigned to the Account. SavingsAccount’s constructor should receive the initial balance, as well as an initial value for the SavingsAccount’s interest rate. SavingsAccount should provide a public member function CalculateInterest that returns a double indicating the amount of interest earned by an account. Member function CalculateInterest should determine this amount by multiplying the interest rate by the account balance. [Note: SavingsAccount should inherit member functions credit and debit as is without redefining them.]
c. Derived class Checking Account should inherit from base class Account and include an additional data member that represents the fee charged per transaction. Checking Account’s constructor should receive the initial balance, as well as a parameter indicating a fee amount. Class Checking Account should redefine member function debit so that it will subtract the fee from the account balance whenever the transaction is performed successfully. Checking Account’s debit and check balance functions should invoke the base-class Account version to perform the updates to an account balance. Checking Account’s debit function should charge a fee only if money is actually withdrawn (i.e., the debit amount does not exceed the account balance).
[Hint: Define Account’s debit function so that it returns a bool indicating whether money was withdrawn. Then use the return value to determine whether a fee should be charged.]
d. After defining the classes in this hierarchy, write a program that creates objects of each class and tests their member functions. Add interest to the Savings Account object by first invoking its calculate Interest function, then passing the returned interest amount to the object’s credit function.
Can someone help with this please? Include comments lines
Given below is the required C++ program-
#include <iostream>
using namespace std;
class account
{
public:
double bal; // variables defined
void credit(int amt) // debit function defined
{
bal=bal-amt;
}
void debit(int amt) // credit function defined
{
bal=bal+amt;
}
};
class saving_account : public account
{
public:
int irate;
saving_account(double r,int b)
{
irate=r;
bal=b;
}
double calculateinterest() // calculate interest defined
{
return bal*(irate/100.0);
}
};
class checking_account : public account
{
public:
int irate;
int fees;
checking_account(double r,int b,int fee)
{
irate=r;
bal=b;
fees=fee;
}
double calculateinterest() // calculate interest defined
{
return bal*(irate/100.0);
}
void credit(int amt)
{
bal=(bal-amt)-fees;
};
void debit(int amt)
{
bal=(bal+amt)-fees;
}
};
int main()
{
saving_account obj(10.0,23400); // object defined
checking_account obj1(10.0,24000,); // object defined
cout<<"Interest calculated for savings"<<obj.calculateinterest()<<endl;
cout<<"Interest calculated for checking"<<obj1.calculateinterest()<<endl;
}
If this answer is helpful please give it a thumbs up......