Section 3.10 Check Point Questions12 questions
3.10.1
Assuming that x is 1, show the result of the following Boolean expressions.
(true) && (3 > 4) !(x > 0) && (x > 0) (x > 0) || (x < 0) (x != 0) || (x == 0) (x >= 0) || (x < 0) (x != 1) == !(x == 1)
3.10.2
(a) Write a Boolean expression that evaluates to true if a number stored in variable num is between 1 and 100.
(b) Write a Boolean expression that evaluates to true if a number stored in variable num is between 1 and 100 or the number is negative.
(b) Write a Boolean expression that evaluates to true if a number stored in variable num is between 1 and 100 or the number is negative.
3.10.3
(a) Write a Boolean expression for |x - 5| < 4.5.
(b) Write a Boolean expression for |x - 5| > 4.5.
(b) Write a Boolean expression for |x - 5| > 4.5.
3.10.4
To test whether x is between 10 and 100, which of the following expressions are correct?
(a) 100 > x > 10 (b) (100 > x) && (x > 10) (c) (100 > x) || (x > 10) (d) (100 > x) and (x > 10) (e) (100 > x) or (x > 10)
3.10.5
Are the following two expressions the same?
(a) x % 2 == 0 && x % 3 == 0 (b) x % 6 == 0
3.10.6
What is the value of the expression x >= 50 && x <= 100
if x is 45, 67, or 101?
3.10.7
Suppose, when you run the following program, you enter the input 2 3 6 from the console. What is the output?
#include <iostream> using namespace std; int main() { double x, y, z; cin >> x >> y >> z; cout << "(x < y && y < z) is " << (x < y && y < z) << endl; cout << "(x < y || y < z) is " << (x < y || y < z) << endl; cout << "!(x < y) is " << !(x < y) << endl; cout << "(x + y < z) is " << (x + y < z) << endl; cout << "(x + y > z) is " << (x + y > z) << endl; return 0; }
3.10.8
Write a Boolean expression that evaluates to true if age is
greater than 13 and less than 18.
3.10.9
Write a Boolean expression that evaluates to true if weight is greater than 50 pounds or height is greater than 60 inches.
3.10.10
Write a Boolean expression that evaluates to true if weight is greater than 50 pounds and height is greater than 60 inches.
3.10.11
Write a Boolean expression that evaluates to true if either weight is greater than 50 pounds or height is greater than 60 inches, but not both.
3.10.12
How do you simplify the Boolean expression in lines 16-17 in Listing 3.5 using the != operator?