Font size
WorksheetsCsp4
Total questions: 86
Worksheet time: 47mins
Which of the following algorithms displays the correct distance for all possible values of num1 and num2 ?
Step 1:
Add num1 and num2 and store the result in the variable sum.
Step 2: Take the absolute value ofsum and display the result.
Step 1:
Subtract num1 from num2 and store the result in the variable diff.
Step 2:
Take the absolute value of diff and display the result.
Step 1:
Take the absolute value of num1 and store it in the variable absNum1.
Step 2:
Take the absolute value of num2 and store it in the variable absNum2.
Step 3:
Add absNum1 and absNum2 and display the result.
Step 1:
Take the absolute value of num1 and store it in the variable absNum1.
Step 2:
Take the absolute value of num2 and store it in the variable absNum2.
Step 3:
Subtract absNum1 from absNum2 and display the result.
A teacher has a goal of displaying the names of 2 students selected at random from a group of 30 students in a classroom. Any possible pair of students should be equally likely to be selected. Which of the following algorithms can be used to accomplish the teacher’s goal?
Step 1:
Assign each student a unique integer from 1 to 30.
Step 2:
Generate a random integer n from 1 to 15.
Step 3:
Select the student who is currently assigned integer nand display the student’s name.
Step 4:
Generate a new random integer n from 16 to 30.
Step 5:
Select the student who is currently assigned integer nand display the student’s name.
Step 1:
Assign each student a unique integer from 1 to 30.
Step 2:
Generate a random integer n from 1 to 30.
Step 3:
Select the student who is currently assigned integer nand display the student’s name.
Step 4:
Generate a new random integer n from 1 to 30.
Step 5:
Select the student who is currently assigned integer nand display the student’s name.
Step 1:
Assign each student a unique integer from 1 to 30.
Step 2:
Generate a random odd integer n from 1 to 29.
Step 3:
Select the student who is currently assigned integer nand display the student’s name.
Step 4:
Generate a new random even integer n from 2 to 30.
Step 5:
Select the student who is currently assigned integer nand display the student’s name.
Step 1:
Assign each student a unique integer from 1 to 30.
Step 2:
Generate a random integer n from 1 to 30.
Step 3:
Select the student who is currently assigned integer nand display the student’s name.
Step 4:
The student who was selected in the previous step is assigned 0. All other students are reassigned a unique integer from 1 to 29.
Step 5:
Generate a new random integer n from 1 to 29.
Step 6:
Select the student who is currently assigned integer nand display the student’s name.
A certain game keeps track of the maximum and minimum scores obtained so far. If num represents the most recent score obtained, which of the following algorithms correctly updates the values of the maximum and the minimum?
If num is greater than the minimum, set the minimum equal tonum. Otherwise, if num is greater than the maximum, set the maximum equal to num.
If num is less than the minimum, set the minimum equal to num. Otherwise, if num is greater than the maximum, set the maximum equal to num.
If num is less than the minimum, set the minimum equal to num. Otherwise, if num is less than the maximum, set the maximum equal to num.
If num is greater than the minimum, set the minimum equal tonum. Otherwise, if num is less than the maximum, set the maximum equal tonum.
A programmer is creating an algorithm that will be used to turn on the motor to open the gate in a parking garage. The specifications for the algorithm are as follows.
-The gate should not open when the time is outside of business hours.
-The motor should not turn on unless the gate sensor is activated.
-The motor should not turn on if the gate is already open.
Which of the following algorithms can be used to open the gate under the appropriate conditions?
Check if the time is outside of business hours. If it is, check if the gate sensor is activated. If it is, check if the gate is closed. If it is, turn on the motor.
Check if the time is during business hours. If it is, check if the gate sensor is activated. If it is, check if the gate is open. If it is, turn on the motor.
Check if the time is during business hours. If it is, check if the gate sensor is activated. If it is not, check if the gate is open. If it is not, turn on the motor.
Check if the time is during business hours. If it is, check if the gate sensor is activated. If it is, check if the gate is open. If it is not, turn on the motor.
Which of the following statements is equivalent to the algorithm in the flowchart?
The variable isOpen is to be used to indicate whether or not a store is currently open. Which of the following is the most appropriate data type for isOpen ?
Boolean
number
string
list
In a certain game, the integer variable bonus is assigned a value based on the value of the integer variable score.
-If score is greater than 100, bonus is assigned a value that is 10 times score.
-If score is between 50 and 100 inclusive, bonus is assigned the value of score.
-If score is less than 50, bonus is assigned a value of 0.
Which of the following code segments assigns bonus correctly for all possible integer values ofscore ?
Select two answers.
IF(score > 100)
{
bonus ← score * 10
}
ELSE
{
IF(score ≥ 50)
{
bonus ← score
}
ELSE
{
bonus ← 0
}
}
IF(score ≥ 50)
{
IF(score > 100)
{
bonus ← score * 10
}
ELSE
{
bonus ← 0
}
}
ELSE
{
bonus ← score
}
IF(score < 50)
{
bonus ← 0
}
ELSE
{
IF(score ≥ 50)
{
bonus ← score
}
ELSE
{
bonus ← score * 10
}
}
IF(score < 50)
{
bonus ← 0
}
ELSE
{
IF(score > 100)
{
bonus ← score * 10
}
ELSE
{
bonus ← score
}
}
The cost of a customer’s electricity bill is based on the number of units of electricity the customer uses.
-For the first 25 units of electricity, the cost is $5 per unit.
-For units of electricity after the first 25, the cost is $7 per unit.
Which of the following code segments correctly sets the value of the variable cost to the cost, in dollars, of using numUnits units of electricity?
A teacher is writing a code segment that will use variables to represent a student’s name and whether or not the student is currently absent. Which of the following variables are most appropriate for the code segment?
A string variable named s and a Boolean variable named a
A string variable named s and a numeric variable named n
A string variable named studentName and a Boolean variable named is Absent
A string variable named studentName and a numeric variable namednumAbsences
1 1
1 2
2 3
3 2
The variable age is to be used to represent a person’s age, in years. Which of the following is the most appropriate data type for age ?
Boolean
number
string
list
1 3
3 3
3 4
4 4
Which of the following are benefits of using well-named variables in a computer program?
Select two answers.
The program will run faster.
The program will be easier for people to read.
The program will have a greater data storage capacity.
The program will be easier to modify in the future.
(NOT input1) OR (NOT input2)
(NOT input1) AND (NOT input2)
NOT (input1 OR input2)
NOT (input1 AND input2)
Which of the following Boolean expressions are equivalent to the expression
Num>-15
Select two answers.
A student is writing a program to model different real-world events using simulations. Which of the following simulations will generate a result that would best be stored using a Boolean variable?
A simulation of flipping a fair coin
A simulation of rolling a fair die (with sides numbered 1 through 6
A simulation of the temperature in a location over time
A simulation of traffic patterns on a road
Central High School keeps a database of information about each student, including the numeric variables numberOfAbsences 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?
numberOfAbsences = 3, gradePointAverage = 3.5
numberOfAbsences = 5, gradePointAverage = 3.8
numberOfAbsences = 6, gradePointAverage = 3.4
numberOfAbsences = 6, gradePointAverage = 3.6
If the variables onTime and absent both have the value false, what is displayed as a result of running the code segment?
Is anyone there?
Better late than never.
Hello. Is anyone there?
Hello. Better late than never.
The code fragment below is intended to display "odd" if the positive number num is odd.
Which of the following can be used to replace <MISSING CONDITION> so that the code fragment will work as intended?
(num MOD 1) = 0
(num MOD 1) = 1
(num MOD 2) = 0
(num MOD 2) = 1
If the inputs A and C are both true, which of the following best describes the output of the AND gate?
The output will be true no matter what the value of input B is.
The output will be false no matter what the value of input B is.
The output will be true if input B is true; otherwise it will be false.
The output will be false if input B is true; otherwise it will be true.
When the value of exam is 70 and the value of presentation is 50
When the value of exam is 70 and the value of presentation is 80
When the value of exam is 80 and the value of presentation is 60
When the value of exam is 80 and the value of presentation is 80
onFloor1 AND callTo2) AND (onFloor2 AND callTo1)
(onFloor1 AND callTo2) OR (onFloor2 AND callTo1)
(onFloor1 OR callTo2) AND (onFloor2 OR callTo1)
onFloor1 OR callTo2) OR (onFloor2 OR callTo1)
Changing line 1 to FOR EACH number IN newList
Changing line 3 to IF (number MOD 2 = 1)
Changing line 5 to APPEND (newList, number)
No change is needed; the code segment is correct as is.
When the values of x and y are both positive.
When the values of x is positive and the value of y is negative.
When the values of X and y are both negative.
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?
The conclusion is correct; the program works as intended.
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.
The conclusion is incorrect; using the test case [0, 1, 4, 5] is not sufficient to conclude the program is correct.
A programmer wants to determine whether a score is within 10 points of a given target. For example, if the target is 50, then the scores 40, 44, 50, 58, and 60 are all within 10 points of the target, while 38 and 61 are not.
Which of the following Boolean expressions will evaluate to true if and only if score is within 10 points of target ?
(score ≤ target + 10) AND (target + 10 ≤ score)
(target + 10 ≤ score) AND (score ≤ target - 10)
(score ≤ target - 10) AND (score ≤ target + 10)
(target - 10 ≤ score) AND (score ≤ target + 10)
For which of the following input values will the circuit have an output of false ?
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?
val1 = true, val2 = true
val1 = false, val2 = false
val1 = true, val2 = false
val1 = false, val2 = true
To be eligible for a particular ride at an amusement park, a person must be at least 12 years old and must be between 50 and 80 inches tall, inclusive.
Let age represent a person’s age, in years, and let height represent the person’s height, in inches. Which of the following expressions evaluates to true if and only if the person is eligible for the ride?
(age ≥ 12) AND ((height ≥ 50) AND (height ≤ 80))
(age ≥ 12) AND ((height ≤ 50) AND (height ≥ 80))
(age ≥ 12) AND ((height ≤ 50) OR (height ≥ 80))
(age ≥ 12) OR ((height ≥ 50) AND (height ≤ 80))
The following procedure is intended to return true if at least two of the three parameters are equal in value and is intended to return false otherwise.
PROCEDURE AnyPairs (x, y, z)
{
IF (x = y)
{
RETURN (true)
}
ELSE
{
RETURN (y = z)
}
}
For which of the following procedure calls does the procedure NOT return the intended value?
AnyPairs ("bat", "cat", "rat")
AnyPairs ("bat", "bat", "rat")
AnyPairs ("bat", "cat", "bat")
AnyPairs ("bat", "cat", "cat")
Assume that the list of numbers nums has more than 10 elements. The program below is intended to compute and display the sum of the first 10 elements of nums.
Line 1: i ← 1
Line 2: sum ← 0
Line 3: REPEAT UNTIL (i > 10)
Line 4: {
Line 5: i ← i + 1
Line 6: sum ← sum + nums[i]
Line 7: }
Line 8: DISPLAY (sum)
Which change, if any, is needed for the program to work as intended?
Lines 1 and 2 should be interchanged.
Line 3 should be changed to REPEAT UNTIL (i ≥ 10).
Lines 5 and 6 should be interchanged.
No change is needed; the program works correctly.
Line 2: count ← 0
Line 3: REPEAT UNTIL (currentNum > end)
Line 4: {
Line 5: count ← count + 1
Line 6: IF (IsPerfect (currentNum))
Line 7: {
Line 8: count ← count + 1
Line 9: currentNum ← currentNum + 1
Line 10: }
Line 11: currentNum ← currentNum + 1
Line 12: }
Line 13: DISPLAY (count)
Which two lines of code should be removed so that the program will work as intended?
Select two answers.
Line 5
Line 8
Line 9
Line 11
For which of the following code segments will the call to NumOccurrences NOT return the intended value?
Select two answers.
Line 2: REPEAT UNTIL (index < 1)
Line 3: {
Line 4: IF ((wordList[index] = "the") OR (wordList[index] = "a"))
Line 5: {
Line 6: REMOVE (wordList, index)
Line 7: }
Line 8: }
While debugging the program, the student realizes that the loop never terminates. Which of the following changes can be made so that the program works as intended?
Inserting index ← index + 1 between lines 6 and 7
Inserting index ← index + 1 between lines 7 and 8
Inserting index ← index - 1 between lines 6 and 7
Inserting index ← index - 1 between lines 7 and 8
Line 1: IF(score - penalty < 0)
Line 2: {
Line 3: score ← score - penalty
Line 4: }
Line 5: ELSE
Line 6: {
Line 7: score ← 0
Line 8: }
Which of the following changes can be made so that the code segment works as intended?
Changing line 1 to IF(score < 0)
Changing line 1 to IF(score + penalty < 0)
Changing line 7 to score ← score + penalty
Interchanging lines 3 and 7
For which of the following procedure calls does the procedure NOT return the intended value?
Select two answers.
To attend a particular camp, a student must be either at least 13 years old or in grade 9 or higher, but must not yet be 18 years old. Let age represent a student’s age and let grade represent the student’s grade level. Which of the following expressions evaluates to true if the student is eligible to attend the camp and evaluates to false otherwise?
((age ≥ 13) OR (grade ≥ 9)) AND (age ≤ 18)
((age ≥ 13) OR (grade ≥ 9)) AND (age < 18)
((age ≥ 13) OR (grade ≥ 9)) OR (age ≤ 18)
((age ≥ 13) OR (grade ≥ 9)) OR (age < 18)
Let n be an integer value. Which of the following expressions evaluates to true if and only if n is a two-digit integer (i.e., in the range from 10 to 99, inclusive)?
n = (n MOD 100)
(n ≥ 10) AND (n < 100)
(n < 10) AND (n ≥ 100)
(n > 10) AND (n < 99)
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 and the number of times the same laptop has been returned to the library . Which of the following indicate that a particular laptop is not currently borrowed?
Select two answers.
The difference between borrows and returns is zero.
The sum of borrows and returns is a positive even number.
The quotient when borrows is divided by returns is greater than 1.
For which of the following input values will the circuit have an output of true ?
A = true, B = true, C = true, D = false
A = true, B = false, C = false, D = true
A = false, B = true, C = true, D = true
A = false, B = false, C = true, D = true
Which of the following initial values for x, y, and z can be used to show that the code segment does not work as intended?
x = 1, y = 2, z = 3
x = 1, y = 3, z = 2
x = 2, y = 3, z = 1
x = 3, y = 2, z = 1
Assume that the Boolean variable hot is assigned the value true and the Boolean variablehumid is assigned the value false. Which of the following will display the value true ?
Select two answers.
Between line 6 and line 7
Between line 9 and line 10
Between line 20 and 21
Between line 21 and 22
A programmer completes the user manual for a video game she has developed and realizes she has reversed the roles of goats and sheep throughout the text. Consider the programmer’s goal of changing all occurrences of “goats” to “sheep” and all occurrences of “sheep” to “goats.” The programmer will use the fact that the word “foxes” does not appear anywhere in the original text.
Which of the following algorithms can be used to accomplish the programmer’s goal?
First, change all occurrences of “goats” to “sheep.”
Then, change all occurrences of “sheep” to “goats.”
First, change all occurrences of “goats” to “sheep.”
Then, change all occurrences of “sheep” to “goats.”
Last, change all occurrences of “foxes” to “sheep.”
First, change all occurrences of “goats” to “foxes.”
Then, change all occurrences of “sheep” to “goats.”
Last, change all occurrences of “foxes” to “sheep.”
First, change all occurrences of “goats” to “foxes.”
Then, change all occurrences of “foxes” to “sheep.”
Last, change all occurrences of “sheep” to “goats.”
Foxtrot
Hotel
November
Yankee
To qualify for a particular scholarship, a student must have an overall grade point average of 3.0 or above and must have a science grade point average of over 3.2. Let overallGPA represent a student’s overall grade point average and let scienceGPA represent the student’s science grade point average. Which of the following expressions evaluates to true if the student is eligible for the scholarship and evaluates to false otherwise?
(overallGPA > 3.0) AND (scienceGPA > 3.2)
(overallGPA > 3.0) AND (scienceGPA ≥ 3.2)
(overallGPA ≥ 3.0) AND (scienceGPA > 3.2)
(overallGPA ≥ 3.0) AND (scienceGPA ≥ 3.2)
Which of the following expressions will evaluate to true if the restaurant should be counted and evaluates to false otherwise?
(avgRating ≥ 4.0) AND ((prcRange = "lo") AND (prcRange = "med"))
(avgRating ≥ 4.0) AND ((prcRange = "lo") OR (prcRange = "med"))
(avgRating ≥ 4.0) OR ((prcRange = "lo") AND (prcRange = "med"))
(avgRating ≥ 4.0) OR ((prcRange = "lo") OR (prcRange = "med"))
Three teams (Team A, Team B, and Team C) are participating in a trivia contest. Let scoreA represent the number of correct questions for Team A, scoreB represent the number of correct questions for Team B, and scoreC represent the number of correct questions for Team C. Assuming no two teams get the same number of correct questions, which of the following code segments correctly displays the team with the highest number of correct questions?
Which of the following code segments will assign the correct letter grade to grade based on the value of the variable score ?
II and III only
I and III only
In a certain country, a person must be at least 16 years old to drive a car and must be at least 18 years old to vote. The variable age represents the age of a person as an integer.
Which of the following expressions evaluates to true if the person is old enough to drive but not old enough to vote, and evaluates to false otherwise?
(age ≥ 16) AND (age ≤ 18)
(age ≥ 16) AND (NOT(age ≥ 18))
(age < 18) AND (NOT(age < 16))
II only
I and II only
I and III only
II and III only
If x has a value of 7 and y has a value of 20, what is displayed as a result of executing the code segment?
ONE
TWO
THREE
FOUR
The following algorithm is intended to take a positive integer as input and display its individual digits in order from right to left. For example, if the input is 512, the algorithm should produce the output2 1 5. Step 3 of the algorithm is missing.
Step 1: Input a positive integer from the user and store it in the variable number.
Step 2: Divide number by 10 and record the integer quotient and the remainder. The integer quotient is the quotient with any part after the decimal point dropped. For example, when 127 is divided by 10, the quotient is 12.7, the integer quotient is 12 and the remainder is 7.
Step 3: (missing step)
Step 4: Repeat steps 2 and 3 until number is 0.
Which of the following can be used as step 3 so that the algorithm works as intended?
Step 3: Display the remainder of number divided by 10 and store the remainder in number.
Step 3: Display the remainder of number divided by 10 and store the integer quotient in number.
Step 3: Display the integer quotient of number divided by 10 and store the remainder in number.
Step 3: Display the integer quotient of number divided by 10 and store the integer quotient in number.
For which of the following grids does the program NOT correctly move the robot to the gray square?
Which of the following code segments correctly displays the cost of a ticket?
cost ← 6
IF ((age > 12) OR includesTour)
{
cost ← cost + 2
}
DISPLAY (cost)
cost ← 6
IF (age > 12)
{
cost ← cost + 2
}
IF (includesTour)
{
cost ← cost + 2
}
DISPLAY (cost)
cost ← 6
IF (age > 12)
{
IF (includesTour)
{
cost ← cost + 2
}
}
DISPLAY (cost)
Which of the following code segments produce the same result as the statement above for all possible values of val1 and val2 ?
Select two answers.
In a certain video game, players are awarded bonus points at the end of a level based on the value of the integer variable timer. The bonus points are awarded as follows.
If timer is less than 30, then 500 bonus points are awarded.
If timer is between 30 and 60 inclusive, then 1000 bonus points are awarded.
If timer is greater than 60, then 1500 bonus points are awarded.
Which of the following code segments assigns the correct number of bonus points to bonus for all possible values of timer ?
Select two answers.
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?
Iteration
Searching
Selection
Sequencing
In a certain video game, the variable maxPS represents the maximum possible score a player can earn. The maximum possible score depends on the time it takes the player to complete the game. The value of maxPS should be 30 if time is greater than 120 and 50 otherwise.
Which of the following code segments correctly sets the value of maxPS based on the value oftime ?
Select two answers.
I and II only
I and III only
II and III only
I, II, and III
Which of the following can be used to replace so that the code segment works as intended?
Which of the following code segments can be used to interchange the values of the variables num1 and num2 ?
A code segment will be used to swap the values of the variables a and b using the temporary variable temp.
Which of the following code segments correctly swaps the values of a and b ?
PROCEDURE allPositive(myList)
{
index ← 1
len ← LENGTH(myList)
REPEAT len TIMES
{
IF(myList[index] > 0)
{
RETURN(true)
}
index ← index + 1
}
RETURN(false)
}
For which of the following contents of myList does the procedure NOT return the intended result?
[-3, -2, -1]
[-2, -1, 0]
[-1, 0, 1]
1, 2, 3]
For which of the following values of numCorrect does the code segment NOT display the intended grade?
Select two answers.
9
8
7
6
The figure below shows a circuit composed of two logic gates. The output of the circuit is true.
Input A must be true.
Input A must be false.
Input A can be either true or false.
For each grid, the program below is intended to move the robot to the gray square. The program uses the procedure Goal_Reached ( ), which evaluates to true if the robot is in the gray square and evaluates to false otherwise.
Grid I only
Grid II only
Both grid I and grid II
Neither grid I nor grid II
temp ← word1
word3 ← word1
word1 ← temp
temp ← word1
word1 ← word3
word3 ← temp
Line 1
Line 4
Line 7
Line 49
A computer program uses 3 bits to represent integers. When the program adds the decimal (base 10) numbers 5 and 3, the result is 0. Which of the following is the best explanation for the result?
An overflow error occurred.
A round-off error occurred.
The result was affected by lossy data compression.
The result was approximated by a floating-point representation.
Which of the following procedure calls can be used to demonstrate that the procedure does NOT work as intended?
FindName (["Andrea", "Ben"], "Ben")
FindName (["Andrea", "Ben"], "Diane")
FindName (["Andrea", "Ben", "Chris"], "Ben")
FindName (["Andrea", "Chris", "Diane"], "Ben"
If the value of x is 3 and the value of y is 5, what is displayed as a result of executing the code segment
-2
2
8
Nothing will be displayed.
What is the value of r as a result of executing the code segment?
10
20
30
40
In the following expression, the variable truckWeight has the value 70000 and the variableweightLimit has the value 80000.
truckWeight < weightLimit
What value does the expression evaluate to?
70000
80000
true
false
If the value of score1 is 350 and the value of score2 is 210, what will be the value ofresult after the code segment is executed?
3
4
5
7
What is the value of sum after the code segment is executed?
12
14
16
18
Which of the following initial values of the variable y would result in the variable z being set to 2 after the code segment is executed?
1
2
3
4
What is displayed as a result of executing the code segment?
true true true
false false false
true false true
false false true
What are the values of first and second as a result of executing the code segment?
first = 100, second = 100
first = 100, second = 200
first = 200, second = 100
first = 200, second = 200
Which of the following is NOT a possible value displayed by the program?
artichoke
broccoli
carrot
daikon
Assume that the Boolean variable x is assigned the value true and the Boolean variable y is assigned the value false. Which of the following will display the value true ?
Select two answers.
Which of the following is NOT a possible value displayed by the program?
too high
in range
too low
out of range
