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 today's lecture notes carefully. 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] 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
  3. [16pts] Fill in the table on the right.
    int n = 5;
    double x = 10.5;
    char c = 'R';
    
    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.
    expressiontypevalue
    n = 2
    n == 2
    c < 200
    1 != x
    1 < x < 10
    1 < x && x < 10
    !n
    c == int('R')
  4. [4pts] Fill in the conditions on the if statements on the right so that they are equivalent. You may want to review how logical operators (i.e., &&, ||, !) work (see the notes on class 3).
    
    if (a <= 'k')
    {
      cout << "easy";
    }
    else
    {
      if (a >= 'q')
        cout << "easy";
      else
        cout << "tough";
    }
    
    
    if (_____________________________________________)
    {
      cout << "easy";
    }
    else
    {
      cout << "tough";
    }    
    
  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 hw.cpp that reads in a year and prints out (correctly) Is Leap Yar or Is Not Leap Year. A typical run of the program should look like this (user input colored red):
      $ ./hw
      Enter year: 703
      Is Not Leap Year
      
      $ ./hw
      Enter year: 2020
      Is Leap Year
      

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