Chapter 8 Programming Languages

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

What contemporary languages do not include a goto?

Java language is the contemporary language that doesn't include a goto, the loop bodies cannot be entered anywhere but at their beginning.

In a letter to the editor of CACM, Rubin (1987) uses the following code segment as evidence that the readability of some code with goats is better than the equivalent code without goats. This code finds the first row of an n by n int matrix named x that has nothing but zero values. for (i = 1; 1 <= n; i++) { for (j = 1; j <= n; j++) if (x[i][j] != 0) goto reject; println ('First all zero row is: ', i); break; reject: }

C++ for (i = 1; i <= n; i++) { flag = 1; for (j = 1; j <= n; j++) if (x[i][j] <> 0) { flag = 0; break; } if (flag == 1) { printf ("First all zero row is: %d\n", i); break; } }

Explain the advantages and disadvantages of the Java for statement, compared to Ada's for.

Java's for construct, like that of the other C based languages, is far more flexible than than that of Ada. On the other hand, Ada's for construct is far less error-prone than that of the C-based languages, largely bc of its relative simplicity.

What are the arguments, pro and con, for Python's use of indentation to specify compound statements in control statement?

One argument in favor of Python's use of indentation is that it demands that programmers use an indentation scheme that promotes readability. This results in a rigid standard for program layout that ensures that all Python programs will be equally readable. If indentation is good for readability, why not use it to indicate compound statements? It is difficult to find a strong argument against the use of indentation to indicate program structure, although sloppy programmers will find the required discipline annoying. Frustrating mixing tab and spaces. Decreasing writability

What is a pretest loop statement? What is a posttest loop statement?

Pretest loop statement is used to mean that the test for loop completion occurs before the loop body is executed. Posttest loop statement is used to mean that it occurs after the loop body is executed.

What are the design issues for all iterative control statements?

The design issues are how the iteration is controlled and where the control mechanism should appear in the loop statement.

What are the design issues for logically controlled loop statements?

The design issues are whether the control should be pretest/posttest and whether the logically controlled loop should be a special form of a counting loop or a separate statement.

What are the design issues for counter-controlled loop statements?

The design issues for counter-controlled loop statement are what the type and scope of the loop variable are, whether it should be legal for the loop variable or loop parameters to be changed in the loop and if so, whether the change affects loop control or not, and if the lop parameters should be evaluated only once or once for every iteration.

What is the difference between the for statement of C++ and that of Java?

The loop control expression in Java is restricted to boolean, unlike that of C++, even though the syntax is similar.

What are the arguments both for and against the exclusive use of Boolean expressions in the control statements in Java (as opposed to also allowing arithmetic expressions, as in C++)?

The primary argument for using Boolean expressions exclusively as control expressions is the reliability that results from disallowing a wide range of types for this use. In C, for example an expression of any type can appear as a control expression, so typing errors that result in references to variable of incorrect types are not detected by the compiler as errors. Con writability

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? Is the flow through the structure restricted to include just a single selectable segment? How are the case values specified? How should unprecedented selectors expressions values be handled, if at all?

What are the common solutions to the nesting problem for two way selectors?

A rule or a syntactic entity.

What did Bohm and Jocopini prove about flowcharts?

All algorithms that can be expressed by flowcharts can be coded in a programming language with only two control statements: one for choosing between two control flow paths and one for logically controlled iterations

What is the definition of block?

Block is sequence of code, deliminated by either braces or the do and end reserved words.

Explain how C#'s switch statement is safer than that of C.

C# has a static semantics rule that disallows the implicit execution of more than one segment. Every segment must end with an explicit unconditional branch statement which transfer control out of the switch statement, or a goto, which can transfer control to one of the selectable segments. Also, C#'s switch control expression and the case statements can be strings in C#.

rewrite using C++ and Python k = (j+ 13)/27 loop: if k > 10 then goto out k = k +1 i = 3*k-1 goto loop out: ....

C++ for (k = (j+13)/27; k <= 10; i = 3* (++k) -1)

Describe a programming situation in which the else clause in Python's for statement would be convenient.

Error handling

What are the design issues for selection structures?

For two way selectors: What s 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? For n-way: What is the form and type of the expression that controls the selection? How are the selectable segments specified? Is execution flow through the structure restricted to include just a single selectable segment? How are the case values specified? How should unrepresented selector expression values be handled, if at all?

What are the pros and cons of using unique closing reserved words on compound statements?

Unique closing keywords on compound statements have the advantage of readability and the disadvantage of complicating the language by increasing the number of keywords.

Definition of control structure?

is a control statement and the collection of statements whose execution it controls

Consider the following C program segment. Rewrite it using no goats or breaks. j = -3; for (i = 0; i < 3; i++) { switch (j + 2) { case 3: case 2: j--; break; case 0: j += 2; break; default: j = 0; } if (j > 0) break; j = 3-i; }

j = -3; for (i = 0; i < 3; i++) { temp = j +2; if (key == 3 || key == 2) j--; else if (key == 0) j+=2; else j = 0; if(j < 0) j = 3-i; }

Use a multiple selection statement for C++ to rewrite the code if ((k == 1) || (k== 2)) j = 2*k-1 if ((k==3)||(k==5)) j = 3*k+1 if (k ==4) j = 4* k=1 if ((k ==6) || (k == 7) || (k == 8)) j = k -2

switch (k) { case1: case 2: j = 2*k-1; break; case 3: case 5: j = 3 * k +1; break; case 4: j = 4 * k - 1; break; case 6: case 7: case 8: j = k -2; break; default: pritnf( "Error in switch, k = %d\n", k) }


संबंधित स्टडी सेट्स

Chap 44 Disorders of the Skeletal System: Metabolic and Rheumatic Disorders

View Set

Excel Tutorial 6: Managing Multiple Worksheets and Workbooks

View Set

Exam 4 (Assessment 4) Adult Health II

View Set

Circumference and Arc Length Assignment 100%

View Set

Econ 201M - Quiz 7: Chapter 24 Long Run Economic Growth

View Set