SYCS-135� Introduction to Programming

Quiz 6 - 10/21/99

 

Name:� ���������� ����������������������� ����������������������� �����������

 

  1. [2] If a function contains a locally declared variable with the same name as a global variable, no confusion results because references to variables in functions are first interpreted as references to local variables.

 

a)� True����������� ����������� b) False

 

  1. [2] Variables declared at the beginning of a block are accessible to all statements in that block, including those in nested blocks (assuming the nested blocks don't declare local variables with the same names).

 

a)� True����������� ����������� b) False

 

  1. [6] The statement:������������������ power(k, l, m);

 

is a call the function whose definition can be found below.� Rewrite the function as a value-��

returning function, then write a function call that assigns the function value to the variable m.

 

void power (float base, ������� ���// IN:� the base to be raised to a power

������������ int exponent,� �� // IN:� the power that the base will be raise to�

������������ float& answer) // OUT: the result from raising the base to power of the exponent

���� {

int i;

answer = 1.0;

i = 1;

while (i <= exponent)

{

����������� answer = answer * base;

����������� i++;

}

}

Answer:��������� ����������������������� ����������������������� ����������������������� �����������������������

����������������� ����������������� ����������������� ����������������� �����������������

����������������� ����������������� ����������������� ����������������� �����������������

����������������� ����������������� ����������������� ����������������� �����������������

����������� ����������� ����������������������� ����������������������� ����������������������� �����������������������

����������������������� ����������������������� ����������������������� ����������������������� �����������������������

����������������������� ����������������������� ����������������������� ����������������������� �����������������������

����������������������� ����������������������� ����������������������� ����������������������� �����������������������

����������������������� ����������������������� ����������������������� ����������������������� �����������������������

����������� ����������� ����������������������� ����������������������� ����������������������� �����������������������

����������������������� ����������������������� ����������������������� ����������������������� �����������������������

����������������������� ����������������������� ����������������������� ����������������������� �����������������������

����������������������� ����������������������� ����������������������� ����������������������� �����������������������

Function call:� ����������������������� ����������������������� ����������������������� �����������������������