Rabu, 26 Juni 2013

Chap 8 - Review Question and Problem Set - Concepts of Programming Languages, Sebesta

CONCEPTS OF
PROGRAMMING LANGUAGES
TENTH EDITION
Robert W. Sebesta
Chapter 8 - Statement-Level Control Structure

Review Question
1. What is the definition of control structure?
Answer: A control structure is a pack of control statement and collection of statements that control its execution.

2. What did Bohm and Jocopini prove about flowcharts?
Answer: Bohm and Jocopini could prove that all algorithms can be expressed by flowchart and alson can be coded in a programming language with only two control statement (choosing between two control and logically controlled iteration)

3. What is the definition of block?
Answer: Block is a squence of code or reserved word that is used by the programmer to give an istruction.

5. What are the design issues for selection structures?        

The design issues for selection structures are:
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?


9. What are the design issues for multiple-selection statements?
Answer:
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?
Answer:
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?
Answer:
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?

20. What contemporary languages do not include a goto?
Answer:
Java language is the contemporary language that doesn’t include a goto.

21. What are the design issues for logically controlled loop statements?
Answer:
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?
Answer:
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?
Answer:
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?

11. Explain the advantages and disadvantages of the Java switch statement, compared to C++’s switch statement.
Answer: Integral ( byte, short etc.), char and String data types can be used as an argument in Java's switch statement, in the other hand in C++ the argument can be int or char.

14. State one of the main legitimate needs for gotos.
Answer: To make a loop exit statement.

Special thanks to Mr. Tri Djoko Wahjono, Ir., M.Sc.

Tidak ada komentar:

Posting Komentar