Question

In: Computer Science

C++ programming------------ Enhance the Account class to compute the interest on the current balance. An account...

C++ programming------------

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(Account.h) and a cpp file (Account.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 as well as comments to understand your code.

Account.h file given**

#ifndef Account_h

#define Account_h

#include <iostream>

using namespace std;

class Account

{

public:

double amount;

Account(double a);

void deposit(double a);

void withdraw(double a);

double get_balance();

};

#endif

Account.cpp file given**

#include "Account.h"

#include <iostream>

using namespace std;

//creates account and sets amount with users account set-up value

Account::Account(double a){

amount = a;

}

void Account::deposit(double a){

if(a < 0){

return;

}

//adds to amount in account once deposited

amount += a;

}

void Account::withdraw(double a){

if(amount-a < 0){

return;

}

//decreases amount in account once withdrawn

amount -= a;

}

//returns balance of account

double Account::get_balance(){

return amount;

}

int main()

{

Account my_account(100); // Set up my account with $100

my_account.deposit(50);

my_account.withdraw(175); // Penalty of $20 will apply

my_account.withdraw(25);

  

cout << "Account balance: " << my_account.get_balance() << "\n";

  

my_account.withdraw(my_account.get_balance()); // withdraw all

cout << "Account balance: " << my_account.get_balance() << "\n";

  

return 0;

}

Solutions

Expert Solution

We know the formula for compound interest

where,

A = amount of money accumulated after n years, including interest.

P = principal amount (the initial amount you borrow or deposit)

r = annual rate of interest (as a decimal)

n = number of times the interest is compounded per year

t = number of years the amount is deposited or borrowed for.

According to question, we have to double the initial investment i.e.,

A = 2P

and n = 12 because it is compounded monthly

therefore,

Taking log both side

We can see that final t value depends on r value not on P value.

Below is the complete code:

Account.h

#include <iostream>

using namespace std;
class Account
{
public:


double amount;
Account(double a);
void deposit(double a);
void withdraw(double a);
double get_balance();
int double_investment(double P, double r);   //function is added

};

Account.cpp

#include "Account.h"
#include <iostream>
#include<math.h>
using namespace std;

//creates account and sets amount with users account set-up value
Account::Account(double a){


amount = a;


}

void Account::deposit(double a){


if(a < 0){
return;
}

//adds to amount in account once deposited
amount += a;
}

void Account::withdraw(double a){


if(amount-a < 0){
return;
}
//decreases amount in account once withdrawn
amount -= a;
}

//returns balance of account

double Account::get_balance(){

return amount;

}

//calculate months required to double the investment
int Account::double_investment(double P, double r)
{


   //convert percentage of rate into decimal
   r = r/100;


   //implement formula for time which was derived in the description
   //i.e., t = log(2)/(12*log(1+(r/12)))
   double t = log10(2)/(12*log10(1+(r/12)));

   //store total month
   int month=0;

   month = t*12;

   return month;

}

int main()

{

   Account my_account(100); // Set up my account with $10

    my_account.deposit(50);

   my_account.withdraw(175); // Penalty of $20 will apply

   my_account.withdraw(25);

  

   cout << "Account balance: " << my_account.get_balance() << "\n";

  

   my_account.withdraw(my_account.get_balance()); // withdraw all

   cout << "Account balance: " << my_account.get_balance() << "\n";


   //Take inital amount and rate as input from user
   int P, r;
   cout<<"Enter initial investment :";
   cin>>P;
   cout<<"Enter annual rate in percent :";
   cin>>r;
  
   //call funtion
   cout<<"Total month required to double the investment = "<<my_account.double_investment(P,r)<<"\n";

   return 0;

}


Related Solutions

*********C++ Program************ Enhance the Account class to compute the interest on the current balance. An account...
*********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...
Question: Java Programming. ** Modify Current Program. Current Program class Account{       //instance variables   ...
Question: Java Programming. ** Modify Current Program. Current Program class Account{       //instance variables    private long accountNumber;    private String firstName;    private String lastName;    private double balance;       //constructor    public Account(long accountNumber, String firstName, String lastName, double balance) {        this.accountNumber = accountNumber;        this.firstName = firstName;        this.lastName = lastName;        this.balance = balance;    }    //all getters and setters    public long getAccountNumber() {        return...
In the two-period model reviewed in class, both the Current Account and the Trade Balance in...
In the two-period model reviewed in class, both the Current Account and the Trade Balance in period 1 worsen (i.e., decrease) with an anticipated increase in the endowment of period two (ΔQ1=0 and ΔQ2>0)'' Use equations of the optimal allocation of consumption in periods 1 and 2, the trade balance in period 1 and the current account in period 1 to support your answer. No credit without explanation. For simplicity, assume the following lifetime utility function: U(C1,C2)= ln(C1) +β ln(C2)...
Write a C++ program (The Account Class) Design a class named Account that contains (keep the...
Write a C++ program (The Account Class) Design a class named Account that contains (keep the data fields private): a) An int data field named id for the account. b) A double data field named balance for the account. c) A double data field named annualInterestRate that stores the current interest rate. d) A no-arg constructor that creates a default account with id 0, balance 0, and annualInterestRate 0. e) The accessor and mutator functions for id, balance, and annualInterestRate....
C# Programming (Class Registration class) Add a Schedule property to the Person class. Add a new...
C# Programming (Class Registration class) Add a Schedule property to the Person class. Add a new behavior as well: add(Section s) this behavior will add a section to the Person’s schedule. The Person’s display() function will also need to be modified to display() the Person’s Schedule. Schedule class has Properties: An array of Sections and a Count. Constructors: only a default constructor is needed. Behaviors: add() and display(). This is my schedule class class Schedule     {         private int...
Write a C program that calculates a student grade in the C Programming Class. Ask the...
Write a C program that calculates a student grade in the C Programming Class. Ask the user to enter the grades for each one of the assignments completed in class: Quiz #1 - 25 points Quiz #2 - 50 points Quiz #3 - 30 points Project #1 - 100 points Project #2 - 100 points Final Test - 100 points The total of the quizzes count for a 30% of the total grade, the total of the projects counts for...
c++ The above Account class was created to model a bank account. An account has the...
c++ The above Account class was created to model a bank account. An account has the properties (keep the properties private) account number, balance, and annual interest rate, date created, and functions to deposit and withdraw. Create two derived classes for checking and saving accounts. A checking account has an overdraft limit, but a savings account cannot be overdrawn. Define a constant virtual toString() function in the Account class and override it in the derived classes to return the account...
(In C++) Bank Account Program Create an Account Class Create a Menu Class Create a main()...
(In C++) Bank Account Program Create an Account Class Create a Menu Class Create a main() function to coordinate the execution of the program. We will need methods: Method for Depositing values into the account. What type of method will it be? Method for Withdrawing values from the account. What type of method will it be? Method to output the balance of the account. What type of method will it be? Method that will output all deposits made to the...
C++ Programming 1) What is the feature that makes a base class an abstract class? 2)...
C++ Programming 1) What is the feature that makes a base class an abstract class? 2) When designing a class hierarchy involving classes A and B, what are the two questions that must be asked to determine whether class B should be derived from class A?
c++ programming 1.1 Class definition Define a class bankAccount to implement the basic properties of a...
c++ programming 1.1 Class definition Define a class bankAccount to implement the basic properties of a bank account. An object of this class should store the following data:  Account holder’s name (string)  Account number (int)  Account type (string, check/savings/business)  Balance (double)  Interest rate (double) – store interest rate as a decimal number.  Add appropriate member functions to manipulate an object. Use a static member in the class to automatically assign account numbers. 1.2 Implement...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT