|
|
 |
|
|
|
|
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 |
|
|
|
|
|
|
|
|
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). |
|
|
|
 |
|
|
|
|
a. if (inChar >= 0 && inChar <= 9)
DoSomething();
b. if (inChar >= A && inChar <= Z ||
inChar >= a && inChar <= z )
DoSomething();
c. if (inChar >= A & 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: |
|
|
|
 |
|
|
|
|
if (IsPrime(n))
cout << n << is a prime number.; |
|
|
|
 |
|
|
|
|
(Hint: If n is not a prime number, it is exactly divisible by an integer in the range 2 through  |
|
|
|
|
|
|
|
|
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. |
|
|
|
|
|
|
|
|
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: |
|
|
|
 |
|
|
|
|
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 |
|
|
|
|
|