01: #include <iostream>
02: #include <iomanip>
03: #include <cmath>
04: 
05: using namespace std;
06: 
07: const int BALANCES_ROWS = 11;
08: const int BALANCES_COLS = 6;
09: 
10: const double RATE_MIN = 5;
11: const double RATE_MAX = 10;
12: const double RATE_INCR = 
13:    (RATE_MAX - RATE_MIN) / (BALANCES_ROWS - 1);
14: const int YEAR_MIN = 5;
15: const int YEAR_MAX = 30;
16: const int YEAR_INCR = 
17:    (YEAR_MAX - YEAR_MIN) / (BALANCES_COLS - 1);
18: 
19: 
20: /**
21:    Prints a table of account balances.
22:    @param the table to print
23:    @param table_rows the number of rows in the table.
24: */
25: void print_table(const double table[][BALANCES_COLS], 
26:    int table_rows)
27: {  
28:    const int WIDTH = 10;
29:    cout << setiosflags(ios::fixed) << setprecision(2);
30:    for (int i = 0; i < table_rows; i++)
31:    {  
32:       for (int j = 0; j < BALANCES_COLS; j++)
33:          cout << setw(WIDTH) << table[i][j];
34:       cout << "\n";
35:    }
36: }
37: 
38: /**
39:    Computes the value of an investment with compound interest
40:    @param initial_balance the initial value of the investment
41:    @param p the interest rate per period in percent
42:    @param n the number of periods the investment is held
43:    @return the balance after n periods
44: */
45: double future_value(double initial_balance, double p, int n)
46: {
47:    double b = initial_balance * pow(1 + p / 100, n);
48:    return b;
49: }
50: 
51: int main()
52: {  
53:    double balances[BALANCES_ROWS][BALANCES_COLS];
54:    for (int i = 0; i < BALANCES_ROWS; i++)
55:       for (int j = 0; j < BALANCES_COLS; j++)
56:          balances[i][j] = future_value(10000, 
57:             RATE_MIN + i * RATE_INCR,
58:             YEAR_MIN + j * YEAR_INCR);
59: 
60:    print_table(balances, BALANCES_ROWS);
61: 
62:    return 0;
63: }