CSCI 157 - HW 3

Homework 3 - Chapter 4


About those *'s ...

At all times I require you to "Show all your work". If the answer is 12, I'm going to want to know exactly how you came to that conclusion. On this homework, particularly on exercises resembling those in 4.8.5,etc (the *'d ones!) many of you will be tempted to keep all or some steps in your head. Don't. This will not be worth full credit. So ... show it all.

Consider the following hypothetical problem.

    What is the value of the following expression if w = 3, q = -2, t = 1?

    ( w + t > q*3 || 2 * q + t > 5 / w ) && !( q >= t)
I recommend you re-write the expression on your page, exactly as given. THEN, substitute in the values. Only when you've done both of those steps, should you start going through a careful sequence of evaluations of the various operators, keeping operator precedence in mind.


Here's an answer to which I would happily give full credit. Student has CLEARLY demonstrated a full understanding of working and precedence of all operators.

  i) ( w +  t   <  q*3 || 2 *  q  + t >  5 / w ) && !(  q >= t)
     ( 3 +  1   < -2*3 || 2 * -2  + 1 >  5 / 3 ) && !( -2 >= 1)
     (   4      < -6   ||  -4     + 1 >  1     ) && !( false  )
     (      false      ||     -3      >  1     ) && true         
     (      false      ||     false            ) && true         
                      false                      && true         
                                               false             

Versus a partial credit... person has shown work for evaluating logical operators but neglected to do so for comparison and mathematical operators.
 ii) ( 3 +  1   < -2*3 || 2 * -2  + 1 >  5 / 3 ) && !( -2 >= 1)
                                       false     && true         
                                               false    

Another partial credit... person has shown work for evaluating mathematical operators but neglected to do so for comparison and logical operators.

 ii) ( w +  t   <  q*3 || 2 *  q  + t >  5 / w ) && !(  q >= t)
     ( 3 +  1   < -2*3 || 2 * -2  + 1 >  5 / 3 ) && !( -2 >= 1)
     (   4      < -6   ||  -4     + 1 >  1     ) && !( -2 >= 1)
                                               false             

I would mark both of the following as completely wrong altho' you may at first think "Hey! One's for sure right!" Can you see why? No work has been shown, just substitution of values.
iii) ( 3 +  1   < -2*3 || 2 * -2  + 1 >  5 / 3 ) && !( -2 >= 1)
                                               true    


 iv) ( 3 +  1   < -2*3 || 2 * -2  + 1 >  5 / 3 ) && !( -2 >= 1)
                                               false