... 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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access