Learn to Program using Alice

Practice Test for the Lesson Titled

Relational and Logical Operators

Published:  June 25, 2007
By Richard G. Baldwin

File: Alice0170PracticeTest.htm


Questions

1.  What is the value of C after the code in Listing 170-110 is executed? 

Listing 170-110.
public void main ( ) {
  Number A = 5 ; Number B = 5 ; Number C = 0 ;
  if ( ( A >= B ) ) {
    if ( ( A > B ) ) {
      C .set( value , 1 );
    } else {
      C .set( value , 2 );
    }
  } else {
    C .set( value , 3 );
  }
  print( C );
}
 

Answer and Explanation

2.  Given the code in Listing 170-111, what is the range of the value of the variable result that is displayed after the while loop has finished executing?

Listing 170-111.
public void main ( ) {
  Number number = 0 ; Number result = 0 ;
  number.set(value,(NumberDialog(question=Enter num)));
  while ( ( ( ( number < 0 ) || ( number > 100 ) ) ) ) {
    number.set(value,(NumberDialog(question=Enter num))));
  }
  result .set( value , number );
  print( result );
}
 

Answer and Explanation

3.  Assume x and y are Boolean variables.  If x has the value true, and y has the value false, which of the following expressions evaluates to true?

Answer and Explanation

4.  True or False:  The following operators with the symbols given are supported by Alice:

  1. Less than:  <
  2. Greater than:  >
  3. Less than or equal to:  <=
  4. Greater than or equal to:  >=
  5. Logical AND:  &
  6. Logical inclusive OR:  ||
  7. Logical NEGATION:  !

Answer and Explanation

5.  True or False:  Operators 1 through 4 in the following list are relational operators.  Operators 5 through 7 in the list are combinational logic operators.

  1. Less than:  <
  2. Greater than:  >
  3. Less than or equal to:  <=
  4. Greater than or equal to:  >=
  5. Logical AND:  &&
  6. Logical inclusive OR:  ||
  7. Logical NEGATION:  !

Answer and Explanation

6.  True or False:  Assume that A and B are numeric variables or expressions that evaluate to numeric values.  The expression (A < B) will evaluate to true if A is algebraically less than B, and will evaluate to false otherwise.

Answer and Explanation

7.  True or False:  Assume that A and B are numeric variables or expressions that evaluate to numeric values.  The expression (A > B) will evaluate to true if A is algebraically less than B, and will evaluate to false otherwise.

Answer and Explanation

8.  True or False:  Assume that A and B are numeric variables or expressions that evaluate to numeric values.  The expression (A <= B) will evaluate to true if A is algebraically less than or is equal to B, and will evaluate to false otherwise.

Answer and Explanation

9.  True or False:  Assume that A and B are numeric variables or expressions that evaluate to numeric values.  The expression (A >= B) will evaluate to true if A is algebraically less than or is equal to B, and will evaluate to false otherwise.

Answer and Explanation

10.  True or False:  Assume that A and B are numeric variables or expressions that evaluate to numeric values.  The expression (A == B) will evaluate to true if A is equal to B, and will evaluate to false otherwise.

Answer and Explanation

11.  True or False:  Assume that A and B are numeric variables or expressions that evaluate to numeric values.  The expression (A != B) will evaluate to true if A is equal to B, and will evaluate to false otherwise.

Answer and Explanation

12.  True or False:  Assume that X and Y are Boolean variables or expressions that evaluate to the Boolean values of true and false.  The expression (X && Y) will evaluate to true if both X and Y are true, and will evaluate to false otherwise.

Answer and Explanation

13.  True or False:  Assume that X and Y are Boolean variables or expressions that evaluate to the Boolean values of true and false.  The expression (X || Y) will evaluate to true if both X and Y are true, and will evaluate to false otherwise.

Answer and Explanation

14.  True or False:  If X is true, !X evaluates to false. 

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 14

True

Explanation 14

Back to Question 14


Answer 13

False

Explanation 13

Back to Question 13


Answer 12

True

Explanation 12

Back to Question 12


Answer 11

False

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

True

Explanation 5

Back to Question 5


Answer 4

False Logical AND:  & is not the correct symbol.

Explanation 4

Back to Question 4


Answer 3

A. !(x && y)

Explanation 3

Back to Question 3


 

Answer 2

C. result contains a value between 0 and 100, inclusive (that is, result is 0 or 100 or any value between 0 and 100).

Explanation 2

Back to Question 2


Answer 1

B. 2

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-