Write a program for deposits accumulate a specific amount.
Question
Typically everyone saves money periodically for retirement, buying a house, or for some other purpose. a program for deposits If you are saving money for retirement, then the money you put in a retirement is fund tax shelter. And your employer also makes some contribution into your retirement fund. In this exercise, for simplicity, we assume that money is put into an account that pays a fix rate. And money is deposit into the account at the end of the specified period. suppose that a person deposits R dollars m times a year into an account that pays r% interest compound m times a year for t years. Then the total amount accumulated at the end of t years is given by R
For example suppose that you deposit $500. At the end of each month into an account that pays 4.8% interest per year compound monthly for 25 years. Then the total money accumulate into the account is 500[(1+0.048/12)-1]/(0.048/12)=$289,022.42
On the other hand, suppose that you want to accumulate s dollars in t years and would to know how much m times a year, you should deposit into an account that pays r% interest compounded m times a year. The periodic payments is given by the formula
Design a class that used the above formula to determine the total amount accumulated into an account. And the periodic deposits to accumulate a specific amount. Your class should have instance variables to there the periodic deposit, the value of m. The interest rate and the number of years the money will be saved. Add appropriate constructors to initialize instance variables. function to set the values of the instance variables and function to do the necessary calculations and output results.
Summary
In this question, we have to write a program for the deposits to accumulate a specific amount. Where we use the periodic deposit, interest rate, and the number of years. Also, appropriate constructors to initialize instance variables, functions to set the values, functions to retrieve the values, and functions to do necessary calculations. After all the calculations are done deposit money, rate of interest, and the accumulated amount will get printed on the screen.
Explanation
Here we write a program for the deposits in this program we have to take a class name Money. In that class, we have to add the variable’s names such as m, t, and pd. So that there m will stand for how many time in a year the amount get compounded. And t will stand for the time required. And also for each method, there is a setter and getter. Then there are two methods defined as inComplete() and timeCash() for the operations. One Input function is used o take the input from the user to enter the deposit and interest rate. Once all the calculations are done it will get printed on the screen as output.
Code
#include <iostream> using namespace std; #include <cmath> /* to implement the given scenario */ class bank { private: /* instance variables */ double pd,m,t; public: /* constructor */ bank(double p,double m1,double t1){ periodicDeposit=p; m=m1; t=t1; } /* getters */ double getPeriodicDeposit(){ return periodicDeposit; } double getM(){ return m; } double getT(){ return t; } /* setters */ void setPeriodicDeposit(double p){ periodicDeposit=p; } void setM(double m1){ m=m1; } void setT(double t1){ t=t1; } /* to get the total amount accumulated */ void inComplete(){ cout<<"Enter the amount to deposit: "; double d,r; cin>>d; cout<<"Enter the rate of interest: "; cin>>r; double total= d*((pow((1+(r/m)), (m*t) )-1)/(r/m)); cout<<"The total amount accumulated = "<<total<<endl<<endl; } /* to display the periodic payment to be done */ void timeCash(){ cout<<"Enter the amount to accumulate: "; double s,r; cin>>s; cout<<"Enter the rate of interest: "; cin>>r; periodicDeposit=((s*(r/m))/(pow((1+(r/m)), (m*t))-1)); cout<<"The Periodic Payment = "<<periodicDeposit<<endl; } }; /* main code */ int main() { bank b(500,12,25); b.inComplete(); b.timeCash(); }
Output
Also read, Make a story like a worker or game of using inheritance.