Thursday, June 27, 2013

Concepts of Programming Languages Chapter 8


Concepts of Programming Languages Chapter 8


Name            : Erland
NIM              : 1601218035
Lecturer       : Tri Djoko Wahjono, Ir., M.Sc. (D0206)
Assignment  : Concept of programming languages Chapter 8

Review Questions


       1.  What is the definition of control structure ?
             Answer : Structure is a control statement and the collection of statements 
                              whose execution it controls.

       2. What did Bohm and Jocopini prove about flowcharts?
            Answer : They proved 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 definition of block?
             Answer : Block is sequence of code, deliminated by either braces or the 
                              do and end reserved words.

       4. What are the design issues for all selection and iteration control statements?
             Answer : 
1. Selection statements:
– what are the form and type of the expression that control the selection?
– how are the then and else clauses specifies? 
– how should the meaning of the nested selectors be specified?
2. Iteration control statement: 
– 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 evaluatedby only once or once for every iteration?

       5. What are the design issues for selection structures?  
             Answer : 
- 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?

        6. What is unusual about Phyton designs of compound statement?
             Answer:
Many languages use braces to form compound statements, which serve as the body of then and else clause. In Phyton, the then and else clauses are statement sequences, rather than compound statements. The complete selection statement is terminated in these languages eith reserved words. Phyton uses indentation to specify compound statements.


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

        8. What are the common solution to the nesting problem for two way selector?
             Answer : The common solution to the nesting problem is to use alternating 
                              means of forming a compound statements.


         9. What are the design issues for multiple selection statement?
             Answer : 
– what is the form and type of the expression that controls the selection?– how are the selectable segments specified?– is the flow through the structure restricted to include just a single selectable segment? – how are the case values specified? – how should unpresented selectors expressions values be handled, if at all?
           11. What is unusual about the C’s multiple selection statement?
                 Answer : 
The C switch statement has virtually no restrictions on the placement of the case expressions, which are treated as if they were normal statement labels. This laxness can result in highly complex structure eithin the switch body. 
12. On what previous language was C’s switch statement based?
       Answer :
The ability to have control flow from one selectable segment to another is rarely used. C’s switch is modeled on the multiple-selection statement in ALGOL