... creates the DollarAmount object balance and initializes it to 100000 pennies (i.e., $1,000)—the initial principal, which we display at line 38. Lines 44–50 perform the interest calculations. Line 46 calls the addInterest member function to perform the interest calculation for the current year. Then, line 49 displays the current year and a string representation of the balance. You can confirm that you entered the interest rate properly by looking at the new balance for year 1 in the output. For example, when calculating 5% interest, the first year’s end-of year balance will be 1050.00, and when calculating 5.25% interest, the first year’s balance will be 1052.50.

5.7.2 Class DollarAmount

Figure 5.8 defines class DollarAmount with data member amount ...

Get C++ How to Program, 10/e now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.