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 "Area Calculation". 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 code below. Fill out the table.
    
    char c1, c2;
    string s1, s2;
    
    cin >> c1;
    if( c1 <= 'Z' )
    {
      cin >> c2; 
      if( c2 <= 'Z' )
      {
        cin >> s1;
        cout << c1 << c2 << s1 << endl;
      }
    }
    else
    {
      if( c1 >= 'a' )
      {
        cin >> s1 >> s2;
        cout << c1 << s1 << " " << s2 << endl;
      }
      else
      {
        cout << c1 << endl;
      }
    }
    
    Input to the program Program output
    IC210 rocks
    Ic210 rocks
    ic210 rocks
    [210 really rocks]
    Homework Homework
  3. [10pts] Consider the following code:
    
    int p;
    p = 1;
    cout << &p << endl;
    {
      int p;
      cout << &p << endl;
    }
    cout << &p << endl;
    
  4. [10pts] Consider the following code. Fill out the table on the right.
    
    string s, t, r;
    
    cin >> s;
    if( s == "hello" )
    {
      cin >> t;
      string s;
      s = s + "." + t + ".world";
    }
    
    cin >> r;
    s = s + "." + r + ".programmers";
    cout << s << endl;
    
    Input to the programProgram output
    hello wonderful go
    computer science nice
  5. [60pts] A year is a leap year if it is evenly divisible by 4, except that years that are evenly divisible by 100 are not leap years unless they are evenly divisible by 400. For example:
    Year divisible by 4? divisible by 100? divisible by 400? Is leap year?
    703nonononot leap year
    704yesnonoleap year
    700yesyesnonot leap year
    800yesyesyesleap year
    Write a program that reads a year and prints out (correctly!) Is Leap Year or Is Not Leap Year. Here are two example runs.
    $ ./hw
    Enter year: 703
    Is Not Leap Year
    $ ./hw
    Enter year: 704
    Is Leap Year

Turn in