SAC EXAMPLE 3
Nested Selection Constructs
(NOTE: This does not implement the OOSD paradigm; see the last extension.)

The following SAC illustrates the simplest type of nested selection constructs, nesting under the "else" (false) branch.  (a) Do enough traces (using the simplest possible data) to test all possible cases of the algorithm represented by the SAC below.  (b) Complete the wording in the output symbols.  What does this algorithm do?

EXTENSIONS:

  1. Redraw this SAC with the first selection based on N > 0 and the second based on N = 0.  (b) Are this case and the original different algorithms or simply different expression of the same algorithm?
  2. This algorithm utilizes selection nested in the "else" (false) branch of another selection statement.  (a) Could an equivalent algorithm be designed using nesting under the "then" (true) branch?  (b) In general, what can be said of the categories selected via selections nested under the else branch?
  3. If the values input for N were Centigrade degrees, any value less than -273.15o would be erroneous data.  (a) Add an "error trap" that would cause the data to be ignored and a warning, "Error, value below absolute zero!", to be output.  (b) Would the error trap be any different if it were added to the version of the SAC given in Extension 1?
  4. If you wanted to classify numbers according to additional categories, how would they be incorporated in the SAC, i.e. nested or in sequence?  (b) On what would this depend?  (c) For example, modify the SAC so that, in addition to positive, negative, and zero, the numbers input would be classified as integer, fractions (e.g. 0.5), and mixed (e.g. 1.5).  (d) How about also classifying the numbers according to whether they are decimal, binary, octal, or hexidecimal?  Extend your SAC to incorporate this classification.  (e) Be sure to include error traps for each additional categorization. (f) Do you get the very important point of the destinction between if-then-elses in sequence and those that are nested?  Do you see how focusing on this helps "problem solving" in algorithm development and how SACs become "power tools" for this development (e.g. how they can be used experiment with different logical organizations)?  If not, don't worry; consider SAC EXAMPLE 4.
  5. If this algorithm were (inefficiently) designed using sequential if statements, how would the conditions have to be modified?  (b) Why would such an algorithm be inefficient?
  6. In general, sequential selections are _________________ and nested selections are ________________.
  7. How would the algorithms in this example be modified to represent OOSD?  (b) Would the different versions of this algorithm have different OOSD versions?