< previous page page_252 next page >

Page 252
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Suggestion: Don't compute Stirling's formula directly. The values of nn and en can be huge, even in floating point form. Take the natural logarithm of the formula and manipulate it algebraically to work with more reasonable floating point values. If r is the result of these intermediate calculations, the final result is er. Make use of the standard library functions log and exp, available through the header file math.h. These functions, described in Appendix C, compute the natural logarithm and natural exponentiation, respectively.
Case Study Follow-up
1. In the Activity program, the endl manipulator appears five times, once in each output statement. Show how to eliminate this duplication of code by using endl just once after the appropriate message is printed.
2. For the Activity program, insert validation tests to exclude temperatures beyond 125 degrees and below -40 degrees. Provide constructive error messages to the user.
3. How would you modify the prompt in the Activity program so that the user avoids violating the constraints in Question 2?
4. Write the preconditions and postconditions for the modules in the Notices program.
5. Change the revised LumberYard program (page 236) so that if a code other than L or P is entered, the other two tests are avoided. Also, if the code is an L, do not test for the P.

 
< previous page page_252 next page >