APCSP Test Study Guide

Ace your homework & exams now with Quizwiz!

3.5 Boolean Expressions 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)

3.5 Boolean Expressions 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 ≥ 10) AND (n < 100)

3.5 Boolean Expressions 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)

3.6 Conditionals Consider the following code segment. num1 ← 6 num2 ← 4 num3 ← 10 IF [num1 < num2] num1 ← num2 ELSE num3 ← num2 IF [num2 >= num3] num1 ← num2 plus num3 sum ← num1 + num2 + num3 What is the value of sum after the code segment is executed?

16

3.1 Variables and Assignments p <-- 10 q <-- 20 r <-- 30 s <-- 40 p <-- q q <-- r s <-- q r <-- p What is the value of r as a result of executing the code segment?

20

3.3 Mathematical Expressions Consider the following code segment. a <-- 10 b <-- 20 c <-- 30 d <-- 40 x <-- 20 b <-- x + b a <-- x + 1 d <-- c + d / 2 DISPLAY a DISPLAY b DISPLAY c DISPLAY d What is displayed as a result of executing the code segment?

21 40 30 50

3.3 Mathematical Expressions Consider the following code segment. x <-- 23 y <-- x MOD y 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?

3

3.1 Variables and Assignments 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 studentName and a Boolean variable named isAbsent

3.6 Conditionals 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 of time ?

A., D.

3.7 Nested Conditionals 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 of score ? A. IF(score > 100) { bonus <-- score * 10 } ELSE { IF(score ≥ 50) { bonus <-- score } ELSE { bonus <-- 0 } } B. IF(score ≥ 50) { IF(score > 100) { bonus <-- score * 10 } ELSE { bonus <-- 0 } } ELSE { bonus <-- score } C. IF(score < 50) { bonus <-- 0 } ELSE { IF(score ≥ 50) { bonus score } ELSE { bonus score * 10 } } D. IF(score < 50) { bonus 0 } ELSE { IF(score > 100) { bonus sc

A., D.

3.6 Conditionals 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?

C.

3.6 Conditionals 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 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.

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 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.

3.3 Mathematical Expressions Which of the following code segments can be used to interchange the values of the variables num1 and num2 ?

Correct answer: D

3.6 Conditionals 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 less than the minimum, set the minimum equal to num. Otherwise, if num is greater than the maximum, set the maximum equal to num.

3.6 Conditionals 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 less than the minimum, set the minimum equal to num. Otherwise, if num is greater than the maximum, set the maximum equal to num.

3.3 Mathematical Expressions 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 30. Step 3: Select the student who is currently assigned integer n and 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 n and display the student's name.

3.3 Mathematical Expressions A student is creating an algorithm to display the distance between the numbers num1 and num2 on a number line. The following table shows the distance for several different values. (If the table is hard to read, flip card) Value of num1 | Value of num2 | Distance Between num1 and num2 | | 5 | 2 | 3 1 | 8 | 7 -3 | 4 | 7 Which of the following algorithms displays the correct distance for all possible values of num1 and num2 ?

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.

3.7 Nested Conditionals 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" } } } Under which of the following conditions will the value "C" be assigned to the variable grade ?

When the value of exam is 80 and the value of presentation is 60

3.1 Variables and Assignments 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

3.5 Boolean Expressions Consider the following code segment. a ← true b ← false c ← true a ← [NOT (a OR b) AND c] c ← [c AND a] DISPLAY a DISPLAY b DISPLAY c What is displayed as a result of executing the code segment?

false false false

3.1 Variables and Assignments 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 ?

number

3.3 Mathematical Expressions Three words are stored in the variables word1, word2, and word3. The values of the variables are to be updated as shown in the following table. (If table is hard to read, flip card) Variable | Value Before Updating | Value After Updating word1 | "xylophone" | "zebra" word2 | "yarn" | "yarn" word3 | "zebra" | "xylophone" Which of the following code segments can be used to update the values of the variables as shown in the table?

temp <-- word1 word1 <-- word3 word3 <-- temp

3.5 Boolean Expressions In the following expression, the variable truckWeight has the value 70000 and the variable weightLimit has the value 80000. truckWeight < weightLimit What value does the expression evaluate to?

true

3.5 Boolean Expressions 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 = false, val2 = false


Related study sets

Anirudh's Intro to Marketing Exam #1

View Set

Chapter 13 Key Terms and Essential Questions

View Set

Seizure and Seizure-like conditions

View Set

BMS 130 Muscles/Neurons & Action Potentials

View Set

04 - SB: Review of the Merchandising Business (10 - 14 mins)

View Set

AP Psychology-Unit 1 Major Historical Figures

View Set