a. What are the design issues associated with selection statements.
b. Draw an UML class diagram of the concepts involved in a two-way selection statement using "Condition" and "Statement" as given classes. [Note].
b. Draw an UML class diagram of the concepts involved in a multiple selection statement using "Expression" and "Statement" as given classes[Note].
b. Draw an UML class diagram of the concepts involved in a counter-controlled loop statement using "Variable", "Expression", and "Statement" as given classes.[Note].
b. What is the definition of a block?
c. Use a UML class diagram with statement, compound statement and block that indicates the relationships and differences between blocks and compound statements. [Note]
a. Give an example of a pretest loop statement and a post-test loop statement in a language and name the language.
b. What is the general form of a pretest loop in your language?
c. Show that any post-test loop in this language above can be re-programmed using a pretest loop.
d. Draw a UML class diagram of the relationship between statements, loops, pretest loops, and post-test loops[Note].
Note. The final may ask you to give a general pre-test loop and re-program it using a post-test loop, or perhaps express a counter controlled loop as a conditional loop, or even a two way selection as a multi-way selection, or vice versa.
The general form of a pretest loop in these languages is
while( condition ) statement
and the general from of a post-test loop is
do
statement
while (condition)
The post loop form executes it's statement at least once. Then it tests to see if any repetitions are needed.
To get the same effect as
while( C ) Swrite
if (C) do
S
while ( C )which reinserts the extra test of the condition.
Similarly to show that any post-test loop in C/C++/Java can be re-programmed using a pretest loop you write.
To get the effect of
do S while(C)by using a post-test loop use
S
while(C) S
Similarly with 'if' and 'switch'.
You can also reprogram all of these structures using only if, goto, and lots of labels. Can you figure out what this is:
L: S;
if( C ) goto L;where L is a label and C a condition.