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 Mandatory Practice Problems. 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] The following program is supposed to read in numbers from the user (until a non-integer value) and report the number of negative, zero and positive values entered (counting duplicates).
    
      int zero = 0, pos = 0, neg = 0, k;
      while(cin >> k) 
      {
        if (k == 0)
          zero++;
        if (k > 0)
          pos++;
        else
          neg++;
      }
      cout << " neg = " << neg << endl;
      cout << "zero = " << zero << endl;
      cout << " pos = " << pos << endl;
    
    Unfortunately, this program has a bug. For example, with input
     2 0 -3 ; 
    it outputs
     neg = 2
    zero = 1
     pos = 1
    
    ... even though there is clearly one negative, one positive and one zero value.

    Annotate the code to show how to fix the bugs.

    Turn in

    Bring your work to class.