Review and Reinforcement: Selection Structures
Tom Kelliher, CS18
Feb. 9, 1996
-
How are the notions of true and false defined in C/C++?
-
What structure do we use in order ``to do, or not to do?''
Example: If the account balance is negative, penalize the account.
-
What structure do we use to choose between two alternatives?
Example: If the grade is greater than or equal to 60, print PASSED,
otherwise print FAILED.
-
What structure do we use to choose between multiple alternatives?
Example: If the day number is one, print Monday, if the day number is
two, print Tuesday, etc.
What roles can the final else play?
-
Write an if/ else to print OK if i is in the range 0
to 10, inclusive and print Whoops! otherwise.
-
What is printed by each of the following?
1) if (50 <= 65 <= 60)
cout << "True" << endl;
else
cout << "False" << endl;
2) i = 0;
if (i = 3)
cout << "True" << endl;
else
cout << "False" << endl;
3) i = 0;
if (!(i = 3) == 1)
cout << "True" << endl;
else
cout << "False" << endl;
Truth tables for single, multiple &&'s and ||
's, !.
In what subtle, but important, ways does a switch differ from a
multiway if/ else?
- Numeric vs. ``boolean'' condition
- Case label vs. complex conditions
- Fall-Through
- default vs. else
Consider converting numerics grades to letter grades. Compare and contrast
the two multiway selection structures.
- Login through Novell
- Start netscape (Web Explorer in the other two labs)
- Using my URL, go to my home page and then navigate to the page for
CS18.
- Find and print the homework assignment.
- Find the compiler, enter and run a simple program (any one will do),
try saving it to your N drive.
Thomas P. Kelliher
Thu Feb 8 09:40:21 EST 1996
Tom Kelliher