Name: ____________________________________________________ Alpha: _____________Section: ________

Describe help received: _________________________________________________________________

See the bottom for how to submit your work.

Due: Before 0800 on next class day

  1. (10 pts) Read lecture notes for today. Honestly declare how you read the notes.
    1. (10 pts) I read the notes carefully. I have a good understanding of the topics therein.
    2. (10 pts) I read the notes carefully, but I don't really understand the following points well:
      
      
      
      
    3. (0 pts) I didn't read the notes carefully.
  2. [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.
  3. [10pts] Consider the following program. What will be the output? Try to solve it manually instead of compiling and running the code. We will ask this kind of question in the exam.
    
    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;
    }
    
    
    output:
  4. [70pts] Write a program that reads four integers s, e, a, b from the user. The program must print out every number that satisfies the following conditions at the same time: The program should print these numbers in increasing order.

    Note: your source code must use a while loop. Example of running your program:

    $ ./hw
    Enter four integers: 10 102 4 6
    12 24 36 48 60 72 84 96
    
    $ ./hw
    Enter four integers: 9 100 3 9
    9 18 27 36 45 54 63 72 81 90 99 
    
    $ ./hw
    Enter four integers: 1000 1500 30 21
    1050 1260 1470 
    

Turn in (Due: 0800 on the next class day)