|
|
|
|
|
|
|
12. The nested If structure below has five possible branches depending on the values read into char variables ch1, ch2, and ch3. To test the structure, you need five sets of data, each set using a different branch. Create the five test data sets. |
|
|
|
 |
|
|
|
|
cin >> ch1 >> ch2 >> ch3;
if (ch1 == ch2)
if (ch2 == ch3)
cout << All initials are the same. << endl;
else
cout << First two are the same. << endl;
else if (ch2 == ch3)
cout << Last two are the same. << endl;
else if (ch1 == ch3)
cout << First and last are the same. << endl;
else
cout << All initials are different. << endl; |
|
|
|
 |
|
|
|
|
a. Test data set 1: ch1 =____ ch2 =_____ ch3 =_____ |
|
|
|
 |
|
|
|
|
b. Test data set 2: ch1 =_____ ch2 =_____ ch3 =_____ |
|
|
|
 |
|
|
|
|
c. Test data set 3: ch1 =_____ ch2 =_____ ch3 =_____ |
|
|
|
 |
|
|
|
|
d. Test data set 4: ch1 =_____ ch2 =_____ ch3 =_____ |
|
|
|
 |
|
|
|
|
e. Test data set 5: ch1 =_____ ch2 =_____ ch3 =_____ |
|
|
|
|
|
|
|
|
13. If x and y are Boolean variables, do the following two expressions test the same condition? |
|
|
|
 |
|
|
|
|
x != y
(x | | y) && ! (x && y) |
|
|
|
|
|
|
|
|
14. The following If condition is made up of three relational expressions: |
|
|
|
 |
|
|
|
|
if (i >= 10 && i <= 20 && i != 16)
j =4; |
|
|
|
 |
|
|
|
|
If i contains the value 25 when this If statement is executed, which relational expression(s) will the computer evaluate? (Remember that C++ uses short-circuit evaluation.) |
|
|
|
|
|
|
|
|
Programming Warm-up Exercises |
|
|
|
|
|
|
|
|
1. Declare eligible to be a Boolean variable, and assign it the value TRUE. |
|
|
|
|
|
|
|
|
2. Write a statement that sets the Boolean variable available to TRUE if numberOrdered is less than or equal to numberOnHand minus numberReserved. |
|
|
|
|
|
|
|
|
3. Write a statement containing a logical expression that assigns TRUE to the Boolean variable isCandidate if satScore is greater than or equal to 1100, gpa is not less than 2.5, and age is greater than 15. Otherwise, isCandidate should be FALSE. |
|
|
|
|
|
|
|
|
4. Given the declarations |
|
|
|
 |
|
|
|
|
Boolean leftPage;
int pageNumber; |
|
|
|
|
|