< previous page page_245 next page >

Page 245
7. The following expressions make sense but are invalid according to C++'s rules of syntax. Rewrite them so that they are valid logical expressions. (All the variables are of type int.)
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
a. x < y <= z
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
b. x, y, and z are greater than 0
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
c. x is equal to neither y nor z
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
d. x is equal to y and z
8. Given these values for Boolean variables x, y, and z:
x = TRUE, y = TRUE, z = FALSE
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
indicate whether each expression is TRUE (T) or FALSE (F).
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
______ a. ! (y | | z) | | x
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
______ b. z && x && y
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
______ c. ! y | | (z | | !x)
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
______ d. z | | (x && (y | | z))
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
______ e. x | | x && z
9. For each of the following problems, decide which is more appropriate, an If-Then-Else or an If-Then. Explain your answers.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
a. Students who are candidates for admission to a college submit their SAT scores. If a student's score is equal to or above a certain value, print a letter of acceptance for the student. Otherwise, print a rejection notice.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
b. For employees who work more than 40 hours a week, calculate overtime pay and add it to their regular pay.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
c. In solving a quadratic equation, whenever the value of the discriminant (the quantity under the square root sign) is negative, print out a message noting that the roots are complex (imaginary) numbers.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
d. In a computer-controlled sawmill, if a cross section of a log is greater than certain dimensions, adjust the saw to cut 4-inch by 8-inch beams; otherwise, adjust the saw to cut 2-inch by 4-inch studs.
10. What causes the error message UNEXPECTED ELSE when this code fragment is compiled?
if (mileage < 24.0)
{
    cout << Gas ;
    cout << guzzler.;
};
else
    cout << Fuel efficient.;
11. The following code fragment is supposed to print Type AB when Boolean variables typeA and typeB are both TRUE, and print Type O when both variables are FALSE. Instead, it prints Type O whenever just one of the variables is FALSE. Insert a { } pair to make the code segment work the way it should.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
if (typeA || typeB)
    if (typeA && typeB)
        cout << Type AB;
else
    cout << Type O;

 
< previous page page_245 next page >