Review and Reinforcement: Selection Structures

Tom Kelliher, CS18

Feb. 9, 1996

if, else

  1. How are the notions of true and false defined in C/C++?

  2. What structure do we use in order ``to do, or not to do?''

    Example: If the account balance is negative, penalize the account.

  3. 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.

  4. 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?

  5. Write an if/ else to print OK if i is in the range 0 to 10, inclusive and print Whoops! otherwise.

  6. What is printed by each of the following?
    1)    if (50 <= 65 <= 60)
             cout << "True" << endl;
             cout << "False" << endl;

    2)    i = 0;
          if (i = 3)
             cout << "True" << endl;
             cout << "False" << endl;
    3)    i = 0;
          if (!(i = 3) == 1)
             cout << "True" << endl;
             cout << "False" << endl;

Boolean Operations

Truth tables for single, multiple &&'s and ||'s, !.


In what subtle, but important, ways does a switch differ from a multiway if/ else?

Consider converting numerics grades to letter grades. Compare and contrast the two multiway selection structures.

Lab ``Try-Out''

  1. Login through Novell
  2. Start netscape (Web Explorer in the other two labs)
  3. Using my URL, go to my home page and then navigate to the page for CS18.
  4. Find and print the homework assignment.
  5. 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