Practice problem 2 from chapter 3 rewritten in C++.