CS 1440 pre-lab activities for Lab Extra (2)

You have 5 minutes to answer these questions.


Answer the following questions in writing before you begin the lab and hand in the solution to your instructor.
1. What will the following code segment display? Assuming that the rest of the program is correct.
      int main() 
      { 
          int x=3, y=2; 
          x = func(y); 
      
          cout << "x = " << x  << "   and y = "  << y  << endl;
          return 0; 
      } 

      int func(int& z) 
      { 
           int x = 0; 
           x = z*z; 
           return z/2; 
       }

2. Suppose you want to write a function to compute the following formula.  Fill out the blanks below the formula.

avg_of_i-sq
This basically means that the average is the sum of N values divided by the number of values.

Function Name: ___________________ Function Type: ____________________

Function argument(s): __________________

Return value (if it is not a void function) : ______________________________

The function prototype: ______________________________________________

3. What is wrong with the following segment? Assuming the rest of the program is correct.
        ofstream mystream;
        int x,y;
        
        
        mystream >> x >> y;