Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please convert my code from C to C++ Typically, everyone saves money periodically for retirement, buying a house, or for some other purposes. If you

Please convert my code from C to C++

Typically, everyone saves money periodically for retirement, buying a house, or for some other purposes. If you are saving money for retirement, then the money you put in a retirement fund is tax sheltered and your employer also makes some contribution into your retirement fund. 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 that a person deposits R dollars m times a year into an account that pays r % interest compounded m times a year for t years. Then the total amount accumulated at the end of t years is given by For example, suppose that you deposit $500 at the end of each month into an account that pays 4.8% interest per year compounded monthly for 25 years. Then the total money accumulated 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 like to know how much money, m times a year, you should deposit into an account that pays r% interest compounded m times a year. The periodic payment is given by the formula Instructions The finance header file has been provided. Use the above formulas 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 store 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, functions to set the values of the instance variables, functions to retrieve the values of the instance variables, and functions to do the necessary calculations and output results.

My Code:

#include  #include  #include "finance.h" using namespace std; finance::finance (double pD, double depInAYear, double y, double ir) { periodicDeposit = pD; numOfDepositsInAYear = depInAYear; years = y; interestRate = ir; } void finance::set(double pD, double depInAYear, double y, double ir) { periodicDeposit = pD; numOfDepositsInAYear = depInAYear; years = y; interestRate = ir; } void finance::setPeriodicDeposit(double pD) { periodicDeposit = pD; } void finance::setNumOfDepositsInAYear(double depInAYear) { numOfDepositsInAYear = depInAYear; } void finance::setTotalNumOfYears(double y) { years - y; } void finance::setInterestRate(double ir) { interestRate = ir; } double finance::getPeriodicDeposit() { return periodicDeposit; } double finance::getNumOfDepositsInAYear() { return numOfDepositsInAYear; } double finance::getTotalNumOfYears() { return years; } double finance::getInterestRate() { return interestRate; } double finance::totalAccumulated() { double term = pow ((1 + interestRate / 100.0 / numOfDepositsInAYear), years * numOfDepositsInAYear); double total = periodicDeposit * (term - 1) / (interestRate / 100.0 / numOfDepositsInAYear); return total; } double finance::periodicPaymentToAccumulateASum(double s) { double first = s * interestRate / 100 / numOfDepositsInAYear; double second = pow ((1 + interestRate / 100 / numOfDepositsInAYear), years * numOfDepositsInAYear); return (first / (second - 1)); } int main() { finance f (500, 12, 25, 4.8); printf ("%lf ", f.totalAccumulated()); printf ("%lf ", f.periodicPaymentToAccumulateASum (289022.416)); return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions