Name: ____________________________________________________ Alpha: _____________________

Describe help received: _________________________________________________________________

See the bottom for how to submit your work.

  1. [10 pts] We would like you to self-test how much you retained from the lecture. Write the correct solution to the Practice Problem of
    Computing the average and maximum 
    Debug your code until it runs correctly. Circle below how you wrote your code.
    1. (10 pts) I was able to write the code without referring to anything.
    2. (10 pts) I had to look at the notes, but still I was able to write the code without looking at the solution.
    3. (10 pts) I had to look at solutions to finish to code.
    4. (0 pts) I didn't do this.
    If you had to look at the solution, briefly describe what you missed but understand now.
    
    
    
    
  2. [10pts] Consider the following program. What will be the output? Use the VS Code debugger -- set the breakpoint on the line of "int a = 1, b=2;" and then track how the code runs step by step.
    
    #include <iostream>
    using namespace std;
    
    int main()
    {
      int a = 1, b = 2;
    
      while(a <= 10)
      {
        if( a % 2 ) 
        {
          a = a + b;
          b = b + 2;
        }
        else
        {
          a = a + 1;
          b = b - 1;
        }
    
        cout << a << " " << b << endl;
      }
    
      return 0;
    }
    
    output:
  3. [10pts] Consider the following program, which is supposed to compute the sum of the integers from 1 to 10.
    
    #include <iostream>
    using namespace std;
    int main()
    {
      int i = 1;
      while(i <= 10)
      {
        int sum = 0;
        sum = sum + i;
      }
      cout << sum << endl;
      return 0;
    }
    1. The program doesn't compile. What kind of error messages will you get from the compiler?
      
      
      
      
      
    2. Annotate the above code fix this error (and any other errors) so that the program both compiles and works properly.

Turn in

Bring your work to class.