Kamis, 27 Juni 2013

Concepts of Programming Languages Assignment - Chapter 8

Review Questions

2. What did Bohm and Jocopini prove about flowcharts?
It was proven that all algorithms that can be expressed by flowcharts can be coded in a programming languages with only two control statements: one for choosing between two control flow paths and one for logically controlled iterations.

3. What is the definition of block?
In Ruby, block is a sequence of code, delimited by either breves or the do and and reserved words.

4. What is/are the design issue(s) for all selection and iteration control statements?
There is only one design issue that is relevant to all of the selection and iteration control statements: Should the control structure have multiple entries?

7. Under what circumstances must an F# selector have an else clause?
An F# selector have an “else” clause if  the “if” expression does return a value.

9. What are the design issues for multiple-selection statements?
What is the form and type of the expression that controls the selection?
How are the selectable segments specified?
How are the case values specified?
How should unrepresented selector expression values be handled, if at all?
Is execution flow through the structure restricted to include just a single selectable segment?

14.  What are the design issues for all iterative control statements?
How is the iteration controlled?
Where should the control mechanism appear in the loop statement?

15.  What are the design issues for counter-controlled loop statements?
What are the type and scope of the loop variable?
Should it be legal for the loop variable or loop parameters to be changed in the loop, and if so, does the change affect loop control?
Should the loop parameters be evaluated only once, or once for every iteration?

21.  What are the design issues for logically controlled loop statements?
Should the control be pretest or post-test?
Should the logically controlled loop be a special form of a counting loop or a separate statement?

23.  What are the design issues for user-located loop control mechanisms?
Should the conditional mechanism be an integral part of the exit?
Should only one loop body be exited, or can enclosing loops also be exited?

Problem Set
1. What design issues should be considered for two-way selection statements?
The design issues for two-way selectors can be summarized as follows:
• What is the form and type of the expression that controls the selection?
• How are the then and else clauses specified?
• How should the meaning of nested selectors be specified?

4. What are the limitations of implementing a multiple selector from two-way selectors and gotos?
A multiple selector can be built from two-way selectors and gotos, but the resulting
structures are cumbersome, unreliable, and difficult to write and read.

5. What are the arguments pro and con, for Java’s approach to specify compound statements in control statements?
• Compound statements are required in control statements when the body of the if
or else clause requires multiple statements.
• Java uses braces to form compound statements, which serve as the bodies of if
and else clauses.

9. Boolean expressions are necessary in the control statements in Java, as opposed to also allowing arithmetic expressions, as in C++. Give a conditional statement that is correct in C++ but not in Java.
int i=10;
if( i )
{
// block of statements
}
This block of statement is valid in C++ but not in Java.

11. Explain the advantages and disadvantages of the Java switch statement, compared to C++’s switch statement.
The Java variable in the argument of a switch statement can be of type integral ( byte,
short etc.), char and String( JDK 1.7 onwards), whereas in C++ the argument can be int
or char.

Tidak ada komentar:

Posting Komentar