Question

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 from the Account and ensure that the debit amount does not exceed the Accounts balance. Member function getBalance should return the current balance Derived class SavingsAccount should inherit the functionality of an Account, but also include a data member of type double indicating the interest rate (percentage) assigned to the Account. SavingsAccounts constructor should receive the initial balance, as well as an initial value for the SavingsAccounts interest rate. SavingsAccount should provide a public member function calculatelnterest that retums a double indicating the amount of interest eamed 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.] Part 1: Class Definition Implement the class definition for class Account and SavingsAccount in the files called Account h and SavingsAccount.h. The class definition should contain only the prototypes of the member functions and double members. Part 2.1: Member-function definition Implement the member-function definition of classes in the files calle Account.cpp and SavingsAccount.cpp. This cpp file contains the actual mplementation of the member functions of the two classes Part 2.2: Test program Write a program that tests your class Account and SavingAcounts. Call your file testAccount.cpp. This program should 1. Instantiate an object of class SavingAccounts and Accounts 2. Add some credit to both objects. 3. Add some credit to both objects 4. Withdraw some amount for both objects. 5. Print the interest for the saving account object. 6. Print the current balance of each account.


Please show it in C++. Thank you!

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

/*Account.h */
#include<iostream>

using namespace std;

class Account{
   private:
      double account_balance;
   public:
      Account(double d){
         account_balance = d;
      }
      void debit(double a);
      void credit(double a);
      double getCurrentBalance();
     
};

/* Account.cpp */
#include<iostream>

using namespace std;

#include "Account.h"


void Account::debit(double a){
     if (a <= account_balance){
            account_balance = account_balance - a;
     }
}

void Account::credit(double a){
     account_balance = account_balance + a;
  
}

double Account::getCurrentBalance(){
      return account_balance;
}

/* SavingsAccount.h */

#include<iostream>

using namespace std;

#include "Account.h"

class SavingsAccount: public Account{
   private:
      double intrestRate;
   public:
      SavingsAccount(double d, double intr): Account(d){
         intrestRate = intr;
      }
      double calculateIntrest();
     
};

#include<iostream>
#include "SavingsAccount.h"

using namespace std;

double SavingsAccount::calculateIntrest(){
    return intrestRate/100.0 * getCurrentBalance();
}

/*testmain.cpp */

#include<iostream>
#include "SavingsAccount.h"

int main(){

    Account a(100);
    SavingsAccount sa(200, 2.3);
    a.debit(45);
    a.credit(100);
    cout << "Balance:" << a.getCurrentBalance() << endl;

    cout << "Intrest amount:" << sa.calculateIntrest() << endl;
   
    return 0;
}

Add a comment
Know the answer?
Add Answer to:
Please show it in C++. Thank you! Problem Definition Create an inheritance hierarchy containing base class...
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
  • 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...

  • 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...

  • 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...

  • For this week's assignment , please create an application following directions in the attached document.(windows form...

    For this week's assignment , please create an application following directions in the attached document.(windows form application) Create a base class named Account and derived classes named SavingsAccount and CheckingAccount that inherit from class Account. Base class Account should include one private instance variable of type decimal to represent the account balance. The class should provide a constructor that receives an initial balance and uses it to initialize the instance variable with a public property. The property should validate the...

  • 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...

  • 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...

  • In C++: Define a class named Account that stores a balance (monetary amount). The class should...

    In C++: Define a class named Account that stores a balance (monetary amount). The class should have a private double variable balance. Add one accessor getBalance function that returns the balance and one deposit function that increases the balance by a given double amount. Then subclass Account with a SavingsAccount class. This class should have a private double variable interest. Add an addInterest function that increases the balance (from the superclass Account) according to the interest. Demonstrate the use in...

  • C++ Help. PLEASE include detailed comments and explanations. PLEASE follow the drections exactly. Thank you. Define...

    C++ Help. PLEASE include detailed comments and explanations. PLEASE follow the drections exactly. Thank you. Define a class with the name BankAccount and the following members: Data Members: accountBalance: balance held in the account interestRate: annual interest rate. accountID: unique 3 digit account number assigned to each BankAccount object. Use a static data member to generate this unique account number for each BankAccount count: A static data member to track the count of the number of BankAccount objects created. Member...

  • (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,...

  • TASK 1 Create a new class called CheckingAccount that extends BankAccount. It should contain a static...

    TASK 1 Create a new class called CheckingAccount that extends BankAccount. It should contain a static constant FEE that represents the cost of clearing onecheck. Set it equal to 15 cents. Write a constructor that takes a name and an initial amount as parameters. Itshould call the constructor for the superclass. It should initializeaccountNumber to be the current value in accountNumber concatenatedwith -10 (All checking accounts at this bank are identified by the extension -10). There can be only one...

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