Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Future Value is what a given sum of money now (present value) is worth at a spec

ID: 3762303 • Letter: F

Question

Future Value is what a given sum of money now (present value) is worth at a specific time in the future given a certain interest rate. Write a C++ class called FutureValue. The class should support the following features:

Private Data:
double amount — The present value amount
float interestRate — The annually compounding interest rate
int years — The number of years for the future value

Constructor:
FutureValue() — Initializes a FutureValue object with a default amount of 0.0, a default interest rate of 0.0f (note that the f means float), and a default years of 1 (years should never be less than 1).

Public Member Functions:
double getAmount() — returns the present value amount
float getInterest() — returns the interest rate
int getYears() — returns the number of years for the future value
double getValue() — returns the future value amount. The future value amount is calculated as Amount * (1.0 + interest)years. Hint: Use the pow function from the <cmath> library.

Operator Overloads:
= double — When double is assigned to the FutureValue object, it is saved as the new present value amount. The operator returns the new amount.
= float — When float is assigned to the FutureValue object, it is saved as the new interest rate. The operator returns the new interest rate.
= int — When int is assigned to the FutureValue object, it is saved as the new years. If the int value assigned is less than 1, years is set to 1 instead. The operator returns the new years.
ostream << — When FutureValue is output to an ostream, it will output the future value formatted as a currency amount (i.e., with a dollar sign and 2 decimal places). The operator returns the ostream& (hint: see Overloading the Stream Operators in your text book).
++ (pre-increment) — When a FutureValue is incremented pre-increment, the number of years is increased by 1. The opreator returns value for number of years after the increment.
++ (post-increment) — When a FutureValue is incremented post-increment, the number of years is increased by 1. The opreator returns value for number of years before the increment.
-- (pre-decrement) — When a FutureValue is decremented pre-decrement, the number of years is decreased by 1. If the number of years is 1, it should not be decreased any further. The operator returns the value for number of years after the decrement (if decremented).
-- (post-decrement) — When a FutureValue is decremented post-decrement, the number of years is decreased by 1. If the number of years is 1, it should not be decreased any further. The operator returns the value for number of years before the decrement (if decremented).

Program: Write a program that creates a FutureValue object using the default constructor. Then the program asks the user for a present value (double) and an interest rate (float). The interest rate should be in decimal form (i.e., 0.10f for 10%, 0.05f for 5%). These values should be assigned to the FutureValue object. Then the application should display (in tabular form) the future values for the years 1 through 10. Your loop should use the FutureValue object as the loop counter. E.g., if fv is the FutureValue object, then your loop would be
for (fv = 1; fv.getYears() < 10; fv++)

Explanation / Answer

The FutureValue() function is used to calculate the future value of an investment. The syntax of this function is:

Extended __fastcall FutureValue(Extended Rate,

                                int NPeriods,

                                Extended Payment,

                                Extended PresentValue,

                                TPaymentTime PaymentTime);

Here is an example:

void __fastcall TForm1::btnCalculateClick(TObject *Sender)

{

            Extended Present, Future, Payment, TheRate;

            int Period;

            Present = StrToFloat(edtPresent->Text);

            Payment = StrToFloat(edtPayment->Text);

            Period = StrToInt(edtPeriod->Text);

            TheRate = StrToFloat(edtRate->Text) / 12;

            double Rate = TheRate /100;

            Future = FutureValue(Rate, Period, Payment, Present, ptEndOfPeriod);

            edtFuture->Text = FloatToStrF(Future, ffCurrency, 8, 2);

}

void __fastcall TForm1::btnExitClick(TObject *Sender)

{

            Close();

}

The NumberOfPeriods() function calculates the number of periodic payments of an investment.

Its syntax is:

Extended __fastcall PeriodPayment(constExtended Rate, int Period, int NPeriods,

const Extended PresentValue, const Extended FutureValue, TPaymentTime PaymentTime);

Here is an example:

void __fastcall TForm1::btnCalculateClick(TObject *Sender)

{

Extended Present, Future, TheRate, Payments, NPeriod;

Present = StrToFloat(edtLoan->Text);

Future = StrToFloat(edtFuture->Text);

Payments = StrToFloat(edtPayments->Text);

TheRate = StrToFloat(edtRate->Text) / 12;

double Rate = TheRate / 100;

// Apply the function

NPeriod = NumberOfPeriods(Rate, -Payments, -Present, Future, ptStartOfPeriod);

// Since the number of periods is really an integer, find its ceiling

Extended Actual = Ceil(NPeriod);

// Display the number of periods

edtNPeriods->Text = FloatToStr(Actual);

}

void __fastcall TForm1::btnExitClick(TObject *Sender)

{

PostQuitMessage(0);

}

The Payment() function is used to calculate the regular payment of an investment. Its

syntax is:

Extended __fastcall Payment(Extended Rate, int NPeriods, constExtended PresentValue, const Extended FutureValue, TPaymentTime PaymentTime);

In the following examples, a customer is applying for a car loan. The car costs $15500. It will be financed at 8.75% for 5 years. The dealer estimates that the car will have a value of $2500 when it is paid off:

void __fastcall TForm1::btnCalculateClick(TObject *Sender)

{

Extended Present, Future, TheRate, Payments, NPeriod;

Present = StrToFloat(edtLoan->Text);

Future = StrToFloat(edtFuture->Text);

TheRate = StrToFloat(edtRate->Text) / 12;

NPeriod = StrToFloat(edtNPeriods->Text);

double Rate = TheRate / 100;

// Apply the function

Payments = Payment(Rate, NPeriod, -Present,

Future, ptStartOfPeriod);

// Display the payments

edtPayments->Text = FloatToStrF(Payments, ffCurrency, 8, 2);

}

While the InterestPayment() function calculates the amount paid as interest for a loan, the PeriodPayment() function calculates the actual amount that applies to the balance of the loan.

This is referred to as the principal. Its syntax is:

Extended __fastcall PeriodPayment(constExtended Rate, int Period, int NPeriods, const Extended PresentValue, const Extended FutureValue, TPaymentTime PaymentTime);

Here is an example:

void __fastcall TForm1::btnCalculateClick(TObject *Sender)

{

Extended Present, Future, TheRate, PPayment;

int Periods, NPeriod;

Present = StrToFloat(edtLoan->Text);

Future = StrToFloat(edtFuture->Text);

TheRate = StrToFloat(edtRate->Text) / 12;

Periods = StrToInt(edtPeriod->Text);

NPeriod = StrToInt(edtNPeriods->Text);

double Rate = TheRate / 100;

// Apply the function

PPayment = PeriodPayment(Rate, Periods, NPeriod,

-Present, Future, ptStartOfPeriod);

// Display the payment

edtPPMT->Text = FloatToStrF(PPayment, ffCurrency, 8, 2);

}

The PresentValue() function calculates the total amount that future investments are worth currently.

Its syntax is:

Extended __fastcall PresentValue(constExtended Rate, int NPeriods, const Extended Payment, const Extended FutureValue, TPaymentTime PaymentTime);

Here is an example:

void __fastcall TForm1::btnCalculateClick(TObject *Sender)

{

Extended Present, Future, TheRate, Payments;

int NPeriod;

Future = StrToFloat(edtFuture->Text);

Payments = StrToFloat(edtPayments->Text);

TheRate = StrToFloat(edtRate->Text) / 12;

NPeriod = StrToInt(edtNPeriods->Text);

double Rate = TheRate / 100;

// Apply the function

Present = PresentValue(Rate, NPeriod, -Payments, -Future, ptStartOfPeriod);

// Display the payment

edtPresent->Text = FloatToStrF(Present, ffCurrency, 8, 2);

}

The InterestPayment() function is used to calculate the amount paid as interest for a loan. Its syntax is:

Extended __fastcall InterestPayment(constExtended Rate, int Period, int NPeriods, const Extended PresentValue, const Extended FutureValue, TPaymentTime PaymentTime);

void __fastcall TForm1::btnCalculateClick(TObject *Sender)

{

Extended Present, Future, Payment, TheRate;

int Periods, NPeriod;

Present = StrToFloat(edtPresent->Text);

Future = StrToFloat(edtFuture->Text);

Periods = StrToInt(edtPeriod->Text);

NPeriod = StrToInt(edtNPeriods->Text);

TheRate = StrToFloat(edtRate->Text) / 12;

double Rate = TheRate /100;

Payment = InterestPayment(Rate, Periods, NPeriod,

Present, Future, ptEndOfPeriod);

edtPayments->Text = FloatToStrF(Payment, ffCurrency, 8, 2);

}

The InterestRate() function is used to find the interest applied to a loan. Its syntax is:

Extended __fastcall InterestRate(int NPeriods, constExtended Payment, const Extended PresentValue, const Extended FutureValue, TPaymentTime PaymentTime);

All of the arguments are the same as described for the InterestPayment() function. Here is an example:

void __fastcall TForm1::btnCalculateClick(TObject *Sender)

{

Extended Present, Future, Payments, Rate;

int NPeriod;

Present = StrToFloat(edtPresent->Text);

Future = StrToFloat(edtFuture->Text);

Payments = StrToFloat(edtPayments->Text);

NPeriod = StrToInt(edtNPeriods->Text);

Rate = InterestRate(NPeriod, Payments, Present,

Future, ptEndOfPeriod) * 12 * 100;

AnsiString Value = FloatToStrF(Rate, ffGeneral, 3, 2);

edtRate->Text = Value + "%";

}