Create an inheritance hierarchy containing base class Account and derived class
ID: 3824373 • Letter: C
Question
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 balance 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 Account's balance. Member function getBalance should return the current balance. Derived class Savings Account 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. Savings Account'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 calculatelnterest should determine this amount by multiplying the interest rate by the account balance.Explanation / Answer
#include <iostream>
using namespace std;
//code
class Account
{
public:
double balance;
Account(double bal)
{
bal=balance;
}
double credit(double amt)
{
balance=balance+amt;
}
double debit(double amt)
{
if(amt<=balance)
{
balance=balance-amt;
}
else
{
cout<<"insuffiecient balance";
}
}
double getBalance()
{
cout<<"Current balance is: "<<balance;
}
};
class SavingsAccount : public Account
{
public:
double rate;
SavingsAccount(double bal,double rt)
{
bal=balance;
rt=rate;
}
double calculateInterest(double interest)
{
interest=balance+(balance*rate)/100;
balance=balance+interest;
cout<<balance;
}
};
int main()
{
SavingsAccount sb;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.