Question

In: Computer Science

Description Typically, most everyone saves money periodically for retirement. In this exercise, for simplicity, we assume...

Description

Typically, most everyone saves money periodically for retirement. In this exercise, for simplicity, we assume that the money is put into an account that pays a fixed interest rate, and money is deposited into the account at the end of the specified period. Suppose the person saving for retirement deposits D dollars m times per year. The account pays r% compound interest rate. And the person will be saving for a period of t time given in years. For example, the person might save D = $500 every m = 12 months. The retirement account pays 4.8% compound interest per year. And the person as t = 25 years to save for retirement. The total amount of savings S accumulated at the end of this time is given by the formula

S = D h (1 + r/m) mt − 1 r/m i

For example, suppose that you deposit $500 at the end of each month (m = 12). The account pays 4.8% interest per year compounded monthly for t = 25 years. Then the total money accumulated into this account is

500[(1 + 0.048/12)300 − 1]/(0.048/12) = 289, 022.42

On the other hand, suppose that you want to accumulate S dollars in savings, and would like to know how much money you should deposit D each deposit period. The periodic payment you need to reach this goal S is given by the formula

D = S(r/m) (1 + r/m)mt − 1

Design a class that uses the above formulas to calculate retirement savings and to help plan retirement goals. Your class should have private instance variables (all of type double) to hold D the deposit amount, m the number of deposit periods per year, r the interest rate and t the time in years the plan will save for retirement. In the class style guidelines, I discourage using single letter variable names usually when writing code. However when we are directly implementing a formula in an engineering or scientific calculation, it is often clearer to use the variable names directly as given in the formula.

For this assignment you need to perform the following tasks.

1. Create a class named RetirementAccount. The class should have a class constructor that takes the 4 variables, D, m, r, t as parameters.

2. Create a default class constructor as well. This constructor can set all of the private member variable values to 1.0.

3. You must have getter and setter methods for all 4 of the member variables of the class. The methods will be named set_D(), set_m(), set_r(), set_t() and get_D(), get_m(), get_r(), get_t(), respectively.

4. Create a member function named tostring(). This function will not take any parameters as input. It returns a string that represents the values/settings of the RetirementAccount class. See the example output below for the format of the string to be returned.

5. Create a member function named calculateRetirementSavings(). This function should implement the first formula to calculate the total amount of savings S the account will generate. This function has no parameters as inputs, and it returns a double amount (the amount of savings) as its result.

6. Create a member function named planRetirementDeposits(). This function takes a double parameters S as input, which is the savings goal you wish to achieve. This function should implement the second equation given above. The function returns a double result, D which is the amount of money that should be deposited each period to meet the savings goal S.


Its in C++ language.

Solutions

Expert Solution

Complete Code for RetirementAccount class and for the DriverProgram added below.

The formula given in description contains invalid characters such as i, h. So I advice you to once check the formula in the question and make necessary changes to the formula in the code in RetirementAccount.cpp file.

Hit like if you liked the solution.

// main.cpp

#include"RetirementAccount.h"
using namespace std;

int main() {
    RetirementAccount ra(500.0, 12, 4.80, 25);
    cout<<ra.tostring()<<endl;

    double S_final = 289022.42f;
    double D = ra.planRetirementDeposits(S_final);
    cout<<"calculated monthly deposited needed to save $"<<S_final<<" is "<<D<<endl;

    double S = ra.calculateRetirementSavings();
    cout<<"Total Retirement savings calculated for monthly deposite of "<<ra.get_D()<<" is "<<S<<endl;
    return 0;
}

// RetirementAccount.h

#ifndef __RETIREMENT_ACCOUNT__
#define __RETIREMENT_ACCOUNT__
#include<iostream>
#include<string>
using namespace std;

class RetirementAccount {
    public:
        RetirementAccount(double D, double m, double r, double t);
        RetirementAccount();

        //getters
        double get_D();
        double get_m();
        double get_r();
        double get_t();

        //setters
        void set_D(double D);
        void set_m(double m);
        void set_r(double r);
        void set_t(double t);

        string tostring();
        double calculateRetirementSavings();
        double planRetirementDeposits(double S);
    private:
        double D;
        double m;
        double r;
        double t;
};
#endif /* __RETIREMENT_ACCOUNT__ */

// RetirementAccount.cpp

#include"RetirementAccount.h"

RetirementAccount::RetirementAccount(double D, double m, double r, double t) {
    this->D = D;
    this->m = m;
    this->r = r;
    this->t = t;
}
RetirementAccount::RetirementAccount() {
    RetirementAccount(1.0, 1.0, 1.0, 1.0);
}

//getters
double RetirementAccount::get_D() { return this->D; }
double RetirementAccount::get_m() { return this->m; }
double RetirementAccount::get_r() { return this->r; }
double RetirementAccount::get_t() { return this->t; }

//setters
void RetirementAccount::set_D(double D) { this->D = D; }
void RetirementAccount::set_m(double m) { this->m = m; }
void RetirementAccount::set_r(double r) { this->r = r; }
void RetirementAccount::set_t(double t) { this->t = t; }

string RetirementAccount::tostring() {
    string st;
    st = string("===== RetirementAccount =====\n") +
         " Deposit in $ : "+to_string(get_D())+"\n" +
         " No. Months   : "+to_string(get_m())+"\n" +
         " Interest Rate: "+to_string(get_r())+"%\n"+
         " No. of years : "+to_string(get_t())+"\n";
    return st;

}

double RetirementAccount::calculateRetirementSavings() {
    double S = D * (1 + (r/m)) * ((m*t) - 1) * (r/m);
    return S;
}

double RetirementAccount::planRetirementDeposits(double S) {
    double D = S * (r/m) * (1 + (r/m)) * ((m*t) - 1);
    return D;
}

// OUTPUT


Related Solutions

Description Construct a personal retirement problem and solve it. The purpose of this exercise is to...
Description Construct a personal retirement problem and solve it. The purpose of this exercise is to use the chapter’s concepts of future values, annuities, and compounding to your personal financial planning. Instructions ◦Determine the amount of investment funds you currently have available in all personal investments and self-directed and vested retirement accounts ◦Then, determine how much you will be adding to your investments a year in the future ◦Next, decide at what age you plan to retire. Determine what annual...
You have learned that money velocity is rather stable. Assume for simplicity that the velocity is...
You have learned that money velocity is rather stable. Assume for simplicity that the velocity is constant (the quantity theory of money). Explain how the growth in the money supply and inflation are related.
Everyone knows what money is. It is the collection of coins and bills that we carry...
Everyone knows what money is. It is the collection of coins and bills that we carry around in our pockets, purses. and wallets. Or at least that people often think that is what money is? In fact, “money” is merely a “social convention” as described by the text – Money is “what it does” rather than “what it is.” i.     (1) Briefly describe three (3) of the four (4) functions that must be present to make money, well, money, AND; (2)...
When firms decide to offer health insurance to their workers [for simplicity we assume they pay...
When firms decide to offer health insurance to their workers [for simplicity we assume they pay the full cost of the policy and do not ask for an employee contribution], they need to reconsider the wages they are willing to pay their workers. Assume the worker values the health insurance at full cost. Please use a labor supply and demand graph (as we covered in class) to analyze the effect of introducing insurance on the labor market. Part A: Show...
Lee saves most of his money from his paycheck; he forgoes restaurant meals, new clothes, and...
Lee saves most of his money from his paycheck; he forgoes restaurant meals, new clothes, and a new car, and he lives in a small one-bedroom apartment. He understands that his utility is low now. However, his ______________ will give him _____ utility in the future. A. planning; lower time-preference B. decision making; higher intertemporal C. decision making; lower intertemporal D. decision making; higher
Retirement planning is a common application of time value of money analysis. In this exercise you...
Retirement planning is a common application of time value of money analysis. In this exercise you need to build a model to calculate required retirement savings from a set of assumptions. Specifically, you must build a spreadsheet to calculate estimates of: Annual income needed in retirement. (based on a % of current salary) Total Savings you need to accumulate by the day you retire. Estimated annual contributions required before retirement needed to meet your retirement goal. These calculations will be...
Jacob is a private math tutor. He has no cost (assume just for simplicity, we know...
Jacob is a private math tutor. He has no cost (assume just for simplicity, we know that opportunity of his time is not zero). Currently Jacob has two students. Andy’s demand function for math private classes is pA = 20−qA while Ben’s demand function is pB = 12−(1/2)qB, where q is number of math classes. (a) Assume that Jacob cannot price discriminate. Jacob has to charge the uniform price to both students. Find the profit-maximizing price he charges for his...
For this exercise, we assume that there are no taxes and financial markets are perfect. The...
For this exercise, we assume that there are no taxes and financial markets are perfect. The ideal bank's interest rate (EAR) is 8% per year for all maturities. Company X owns one apartment building and has no other assets. Company X is 100% equity-financed;_ its revenue comes entirely from rental revenue of apartments it owns. We also assume that there are no cash costs, no depreciations, no investments, no working capital, therefore we have: rental revenue=EBIT=net income=free cash flow. Company...
Let’s assume that there are two goods x1= cat food, x2 = money. Consider a retirement...
Let’s assume that there are two goods x1= cat food, x2 = money. Consider a retirement home with two inmates, Mrs M and a grumpy old man, Mr Q. Mrs. M has the following endowment: W1=0, W2=30 , while Mr.Q has: W1=30, W2=0 . They have the following utility functions: U(x1,x2) = x1x2 (a) Illustrate the available resources and the initial allocation (=endowment) in an Edgeworth box. (b) Set the price of money equal to one, and define p as...
We assume an age at retirement of 67. Assuming that you start with zero dollars, at...
We assume an age at retirement of 67. Assuming that you start with zero dollars, at your age**, today, and you begin setting aside $500 per month, each month, from the present until age 67. How much money will you have set aside? Now, assume that your savings are invested at a annual return rate of 7%. How much money will you have at age 67? Would it make a difference if you invested an additional $100 each month, for...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT