Listings 7.5 to 7.15, from "The C++ Workbook" by Wiener and Pinson, Addison-Wesley, 1990.