QUESTIONS AND CORRECT ANSWERS
Consider the following code segment.
Which of the following best describes the behavior of the code segment? - CORRECT
ANSWER The code segment displays the value of 2(53)2(53) by initializing result to 2 and
then multiplying result by 5 a total of three times.
In the following procedure, assume that the parameter x is an integer.
Which of the following best describes the behavior of the procedure? - CORRECT ANSWER It
displays true if x is negative and displays nothing otherwise.
Consider the following code segment, where exam and presentation are integer variables and grade is
a string variable.
IF((exam > 90) AND (presentation > 80))
{
grade ←
"A"
}
IF((exam > 80) OR (presentation > 75))
{
grade ←
"B"
}
ELSE
{
IF((exam > 70) OR (presentation > 60))
{
grade ←
"C"
}
ELSE
, {
IF(exam > 60)
{
grade ←
"D"
}
ELSE
{
grade ←
"F"
}
}
} - CORRECT ANSWER When the value of exam is 80 and the value of presentation is 60
The following code segment is used to determine whether a customer is eligible for a discount on a
movie ticket.
val1 ←← (NOT (category = "new")) OR (age ≥ 65)
val2 ←← (category = "new") AND (age < 12)
If category is "new" and age is 20, what are the values of val1 and val2 as a result of executing the
code segment? - CORRECT ANSWER val1 = false, val2 = false
Consider the following code segment.
What is displayed as a result of executing the code segment? - CORRECT ANSWER 100 300
500
Consider the following code segment.
Which of the following CANNOT be displayed as a result of executing the code segment? -
CORRECT ANSWER 1324
In the following procedure, the parameter max is a positive integer.
PROCEDURE printNums(max)
{