Name: ______________________________________________ Alpha: ________________

Describe help received: _________________________________________________________________

For this assignment you will want to consult the C++ operator associativity/precedence table.

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

    1. x + y * z evaluates as (x + y) * z OR x + (y * z) due to: precedence associativity

    2. x > y + z evaluates as (x > y) + z OR x > (y + z) due to: precedence associativity

    3. cin >> x >> y evaluates as (cin >> x) >> y OR cin >> (x >> y) due to: precedence associativity

    4. x = y = 1 evaluates as (x = y) = 1 OR x = (y = 1) due to: precedence associativity

    5. cin >> x = y evaluates as (cin >> x) = y OR cin >> (x = y) due to: precedence associativity

  2. [10pts] Assuming the declarations in the left column, fill in the table. Each expression should be taken as independent, i.e. if one expression modifies some variable's value, those modifications do not carry over to the next expression.
    int n = 5;
    double x = 1.5;
    char c = 'R';
    
    expressiontypevalue
    n = 2
    n == 2
    c < 200
    1 != x
    n*x
  3. [80pts] 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. Clear? 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
    703 is not a Leap Year
    $ ./hw
    Enter year: 704
    704 is a Leap Year
Turn in a printout of this cover sheet with your answers to the questions, your source code, and a screen capture of your program running each of the four examples from the table above (703, 704, 700, and 800).