A programmer wrote the code segment below to display the average of all the elements in a list called numbers. There is always at least one number in the list.
Line 1: count ← 0
Line 2: sum ← 0
Line 3: FOR EACH value IN numbers
Line 4: {
Line 5: count ← count + 1
Line 6: sum ← sum + value
Line 7: average ← sum / count
Line 8: }
Line 9: DISPLAY (average)
The programmer wants to reduce the number of operations that are performed when the program is run. Which change will result in a correct program with a reduced number of operations performed?'
a. Interchanging line 1 and line 2
b. Interchanging line 5 and line 6
c. Interchanging line 6 and line 7
d. interchanging line 7 and line 8
D
Central High School keeps a database of information about each student, including the numeric variables numboerOfAbsences and gradePointAverage. The expression below is used to determine whether a student is eligible to receive an academic award.
(numberOfAbsences <= 5) AND (gradePointAverage > 3.5)
Which of the following pairs of values indicates that a student is eligible to receive an academic award?
a. numberOfAbsences = 3, gradePointAverage = 3.5
b. numberOfAbsences = 5, gradePointAverage = 3.8
c. numberOfAbsences = 6, gradePointAverage = 3.4
d. numberOfAbsences = 6, gradePointAverage = 3.6
B
Sam is having trouble with her code. She sends her code to Ben for him to debug. Which of the following would be the most useful to help him debug?
a. A brief description of what the program is intended to do.
b. A list of things Sam thinks might be wrong
c. A list of what Sam has done to get the code working.
d. A list of desired inputs with expected outputs.
D
Consider the following code segment, which uses the variables r, s, and t.
r ← 1
s ← 2
t ← 3
r ← s
s ← t
DISPLAY (r)
DISPLAY (s)
What is displayed as a result of running the code segment?
a. 1 1
b. 1 2
c. 2 3
d. 3 2
C
Which of the following are benefits of using well-named variables in a computer program?
Select two answers.
a. The program will run faster.
b. The program will be easier for people to read.
c. The program will have a greater data storage capacity.
d. The program will be easier to modify in the future.
B and D
In the program below, y is a positive integer (e.g. l, 2, 3, ...).
result ← 0
REPEAT 3 TIMES {
REPEAT y TIMES {
result ← result + 1
}
}
What is the value of result after running the program?
a. y+3
b. 3y
c. y^3
d. 3^y
B
In the program below, the initial value of x is 5 and the initial value of y is 10.
IF (X <0)
DISPLAY ("Foxtrot")
ELSE
IF (X > y)
DISPLAY ("Hotel")
ELSE
IF (y > 0)
DISPLAY ("November")
ELSE
DISPLAY ("Yankee")
What is displayed as a result of running the program?
a. Foxtrot
b. Hotel
c. November
d. Yankee
C
a. ["Andy"]
b. ["Andy", "Vickie", "Tom", "Kelly", "John", "Sally"]
c. ["Sally", "John", "Kelly", "Tom", "Vickie", "Andy"]
d. ["Andy", "Sally", "John", "Kelly", "Tom", "Vickie"]
The code fragment below is intended to display "odd" if the positive number num is odd.
IF (<MISSING CONDITION>)
DISPLAY “odd”
a. (num MOD 1) = 0
b. (num MOD 1) = 1
c. (num MOD 2 ) = 0
d. (num MOD 2) = 1
Which of the following can be used to replace <MISSING CONDITION> so that the code fragment will work as intended?
D
Some programming languages use constants, which are variables that are initialized at the beginning of a program and never changed. Which of the following are good uses for a constant?
I. To represent the mathematical value for (pi) as 3.14
II. To represent the current score in a game
III. To represent a known value such as the number of days in a week
a. I and II only
b. I and III only
c. II and III only
d. I, II, and III
C
Consider the following code:
REPEAT UNTIL (x MOD 2 = 0)
x <-- x + 4
Which of the following accurately describes this loop?
Choose 2 answers
a. it is possible for the loop to be infinite
b. it is possible for the loop to never run
c. The max number of times the loop will run is 2 times
d. The loop will error
A and B
C
A programmer wrote the program below. The program uses a list of numbers called numList. The program is intended to display the sum of the numbers in the list.
sum ← numList [1]
FOR EACH value IN numList
sum ← sum + value
DISPLAY sum
In order to test the program, the programmer initializes numList to [0 , 1 , 4 , 5]. The program displays 10, and the programmer concludes that the program works as intended. Which of the following is true?
a. The conclusion is correct; the program works as intended.
b. The conclusion is incorrect; the program does not display the correct value for the test case [0, 1, 4, 5].
c. The conclusion is incorrect; using the test case [0, 1, 4, 5] is not sufficient to conclude the program is correct.
d. The conclusion is incorrect; using the test case [0, 1, 4, 5] only confirms that the program works for lists in increasing order.
C
Assume a is 3, b is 6 and c is 8. Which of these statements would evaluate to 2 given these starting values. Select 2 answers.
A and C
An algorithm will be used to identify the maximum value in a list of one or more integers. Consider the two versions of the algorithm below.
Algorithm I : Set the value of a variable max to -1. Iterate through the list of integer values. If a data value is greater than the value of the variable max, set max to the data value.
Algorithm II : Set the value of a variable max to the first data value. Iterate through the remaining values in the list of integers. If a data value is greater than the value of the variable max, set max to the data value.
Which of the following statements best describes the behavior of the two algorithms?
a. Both algorithms work correctly on all input values.
b. Algorithm I always works correctly, but Algorithm II only works correctly when the maximum value is not the first value in the list.
c. Algorithm II always works correctly, but Algorithm I only works correctly when the maximum value is greater than or equal to -l.
d. Neither algorithm will correctly identify the maximum value when the input contains both positive and negative input values.
C
a. x > 1
b. x = -3
c. x <= -5
d. x = -6
D
Which of the following will evaluate to TRUE given that x is true and y is false?
C and D
A. I only
B. II only
C. I and II
D. II and III
C
Slide #2
A
A school library allows students to borrow laptops. A computer program is used to count the number of times a particular laptop has been borrowed from the library (borrows) and the number of times the same laptop has been returned to the library (returns). Which of the following indicate that a particular laptop is not currently borrowed?
Select two answers.
a. The difference between borrows and returns is zero.
b. The product of borrows and returns is a positive even number.
c. The quotient when borrows is divided by returns is greater than l.
d. The sum of borrows and returns is a positive even number.
A and D
A and C
Which of the following will multiply x by 2 when it is even and multiply x by -2 if it is odd and add 1 to x only if x is zero.
A
Given only the test cases and their intended output, what is the most likely purpose of the code that takes this input and generates this output
a. to determine random numbers less than input
b. to determine all factors of input
c. to determine multiplication tables for students
d. to generate lottery numbers based on input number
B
Slides #1
B
An algorithm has been developed to compute the sum of all the elements in a list of integers. Which of the following programming structures must be added to the existing algorithm so that the new algorithm computes the sum of only the even integers in the list?
a. Iteration
b. Searching
c. Selection
d. Sequencing
C