|
|
 |
|
|
|
|
void Power( float base,
int exponent,
float& answer )
{
int i;
answer = 1.0;
i = 1;
while (i <= exponent)
{
answer = answer * base;
i++;
}
} |
|
|
|
|
|
|
|
|
9. You are given the following Test function and a C++ program in which the variables a, b, c, and result are declared to be of type float. In the calling code, a = -5.0, b = 0.1, and c = 16.2. What is the value of result when each of the following calls returns? |
|
|
|
 |
|
|
|
|
float Test( float x,
float y,
float z )
{
if (x > y || y > z)
return 0.5;
else
return -0.5;
}
a. result = Test(5.2, 5.3, 5.6);
b. result = Test(fabs(a), b, c); |
|
|
|
|
|
|
|
|
10. What is wrong with each of the following C++ function definitions? |
|
|
|
 |
|
|
|
|
a. void Test1( int m,
int n )
{
return 3 * m + n;
}
b. float Test2( int i,
float x )
{
i = i + 7;
x = 4.8 + float(i);
} |
|
|
|
|
|
|
|
|
11. Explain why it is risky to use a reference parameter as a formal parameter of a value-returning function. |
|
|
|
|
|