Name: ____________________________________________________ Alpha: ________________________

Describe help received: _____________________________________________________________________

Print this homework sheet, bring it to the class, and turn it in right before the next lecture starts.

  1. [10pts] For each of the below, circle the correctly parenthesized version of the expression and circle "precedence" or "associativity" as appropriate.

    expressionevaluated asdue to
    x + y * z (x + y) * z   OR   x + (y * z) precedence   OR   associativity
    x > y + z (x > y) + z   OR   x > (y + z) precedence   OR   associativity
    cin >> x >> y (cin >> x) >> y   OR   cin >> (x >> y) precedence   OR   associativity
    x = y = 1 (x = y) = 1   OR   x = (y = 1) precedence   OR   associativity
    x = y == z (x = y) == z   OR   x = (y==z) precedence   OR   associativity
  2. [10pts] Assume the following declarations.
    expressiontypevalue
    n = 2
    n == 2
    c < 200
    1 != x
    1 < x < 10
    int n = 5;
    double x = 10.5;
    char c = 'R';
    
    Fill in the table on the right. Note: each expression should be taken as independent. I.e. if one expression modifies some variable values, those modifications do not carry over to the next expression.
  3. [5pts] Fill in the conditions on the if statements on the right so that they are equivalent.
    
    if (a <= 'k')
    {
      cout << "easy";
    }
    else
    {
      if (a >= 'q')
        cout << "easy";
      else
        cout << "tough";
    }
    
    
    if (_____________________________________________)
    {
      cout << "easy";
    }
    else
    {
      cout << "tough";
    }    
    
  4. [15pts] Read part 1 of Lab 3 (see calendar). Write out "pseudocode" that will solve this problem. This is not a complete solution; it just describes the basic steps using English, but the steps should be small enough that you can translate it into C++ without too much work. It should look like a lists of steps, not a paragraph. You can type this up or handwrite it on the back of this homework. Don't stress too much about this; the point is to read the lab in advance and start thinking about a solution!
  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
    Submit
    ~/bin/submit -c=IC210 -p=hw07 hw.cpp
    
    Turn in a printout of this cover sheet and the codeprint of hw.cpp