Name______________________________________________________________

 

1.  (50%) Consider the following program:

 

void GI (int& x, int& y) {

      x = 3;

      y = x + 2;

}

 

int C (int x, int b, int& z) {

 

      int j = 0;

      z = 0;

      x = 1;

      while (j < b) {

            j+=2;

            z += 1;

      }

      return j;

}

 

void main () {

      int x, y, z;

      GI (x, y);

      cout << C (x, y, z) << endl;

      if (z >= 2) {

            cout << x <<"," << y << "," <<z;

      }

}

 

What is output by the program above?  Partial credit will be given for all work shown.

 

 

output:

6

3,5,3

 

  1.  (50%)  In the space below, write a C++ function with a single, positive integer parameter n whose return value is the sum of the first n terms of the series

 

 

float Func (int n) {

            float sum = 0.0;

                        for (int j = 1; j <= n; j++) {

                                    sum += (j/pow(2.0, j-1));        

                        }

                        return sum;

            }