Question

(C++) How do I develop a polymorphic banking program using an already existing Bank-Account hierarchy? For each account...

(C++)

How do I develop a polymorphic banking program using an already existing Bank-Account hierarchy? For each account in the vector, allow the user to specify an amount of money to withdraw from the Bank-Account using member function debit and an amount of money to deposit into the Bank-Account using member function credit. As you process each Bank-Account, determine its type. If a Bank-Account is a Savings, 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, print the updated account balance obtained by invoking base-class member function getBalance.

Here is the already existing code:

#include<iostream>

using namespace std;

//Define base class Bank_Account

class Bank_Account

{

protected:

       double balance; //data member to hold balance

public:

       //Parameterized constructor for initial balance

       Bank_Account(double bal)

       {

              //Check validity of balance

              if (bal >= 0)

              {

                     balance = bal;

              }

              else if (bal < 0)

              {

                     balance = 0;

                     cout << "\nInitial balance was invalid";

              }

       }

       //member function to credit the amount to account balance

       void credit(double amount)

       {

              balance = balance + amount;

       }

       //member function to debit amount from account balance

       bool debit(double amount)

       {

              //check if amount is valid

              if (amount > balance)

              {

                     cout << "\nThe balance is less than the debit amount";

                     return false;

              }

              else

              {

                     balance = balance - amount;

                     return true;

              }

       }

       //member function to fetch the acccount balance

       double getBalance()

       {

              return balance;

       }

};

//defined Savings_Account class with extending Bank_Account

class Savings_Account : public Bank_Account

{

protected:

       double interestRate;

public:

       //Parameterized constructor of Savings_Account which calls Parameterized constructor of Bank_Account with passing balance

       Savings_Account(double bal, double rate) :Bank_Account(bal)

       {

              interestRate = rate;

       }

       //member function to calculate interest rate  

       double calculateInterest()

       {

              return balance * interestRate;

       }

};

class Checking_Account : public Bank_Account

{

protected:

       double fee;

public:

       //Parameterized constructor of Checking_Account which calls Parameterized constructor of Bank_Account with passing balance

       Checking_Account(double bal, double feeTrans) :Bank_Account(bal)

       {

              fee = feeTrans;

       }

       //member function to apply transaction fee on crediting the amount

       void credit(double amount)

       {

              Bank_Account::credit(amount);

              balance = balance - fee;

       }

       //member function to apply transaction fee on debiting the amount

       void debit(double amount)

       {

              bool withdrawn = Bank_Account::debit(amount);

              if (withdrawn)

              {

                     balance = balance - fee;

              }

       }

};

int main()

{

       Bank_Account bankObj(200);

       Savings_Account savObj(300, 0.04);

       Checking_Account checkObj(400, 5.0);

       cout << endl << "Balance in Bank-Account: " << bankObj.getBalance();

       cout << endl << "Balance in Savings-Account: " << savObj.getBalance();

       cout << endl << "Balance in Checking-Account: " << checkObj.getBalance();

       bankObj.debit(50);

       savObj.debit(100);

       checkObj.debit(100);

       cout << endl << endl << "Balance after debiting amount from all three account";

       cout << endl << "Balance in Bank-Account: " << bankObj.getBalance();

       cout << endl << "Balance in Savings-Account: " << savObj.getBalance();

       cout << endl << "Balance in Checking-Account: " << checkObj.getBalance();

       bankObj.credit(100);

       savObj.credit(200);

       checkObj.credit(250);

       cout << endl << endl << "Balance after crediting amount from all three account";

       cout << endl << "Balance in Bank-Account: " << bankObj.getBalance();

       cout << endl << "Balance in Savings-Account: " << savObj.getBalance();

       cout << endl << "Balance in Checking-Account: " << checkObj.getBalance();

       double interestAmoutn = savObj.calculateInterest();

       savObj.credit(interestAmoutn);

       cout << endl << endl << "After adding interest, savings account have balance: " << savObj.getBalance();

       return 0;

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please go through instructions and comments carefully thank you

Add the following function in Savings_Account classs (at line 128 in code ) such that overwrites the parent class function.

virtual void credit(double amount)

{
//Calling parent functions from the derived function.
Bank_Account::credit(amount); //deposited balance
Bank_Account::credit(calculateInterest()); //deposited interest

}

virtual - keyword used to overwrite function

In the output credit is function used where balance deposited is 200 and including interest it is displayed as 416

Output for reference

128 //Functuon polymorpmsm techn飞que. us飞ng virtual void credit(double amount) 129 130 131 //Calling parent functions from th

Add a comment
Know the answer?
Add Answer to:
(C++) How do I develop a polymorphic banking program using an already existing Bank-Account hierarchy? For each account...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • MAIN OBJECTIVE       Develop a polymorphic banking program using the Account hierarchy created (below). C++ Capture...

    MAIN OBJECTIVE       Develop a polymorphic banking program using the Account hierarchy created (below). C++ Capture an output. polymorphism. Write an application that creates a vector of Account pointers to two SavingsAccount and two CheckingAccountobjects. For each Account in the vector, allow the user to specify an amount of money to withdraw from the Account using member function debit and an amount of money to deposit into the Account using member function credit. As you process each Account, determine its...

  • Introduction Extend the inheritance hierarchy from the previous project by changing the classes to template classes....

    Introduction Extend the inheritance hierarchy from the previous project by changing the classes to template classes. Do not worry about rounding in classes that are instantiated as integer classes, you may just use the default rounding. You will add an additional data member, method, and bank account type that inherits SavingsAc-count ("CD", or certicate of deposit). Deliverables A driver program (driver.cpp) An implementation of Account class (account.h) An implementation of SavingsAccount (savingsaccount.h) An implementation of CheckingAccount (checkingaccount.h) An implementation of...

  • In C++ Create an inheritance hierarchy that a bank might use to represent customers’ bank accounts. All customers at this bank can deposit (i.e., credit) money into their accounts and withdraw (i.e.,...

    In C++ Create an inheritance hierarchy that a bank might use to represent customers’ bank accounts. All customers at this bank can deposit (i.e., credit) money into their accounts and withdraw (i.e., debit) money from their accounts. More specific types of accounts also exist. 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). Create an inheritance hierarchy containing base class Account and derived...

  • Should be in C# Create an inheritance hierarchy that a bank might use to represent customers’...

    Should be in C# Create an inheritance hierarchy that a bank might use to represent customers’ bank accounts. All customers at this back can deposit (i.e. credit) money into their accounts and withdraw (i.e. debit) money from their accounts. More specific types of accounts also exist. Savings accounts, for instance, earn interest on the money they hold. Checking accounts, on the other hand, charge a fee per transaction. Create base class Account and derived classes SavingsAccount and CheckingAccount that inherit...

  • Im having trouble with this C++ program. Lab 10/object/test files provided LAB 10 1 //Savings.cpp - displays the account balance at 2 //the end of 1 through 3 years 3 //Created/revised by <your nam...

    Im having trouble with this C++ program. Lab 10/object/test files provided LAB 10 1 //Savings.cpp - displays the account balance at 2 //the end of 1 through 3 years 3 //Created/revised by <your name> on <current date> 4 5 #include <iostream> 6 #include <iomanip> 7 #include <cmath> 8 using namespace std; 9 10 //function prototype 11 double getBalance(int amount, double rate, int y); 12 13 int main() 14 { 15 int deposit = 0; 16 double interestRate = 0.0; 17...

  • Please show it in C++. Thank you! Problem Definition Create an inheritance hierarchy containing base class...

    Please show it in C++. Thank you! Problem Definition Create an inheritance hierarchy containing base class Account and derived class Savings-Account. Base class Account should include one data member of type double to represent the account balance. The class should provide a constructor that receives an initial baiance and uses it to initialize the data member. The class should provide three member functions. Member function credit should add an amount to the current balance. Member function debit should withdraw money...

  • question

    : Implement the following given scenario in C++ a. Create an inheritance hierarchy by writing the source code, containing base class BankAccount and derived classes SavingsAccount and CheckingAccount that inherit from class BankAccount. b. Implement Polymorphism where required to achieve the polymorphic behavior. c. Multiple constructors be defined for initializing the account of a user. d. The class should provide four member functions. i. Member function Credit should add an amount to the current balance. ii. Member function Debit should...

  • NETBEANS JAVA BANK PROGRAM (TAKE SCREENSHOTS FROM NETBEANS INCLUDING OUTPUT PLEASE) Display the accounts for the...

    NETBEANS JAVA BANK PROGRAM (TAKE SCREENSHOTS FROM NETBEANS INCLUDING OUTPUT PLEASE) Display the accounts for the current displayed customer PLEASEEEEEEEEEE package bankexample; import java.util.UUID; public class Customer { private UUID id; private String email; private String password; private String firstName; private String lastName;    public Customer(String firstName, String lastName, String email, String password) { this.id = UUID.randomUUID(); this.firstName = firstName; this.lastName = lastName; this.email = email; this.password = password; } public String getFirstName() { return firstName; } public void setFirstName(String...

  • C++ Check Book Program I need to have a checkbook program that uses the following items....

    C++ Check Book Program I need to have a checkbook program that uses the following items. My code that I have appears below. 1) Math operations using built-in math functions 2) Class type in a separate .h file with member functions (accessor functions, get, set, show, display find, etc). There needs to be an overloaded function base/derived classes or a template. 3) Binary File #include <iostream> using namespace std; int main() {     double checking,savings;     cout<<"Enter the initial checking...

  •       C++ -- Vector of Bank Accounts (15 pts) Please help! :( Use csegrid or Clion for...

          C++ -- Vector of Bank Accounts (15 pts) Please help! :( Use csegrid or Clion for this part Add on to the lab12a solution(THIS IS PROVIDED BELOW). You will add an overload operator function to the operator << and a sort function (in functions.h and functions.cpp)    Print out the customer’s name, address, account number and balance using whatever formatting you would like    Sort on account balance (hint: you can overload the < operator and use sort from the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT