[Skip Navigation] [CSUSB] / [CNS] / [CSE] / [R J Botting] /[CS320 Course Materials] /09q.html [09q.txt(Text)] [Search ]
Tue Apr 30 16:10:09 PDT 2013
[Schedule] [Syllabi] [Text] [Labs] [Projects] [Resources] [Grading] [Contact]
Notes: [01] [02] [03] [04] [05] [06] [07] [08] [09] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20]

Contents


    CS320/09 Questions on Statements - Chapter 8

      Question 1 Selection Statements

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

      Question 3 Multiple Selection Statements

      a. List design issues for multiple selection statements.

      b. Draw an UML class diagram of the concepts involved in a multiple selection statement using "Expression" and "Statement" as given classes[Note].

      Question 2 Counter controlled Loops

      a. What are the design issues associated counter-controlled loop statements.

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

      Question 4 Compound Statements

      a. What is the definition of a compound statement?

      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]

      Question 5 Pretest and Post-test Loops

      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.

      Question 6 Syntax for Control Structures

      List, briefly the Pros(+) and Cons(-) of using unique closing reserved words (like END IF or FI in Algol 68 and Ada) to delimit compound statements and control structures rather than the same ones (END or "}" in Pascal and C/C++/Java).

      Review how well you did these exercises and think about how much revision you will need for the final

      Note

      You can fit all the UML diagrams above into one model and express the semantics by defining an execute() operation for each class of statement. To complete the formal semantics you would have to use the Object Constraint Language to define precisely how the various classes of statements are executed. Most real language reference manuals rely on "hand waving" -- informal comments and appeals to common sense.

      Project Questions

      In your new language what control structures do you have? How do you resolve the design issues and options for these control structures? Do your choices match the goals for your language?

      Answer 5c

    1. Show that any post-test loop in C/C++/Java can be re-programmed using a pretest loop.

      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 ) S
      write
       	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.

    Review how you did in class

    Do you need to go over this before the final?

( End of document ) <<Contents | Top