Published: June 19, 2007
By Richard G. Baldwin
File: Alice0165PracticeTest.htm
1. What is the value of x after the code in Listing 165-101 is executed? (Hint: ignore the word times. It is misleading.)
Listing 165-101.
public void main ( ) { Number x = 0 ; for (int index=2; index< 7 times ; index++) { x .set( value , ( ( x + index ) ) ); } print( x ); } |
2. The loop shown in Listing 165-102:
Listing 165-102.
public void main ( ) { Number count = 1 ; Number sum = 0 ; while ( ( count < 10 ) ) { sum .set( value , ( ( sum + count ) ) ); count .set( value , ( ( count + 1 ) ) ); } } |
3. You have designed a program and have a number of steps which must be executed multiple times. What is the program control structure most likely to be used to do this?
4. True or False: Structured programming is not important in modern computer programming.
5. True or False: Any programming logic problem can be solved using an appropriate combination of only three programming structures.
6. True or False: The three structures required by structured programming are known generally as:
7. True or False: In structured programming, a section of program code must have only one entry point, but there may be multiple exit points.
8. True or False: In structured programming, structures may be nested inside of other structures provided that every structure meets the basic rules for a structure.
9. True or False: The general requirement for the sequence structure is that one or more actions may be performed in sequence after entry and before exit.
10. True or False: In a sequence structure, one or more of the action elements may themselves be sequence, selection, or loop structures.
11. True or False: The selection or decision structure can be described as shown in the pseudocode in Figure 165-11.
Figure 165-11. The selection structure in pseudocode.
Enter Test a condition for large or small On large Take one or more actions in sequence On small Take none, one, or more actions in sequence Exit |
12. True or False: For a selection structure, when all of the actions for a chosen branch have been completed in sequence, control is transferred to the other branch of the selection structure.
13. True or False: For a selection structure, it is often the case that no action is required when the test returns false. In that case, control simply exits the structure without performing any actions.
14. True or False: The loop or iteration structure can be described as shown in the pseudocode in Figure 165-14.
Figure 165-14. The loop structure in pseudocode.
Enter Test a condition for true or false Exit on false On true Perform one or more actions in sequence. Go back and test the condition again |
There is only one entry point and one exit point for a loop structure.
15. True or False: For a loop structure, unless something is done in one of the actions in the body of the loop to cause the test to eventually return false, control will never exit the loop.
In this case, the program will be caught in what is commonly referred to as a finite loop.
16. True or False: In some programming languages, there are a couple of structures other than sequence, selection, and loop that structured-programming experts are willing to accept for convenience:
These structures are not required for the solution of programming logic problems. Also, they are not support by Alice 2.0.
17. True or False: To create a selection structure in Alice, begin by dragging the if tile from the object tree and dropping it at the appropriate location in the edit pane.
18. True or False: When constructing a selection structure in Alice 2.0, the expression that you place in the conditional clause is the expression that will be evaluated to determine which part of the selection structure to execute. If the expression in the conditional clause evaluates to true, the code between the curly braces before the else clause will be executed. If the expression in the conditional clause evaluates to false, the code in the body of the else clause will be executed.
19. True or False: To create a while loop structure in Alice, begin by dragging the loop tile from the bottom of the Alice development screen and dropping it at the appropriate location in the edit pane.
20. True or False: As is the case with a selection structure, a loop structure has a conditional clause.
21. True or False: Once the skeleton for a loop structure appears in your Alice code, you can replace the placeholder value with any expression that will evaluate to a value of type Number.
22. True or False: The expression that you place in the conditional clause of a loop structure is the expression that will be evaluated to determine if the code in the body of the loop structure (the code between the curly braces) will be executed one time, or if the loop structure will terminate.
23. True or False: If the expression in the conditional clause of a while loop structure evaluates to false, the code in the body of the loop will be executed once. If the expression in the conditional clause evaluates to true, the loop will terminate immediately causing the code in the body of the loop to be skipped and causing the next statement following the body of the loop to be executed.
24. True or False: The purpose of a priming read is to get the first input value before entering the loop so that the value can be used to determine the behavior of the loop during the first iteration.
25. True or False: A while loop is known as a pre-test or entry-condition loop. This is because the conditional test is performed before the code in the body of the loop is executed. If the test returns false the first time that it is performed, the code in the body of the loop won't be executed.
Other programming languages such as Java, C++, and C# also have an exit-condition loop, known as a do-while loop. The major significance of the exit-condition loop is that the code in the body of the loop will be executed at least once, even if the test returns false the first time that it is performed. This is because the test is performed after the body of the loop has already executed once.
Alice does not have an exit-condition loop.
26. True or False: If you drag the loop tile (instead of the while tile) from the bottom of the Alice development screen and drop it into the edit pane, a for loop will be created. A for loop is an exit-condition loop. The code in the body of the loop will continue to execute for as long as the conditional clause evaluates to true.
Copyright 2007, Richard G. Baldwin.
Faculty and staff of public and private non-profit educational institutions are
granted a license to reproduce and to use this material for purposes consistent
with the teaching process. This license does not extend to commercial
ventures. Otherwise, reproduction in whole or in part in any form or medium
without express written permission from Richard Baldwin is prohibited.
The following image is the splash screen from Alice 2.0, and is the property of the developers of Alice at Carnegie Mellon.
Copyright 2007, Richard G. Baldwin. Faculty and staff of public and private non-profit educational institutions are granted a license to reproduce and to use this material for purposes consistent with the teaching process. This license does not extend to commercial ventures. Otherwise, reproduction in whole or in part in any form or medium without express written permission from Richard Baldwin is prohibited.
The following image is the splash screen from Alice 2.0, and is the property of the developers of Alice at Carnegie Mellon.
-end-