ooo T-Mobile 10:09 PM @ 14% ps://moodle.oakland.edL] Write a class BankAccount t
ID: 3869901 • Letter: O
Question
ooo T-Mobile 10:09 PM @ 14% ps://moodle.oakland.edL] Write a class BankAccount 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 (and you should also implement a no-arguments constructor that sets both the balance and the interest rate to zero) The class should have methods to change or retrieve the current balance or interest rate. There should also be methods to make a deposit (add to the balance) or withdrawal (subtract from the balance). Finally, there should be a method that adds interest to the balance at the current interest rate. This function should have a parameter indicating how to be added (For example, 0.5 years indicate 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 it will take 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. many years' worth of interest areExplanation / Answer
#include<iostream>
#include<string>
using namespace std;
class BankAccount {
private:
static int id;
string name;
int acc_no;
double balance;
double rate;
public:
BankAccount(){
acc_no = id+1;
name = "";
rate = 0;
balance = 0;
}
BankAccount(double a, double b, string c){
acc_no = id+1;
name = c;
rate = b;
balance = a;
}
double getBalance(){
return balance;
}
void setBalance(double a){
balance = a;
}
double getIntrest(){
return rate;
}
void setIntrest(double a){
rate = a;
}
void deposit(double a){
balance - balance + a;
}
void withdrawl(double a){
if (balance < a)
cout << "Insufficient balance" << endl;
else {
balance = balance - a;
}
}
void UpdateWithIntrest(double b){ // b is in years
int n = 12 * b;
double monthly_rate = rate/12;
for (int i = 0; i<n; i++){
balance = balance + (monthly_rate/100)*balance;
}
}
void HowLong(){
double bal,intr,deposit,value;
cout << "Enter initial balance :";
cin >> bal;
cout << "Enter annual intrest :";
cin >> intr;
cout << "Enter yearly deposit :";
cin >> deposit;
cout << "Enter value to which balance should reach :";
cin >> value;
if (value > bal){
int count = 0;
while (bal < value){
bal = bal + (intr/1200)*bal;
if (count == 11){
bal = bal + deposit;
}
count++;
}
cout << "It will take " << count << " months. ";
}
else {
cout << "Incorrect expected value" << endl;
}
}
};
int BankAccount::id = 0;
int main(){
BankAccount at(100,5,"name1");
BankAccount at1;
at1.HowLong();
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.