Learn to Program using Alice

Practice Test for the Lesson Titled

Arrays

Published:  June 30, 2007
By Richard G. Baldwin

File: Alice0180PracticeTest.htm


Questions

1.  After the execution of the code in Listing 16, what does idx contain?

Listing 1. 180-116.
public void main ( ) {
  Number[] myArray = [5,7,3,10,2]; Number x = 0 ; 
  Number y = 0 ; Number idx = 0 ;
  for (int index=0;index < (myArray.length);index++){
    x.set( value , ( myArray [ index ] ) );
    if ( ( x > y ) ) {
      idx .set( value , index );
      y .set( value , x );
    } else {
      Do Nothing
    }
  }
  print( idx );
  print( y );
}

Answer and Explanation

2.  If score is an array containing 5 values, in the following order: 80, 75, 90, 60, 100, what is the content of score[1] ?

Answer and Explanation

3.  An array is a collection of values:

Answer and Explanation

4.  Which of the following would be used to store a list of 50 test scores?

Answer and Explanation

5.  In an array, we access the data value we are searching for by its

Answer and Explanation

6.  True or False:  Arrays can be used as data structures or containers for data of any valid Alice type.

Answer and Explanation

7.  True or False:  Whenever you need to use the data contained in an array in your program, you drag the array tile up from the bottom of the code edit pane and drop it into the edit pane.

Answer and Explanation

8.  True or False:  If the declared type of an Alice array is Object, the individual objects that are stored in the array can include a variety of different kinds of objects such as penguins, monkeys, lemurs, ladybugs, kangaroos, the camera, the light, the ground, etc.

Answer and Explanation

9.  True or False:  You can mix elements of type Boolean with type Number in an Alice array.

Answer and Explanation

10.  True or False:  Each variable in an array is commonly called an element.

Answer and Explanation

11.  True or False:  Each element in an array has a subscript or index that differentiates it from every other element in the array.  (Some people call it a subscript while others call it an index.)

Answer and Explanation

12.  True or False:  An array index is negative integer that indicates the position of a particular element relative to the first element in the array.  The first element in the array always has an index value of 0.

Answer and Explanation

13.  True or False:  It is not necessary to declare an array before you can use it.  Arrays are created automatically by the Alice runtime system when needed.

Answer and Explanation

14.  True or False:  You specify the number of elements (the size) of an array when you declare it.  Once created, the size of an array cannot be changed at runtime.

Answer and Explanation

15.  True or False:  If the size of the array is N, the index values for the elements in the array always extend from 0 to N inclusive

Answer and Explanation

16True or False:  You access an individual element in an array by:

Answer and Explanation

17True or False:  If you attempt to access an array element at an index value that is equal to or larger than the size of the array, the program will abort with an error at runtime.  Similarly, if you attempt to access an array element using a negative index, the program will abort with an error at runtime.

Answer and Explanation

18True or False:  Once an array element is populated, it is impossible to remove the contents of the element.  If you don't want those contents to be there, you must overwrite those contents with something else.

Answer and Explanation



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.

Answers and Explanations


Answer 18

True

Explanation 18

Back to Question 18


Answer 17

True

Explanation 17

Back to Question 17


Answer 16

True

Explanation 16

Back to Question 16


Answer 15

False

Explanation 15

Back to Question 15


Answer 14

True

Explanation 14

Back to Question 14


Answer 13

False

Explanation 13

Back to Question 13


Answer 12

False

Explanation 12

Back to Question 12


Answer 11

True

Explanation 11

Back to Question 11


Answer 10

True

Explanation 10

Back to Question 10


Answer 9

False

Explanation 9

Back to Question 9


Answer 8

True

Explanation 8

Back to Question 8


Answer 7

False

Explanation 7

Back to Question 7


Answer 6

True

Explanation 6

Back to Question 6


Answer 5

C. subscript or index

Explanation 5

Back to Question 5


Answer 4

D. an array

Explanation 4

Back to Question 4


Answer 3

C. with a common name and identical data types, but each with a unique index associated with it, which is used to uniquely identify it.

Explanation 3

Back to Question 3


 

Answer 2

C. 75

Explanation 2

Back to Question 2


Answer 1

C. idx contains the subscript of the largest element in the array.

Explanation 1

Back to Question 1


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-