Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a class to keep track of a balance in a bank account with a varying annual

ID: 3664765 • Letter: W

Question

Write a class to keep track of a balance in a bank account with a varying annual interest rate. The constructor will set both the balance and the annual interest rate to some initial values (with defaults of zero). The class should have member functions to change or retrieve the current balance or interest rate. There should also be functions to make a deposit (add to the balance) or a withdrawal (subtract from the balance). Finally, there should be a function that adds interest to the balance at the current interest rate. This function should have a parameter indicating how many years’ worth of interest are to be added (for example, 0.5 years indicates that the account should have six months’ interest added). Use the class as part of an interactive program that allows the user to determine how long an initial balance will take to grow to a given value. The program should allow the user to specify the initial balance, the interest rate, and whether there are additional yearly deposits. In C++ please

Explanation / Answer

class BankAccount
{
private:
double Balance;
double InterestRate;

public:
BankAccount();
BankAccount(double B, double IR){Balance=B; InterestRate=IR;}


void setB(double newB);
double getB() const;
void setIR(double IR);
double getIR() const;
void Deposit(double amount);
void Withdraw(double amount);
void addInterest(int years);
double addInterest();



};





BankAccount::BankAccount()

{
Balance=0;
InterestRate=0;
}


void BankAccount::setB(double newBalance)
{
Balance = newBalance;
}

void BankAccount::setIR(double newInterestRate)
{
InterestRate = newInterestRate;
}

double BankAccount::getB() const
{
return Balance;
}
double BankAccount::getIR() const
{
return InterestRate;
}

void BankAccount::Deposit(double amount)
{
Balance = Balance + amount;
}

void BankAccount::Withdraw(double amount)
{
Balance = Balance - amount;
}




#include <iostream>
#include <string.h>
#include <stdio.h>
#include <math.h>
using namespace std;

int main ()

{
int year;
double getB;
double getIR;
double B = 0;
double IR =0;
double IRate;
double TV=0;


BankAccount Checking;


cout<<"Welcome to your BankAccount"<<endl;
cout<<" what is your initial Balance? " <<Checking.getB()<<endl;
cin>> B;

cout<<" what is your initial Interest Rate? " <<Checking.getIR()<<endl;
cin>> IR;

cout<<" what is your target Value?"<<endl;
cin >>TV;


{

year = ((TV/B-1)/IR);
return year;
}

cout << "Your initial account will take" <<year>> "to grow to get interest" << endl;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote