CSP Progress Check 2 Review
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? I. (age ≥ 16) AND (age ≤ 18) II. (age ≥ 16) AND (NOT(age ≥ 18)) III. (age < 18) AND (NOT(age < 16))
II and III only
refactoring
Making a program simpler after adding a new feature.
Find the flipped bit.For this table, identify the bit that was flipped.
The bit in row 4 column 4.
lossless compression
algorithm is one in which no data are lost; the original data can be completely recovered. An example of lossless compression is RLE.
What does the following AP CSP pseudocode display? Remember to trace through the code keeping track of the values in a and b after each line of code. a ← 1 (Set a to 1)b ← a (Set b to the current value of a)b ← b + 1 (Add 1 to b)a ← a + b (Set a to be the current value of a + b)DISPLAY(a)DISPLAY(b)
3 2
Which of the following is an advantage of a lossless compression algorithm over a lossy compression algorithm?
A lossless compression algorithm can guarantee reconstruction of original data, while a lossy compression algorithm cannot.
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 ?
A person's age is typically represented numerically, so a numeric variable is most appropriate.
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 student name is best represented using a string. The status of whether a student is absent can be represented using only the values true and false, so a Boolean variable is most appropriate. For both variables, using meaningful variable names helps with the readability of the code segment.
Three students in different locations are collaborating on the development of an application. Which of the following strategies is LEAST likely to facilitate collaboration among the students?
Having all three students write code independently and then having one student combine the code into a program
In the following code segment, score and penalty are initially positive integers. The code segment is intended to reduce the value of score by penalty. However, if doing so would cause score to be negative, score should be assigned the value 0. For example, if score is 20 and penalty is 5, the code segment should set score to 15.If score is 20 and penalty is 30, score should be set to 0. The code segment does not work as intended. 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?
Interchanging lines 3 and 7 ensures that if reducing score by penalty results in a negative value, score is set to 0. Otherwise, score is reduced by penalty.
Consider the following code segment. What is the value of r as a result of executing the code segment?
The first four statements assign values to the variables. The fifth statement assigns the value of q (which is 20) to p. The sixth statement assigns the value of r (which is 30) to q. The seventh statement assigns the value of q (which is 30) to s. The last statement assigns the value of p (which is 20) to r. Therefore, r has the value 20. After executing the code segment, the value of p is 20, the value of q is 30, the value of r is 20, and the value of s is 30.
Consider the following code segment. x ← 25 y ← 50 z ← 75 x ← y y ← z z ← x Which of the variables have the value 50 after executing the code segment?
The first three statements assign values to the variables. The fourth statement assigns the value of y (which is 50) to x. The fifth statement assigns the value of z (which is 75) to y. The sixth statement assigns the value of x (which is 50) to z. Therefore, x and z both have the value 50.
Consider the following code segment. What are the values of first and second as a result of executing the code segment?
The first two statements assign values to the variables. The third statement assigns the value of first (which is true) to second. The fourth statement assigns the value of second (which is true) to first.
The following procedure is intended to return true if the list of numbers myList contains only positive numbers and is intended to return false otherwise. The procedure does not work as intended. 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?
The procedure traverses this list and eventually encounters the positive value 1. At this point, the procedure returns true when it should return false because the list does not contain only positive values. [-1, 0, 1]
lossy compression
algorithm is one in which some data are lost; the original data cannot be completely restored. An example of lossy compression is JPEG.
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 ?
it would be more appropriate to use a Boolean value because the status could be represented using only the values true and false.
The following code segment is intended to set max equal to the maximum value among the integer variables x, y, and z. The code segment does not work as intended in all cases. 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 = 3, y = 2, z = 1