Waiting for answer This question has not been answered yet. You can hire a professional tutor to get the answer.

QUESTION

I need to Develop a polymorphic banking program using the Bank-Account hierarchy created in my previous Assignment.

I need to Develop a polymorphic banking program using the Bank-Account hierarchy created in my previous Assignment. For each account in the vector, I have to allow the user to specify an amount of money to withdraw from the BankAccount using member function debit and an amount of money to deposit into the Bank-Account using member function credit. As I process each Bank-Account, I have to determine its type. If a Bank-Account is a Savings, I need to calculate the amount of interest owed to the Bank-Account using member function calculateInterest, then add the interest to the account balance using member function credit. After processing an account, I need to print the updated account balance obtained by invoking base-class member function getBalance.

This is my previous assignment below:

#include<iostream>

using namespace std;

class Account

{

private :

double balance;

public:

Account(double bal)

{

if(bal>=0)

balance=bal;

else{

balance=0;

cout<<"You entered an invalid value!"<<endl;

}

}

void credit(double cr)

{

balance=balance+cr;

}

void debit(double db)

{

if(db>balance)

cout<<"Debit amount exceeded account balance"<<endl;

else

balance=balance-db;

}

double getBalance()

{

return balance;

}

};

class SavingsAccount :public Account{

private:

double interestRate;

public:

SavingsAccount(double bal,double rate): Account(bal)

{

interestRate=rate;

}

double calculateInterest()

{

return (interestRate*getBalance())/100;

}

};

class CheckingAccount :public Account{

private :

double feeCharged;

public:

CheckingAccount(double bal,double fee) : Account(bal)

{

feeCharged=fee;

}

void credit(double cr)

{

cr=cr-feeCharged;

Account::credit(cr);

}

void debit(double db)

{

db+=feeCharged;

Account::debit(db);

}

};

int main()

{

SavingsAccount *sa=new SavingsAccount(700,2);

cout<<"nThe Saving Account : Bal. = 700 and Int. rate = 2n"<<endl;

cout<<"Interest RS : "<<sa->calculateInterest()<<endl;

cout<<"Adding Credit 115.7 "<<endl;

sa->credit(115.7);

cout<<"BALANCE : "<<sa->getBalance()<<endl;

cout<<"Debit 25.3 "<<endl;

sa->debit(10.5);

cout<<"BALANCE : "<<sa->getBalance()<<endl;

cout<<"nThe checking Account Bal. = 350 and fee=35n"<<endl;

CheckingAccount *ca=new CheckingAccount(350,35);

cout<<"BALANCE : "<<ca->getBalance()<<endl;

cout<<"CREDIT 50" <<endl;

ca->credit(50);

cout<<"BALANCE : "<<ca->getBalance()<<endl;

return 0;

}

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question