Question

C++ Program help! Typically, everyone saves money periodically for retirement, buying a house, or for some...

C++ Program help! 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 Math Figure 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 Math Figure Instructions Design a class that uses 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. Also, write a program to test your class.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Screenshot

---------------------------------------------------------------------------------

Program

AmountAccumulate.h

#include<iostream>
#include<cmath>
using namespace std;
//Create a class
class AmountCalculate
{
   ///Member functions
public:
   //Default constructor
   AmountCalculate();
   //Parameterized constructor
   AmountCalculate(double,double,int);
   //Destructor
   ~AmountCalculate();
   //Setters
   void setAmt(double);
   void setInterest(double);
   void setYear(int);
   //Getters
   double getAmt();
   double getInterest();
   int getYear();
   //Method to calculate accumulated amount
   double Calculate();
   //Print details
   void print();
   //Instance variables
private:
   double periodicAmt;
   double interest;
   int year;
};

AmountAccumulate.cpp

#include "AmountAccumulate.h"
AmountCalculate::AmountCalculate()
{
   //Default constructor
   periodicAmt = 0;
   interest = 0;
   year = 0;
}
//Destructor
AmountCalculate::~AmountCalculate()
{
}
//Parameterized constructor
AmountCalculate::AmountCalculate(double amt, double ir, int yr) {
   if (amt < 0) {
       periodicAmt = 0;
   }
   else {
       periodicAmt = amt;
   }
   if (ir < 0) {
       interest = 0;
   }
   else {
       interest = ir;
   }
   if (yr < 0) {
       year = 0;
   }
   else {
       year = yr;
   }
}
//Setters
void AmountCalculate::setAmt(double amt) {
   if (amt < 0) {
       periodicAmt = 0;
   }
   else {
       periodicAmt = amt;
   }
}
void AmountCalculate::setInterest(double ir) {
   if (ir < 0) {
       interest = 0;
   }
   else {
       interest = ir;
   }
}
void AmountCalculate::setYear(int yr) {
   if (yr < 0) {
       year = 0;
   }
   else {
       year = yr;
   }
}
//Getters
double AmountCalculate::getAmt() {
   return periodicAmt;
}
double AmountCalculate::getInterest() {
   return interest;
}
int AmountCalculate::getYear() {
   return year;
}
//Method to calculate accumulated amount
double AmountCalculate::Calculate() {
   return periodicAmt * (pow((1 + (interest / 100) / 12), (12 * year)) - 1) / ((interest / 100) / 12);
}
//Print details
void AmountCalculate::print() {
   cout << "Peridic depositing amount : $" << periodicAmt << endl;
   cout << "Compounding interest Rate : " << interest <<"%"<< endl;
   cout << "Number of years depositted : " << year << endl;
   cout << "Accumulated Amount         : $" << Calculate() << endl;
}

main.cpp

#include <iostream>
#include "AmountAccumulate.h"
using namespace std;
//Function protoytpe
void test();
int main()
{
   test();
}
//test method
void test() {
   double amt, ir;
   int yr;
   //Prompt for each values
   cout << "Enter the periodic amount : ";
   cin >> amt;
   cout << "Enter interest rate : ";
   cin >> ir;
   cout << "Enter years : ";
   cin >> yr;
   //Create object
   AmountCalculate calculator(amt, ir, yr);
   calculator.print();
}

---------------------------------------------------------

Output

Enter the periodic amount : 500
Enter interest rate : 4.8
Enter years : 25
Peridic depositing amount : $500
Compounding interest Rate : 4.8%
Number of years depositted : 25
Accumulated Amount         : $289022

Add a comment
Know the answer?
Add Answer to:
C++ Program help! Typically, everyone saves money periodically for retirement, buying a house, or for some...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT