In: Computer Science
*********C++ Program************
Enhance the Account class to compute the interest on the current
balance. An account has initial balance of $10,000.00, and 6%
percent annual interest is compounded monthly until the investment
is double.
Write a main function to determine the number of months to double
the initial investment. Create function name "double investment"
for this project. Create a menu to allow the user to enter the
initial investment and the annual interest rate. Please create a
header file(bank.h) and a cpp file (bank.cpp). Below is code
provided that needs to be altered to add "double investment"
function. Please include code and output screenshots to show
validation of functionality. Thank you!
#include <iostream>
using namespace std;
//public class
class Account{
public:
//instance variables
double amount;
//creates account and sets amount with users account set-up value
Account(double a){
amount = a;
}
//adds to amount in account once deposited
void deposit(double a){
if(a < 0){
return;
}
amount += a;
}
//decreases amount in account once withdrawn
void withdraw(double a){
if(amount-a < 0){
return;
}
amount -= a;
}
//returns balance of account
double get_balance(){
return amount;
}
};
`Hey,
Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.
//bank.h
#ifndef BANK_H
#define BANK_H
class Account{
public:
//instance variables
double amount;
double rate;
//creates account and sets amount with users account set-up
value
Account(double a,double r);
//adds to amount in account once deposited
void deposit(double a);
//decreases amount in account once withdrawn
void withdraw(double a);
//returns balance of account
double get_balance();
double investment();
};
#endif
//bank.cpp
#include "bank.h"
Account::Account(double a,double r){
amount = a;
rate=r;
}
void Account::deposit(double a){
if(a < 0){
return;
}
amount += a;
}
//decreases amount in account once withdrawn
void Account::withdraw(double a){
if(amount-a < 0){
return;
}
amount -= a;
}
//returns balance of account
double Account::get_balance(){
return amount;
}
double Account::investment()
{
int n=0;
double num=amount;
while(num<2.0*amount)
{
num=(1.0+rate/12.0)*num;
n=n+1;
}
return n;
}
//main.cpp
#include <iostream>
#include "bank.cpp"
using namespace std;
//public class
int main()
{
cout<<"Enter initial investment: ";
double amount;
cin>>amount;
cout<<"Enter percent rate: ";
double rate;
cin>>rate;
Account *p=new Account(amount,rate/100.0);
int n=p->investment();
cout<<"It takes "<<n<<" months to double the
intial investment\n";
return 0;
}
Kindly revert for any queries
Thanks.