< previous page page_244 next page >

Page 244
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
cout << I'm;
if (i >= m)
    cout << Cow;
else
    cout << Adam;
4. Given the int variables x, y, and z, where x is 3, y is 7, and z is 6, what is the output from each of the following code fragments?
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
a. if (x <= 3)
       cout << x + y << endl;
   cout << x + y << endl;
b. if (x != -1)
       cout << The value of x is  < x << endl;
   else
       cout << The value of y is  < y << endl;
c. if (x != -1)
   {
       cout << x  endl;
       cout << y << endl;
       cout << z << endl;
   }
   else
       cout << y << endl;
       cout << z << endl;
5. Given this code fragment:
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
if (height >= minHeight)
    if (weight >= minWeight)
        cout << Eligible to serve. << endl;
    else
        cout << Too light to serve. << endl;
else
    if (weight >= minWeight)
        cout << Too short to serve. << endl;
    else
        cout << Too short and too light to serve. << endl;
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
a. What is the output when height exceeds minHeight and weight exceeds minWeight?
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
b. What is the output when height is less than minHeight and weight is less than minWeight?
6. Match each logical expression in the left column with the logical expression in the right column that tests for the same condition.
______ a. x < y && y < z
(1) ! (x ! = y) && y == z
______ b. x > y && y >= z
(2) ! (x <= y &bbar;&bbar;y < z)
______ c. x != y &bbar;&bbar; y ==z
(3) (y < z)&bbar;&bbar;y == z)
______ d. x == y &bbar;&bbar; y <=z
(4) ! (x >= Y) & & ! (y >= z)
______ e. x == y && y == z
(5) ! (x == y && y != z)

 
< previous page page_244 next page >