﻿ Lab 4

Lab 4

Complete the program in Lab04.cpp according to the specifications given below.

Output Specifications

Generate a text file named "Investments.txt" containing a table that gives the results of  several lump-sum investments earning compound interest. Each line of the table represents one investment and contains the present value (dollars), the nominal annual rate (as a percent), the compounding frequency (monthly, quarterly, semiannually, or annually), the term in years, the future value (dollars), the total interest earned during the term of the investment (dollars), and the annual percentage yield (as a percent). The table columns are separated by two blank spaces and the table format is illustrated in the example below.

```   Present  Nominal  Compounding              Future       Total
Value     Rate  Frequency     Years       Value    Interest      APY
----------  -------  ------------  -----  ----------  ----------  -------
1000.00    5.25%  Annually         10     1668.10      668.10   5.250%
1000.00    5.25%  Semiannually     10     1679.05      679.05   5.319%
1000.00    5.25%  Quarterly        10     1684.70      684.70   5.354%
1000.00    5.25%  Monthly          10     1688.52      688.52   5.378%
1500.00    4.00%  Quarterly         5     1830.29      330.29   4.060%
500.00    6.90%  Monthly           3      614.63      114.63   7.122%
2500.00    3.93%  Monthly           8     3421.84      921.84   4.002%```

Input Specifications

The investment parameters will be read from a text file named "Investments.dat". Each line of the file contains four numbers: the present value (in dollars and cents), the nominal annual rate (as a percent but without the percent symbol), the compounding frequency (an integer), and the term in years (an integer). The number of lines in the file is unknown ahead of time. The results shown earlier were generated using this data file:

```1000 5.25  1 10
1000 5.25  2 10
1000 5.25  4 10
1000 5.25 12 10
1500 4.0 4 5
500 6.9 12 3
2500 3.93 12 8```

Process Specifications

Calculate the future value, the total interest earned, and the annual percentage yield for each investment:

 Variable Represents Formula FV Future Value FV = PV*(1+i)n PV Present Value Given r Nominal Annual Rate (%) Given ppy Periods per Year Given i Periodic Rate (%) i=r/ppy t Time in Years Given n Number of Periods n=t*ppy I Total Interest I = FV - PV APY Annual Percentage Yield APY = (1+i)ppy - 1

When writing a line to the report, you will need a selection structure to determine the compounding frequency in words given the compounding frequency as an integer (the periods per year).

Miscellaneous

There is no exponentiation operator in C++. However, C++ provides a function that performs this useful operation:

`    pow(b, n) returns the value of bn as a double `

To use this function, you must include the cmath header file:

`#include<cmath>`