< previous page page_456 next page >

Page 456
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
write the body of the function to return the length of the hypotenuse of a right triangle. The formal parameters represent the lengths of the other two sides. The formula for the hypotenuse is
0456-01.gif
9. Write a value-returning function named FifthPow that returns the fifth power of its float parameter.
10. Write a value-returning function named Min that returns the smallest of its three integer parameters.
11. The following If conditions work correctly on most, but not all, machines. Rewrite them using the is functions from the C++ standard library (header file ctype.h).
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
a. if (inChar >= 0 && inChar <= 9)
       DoSomething();
b. if (inChar >= A && inChar <= Z ||
       inChar >= a && inChar <= z   )
       DoSomething();
c. if (inChar >= A &amp; inChar <= Z ||
       inChar >= 0 && inChar <= 9   )
       DoSomething();
d. if (inChar << a || inChar > z)
       DoSomething();
12. Write a Boolean value-returning function IsPrime that receives an integer parameter n, tests it to see if it is a prime number, and returns TRUE if it is. (A prime number is an integer greater than or equal to 2 whose only divisors are 1 and the number itself.) A call to this function might look like this:
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
if (IsPrime(n))
    cout << n <<  is a prime number.;
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
(Hint: If n is not a prime number, it is exactly divisible by an integer in the range 2 through c0456-01.gif
13. Write a value-returning function named Postage that returns the cost of mailing a package, given the weight of the package in pounds and ounces and the cost per ounce.
Programming Problems
1. If a principal amount (P), for which the interest is compounded Q times per year, is placed in a savings account, then the amount of interest earned after N years is given by the following formula, where I is the annual interest rate as a floating point number:
0456-02.gif
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Write a C++ program that inputs the values for P, I, Q, and N and outputs the interest earned for each year up through year N. You should use a value-returning

 
< previous page page_456 next page >