APCS Unit 4 test

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

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? Responses

((age ≥ 13) OR (grade ≥ 9)) AND (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 ≥ 10) AND (n < 100)

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)

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

Which of the following CANNOT be displayed as a result of executing the code segment?

1 3 2 4

What is the value of sum after the code segment is executed?

16

What is displayed as a result of executing the code segment?

21 40 30 50

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? x = 23 z = x MOD y

3

Consider the following code segment. result ← 1 IF(score1 > 500) { result ← result + 1 IF(score2 > 500) { result ← result + 1 } ELSE { result ← result + 2 } } ELSE { result ← result + 5 IF(score2 > 500) { result ← result + 1 } ELSE { result ← result - 1 } } If the value of score1 is 350 and the value of score2 is 210, what will be the value of result after the code segment is executed? Responses

5

Consider the following spinner, which is used to determine how pieces are to be moved on a game board. Each region is of equal size. Which of the following code segments can be used to simulate the behavior of the spinner?

Answer B Of the regions in the spinner, 25% are yellow, 25% are blue, and 50% are red. This code segment generates a random value from 1 to 4, inclusive. If the random value is 1 (25% of the time), color is assigned "yellow". If the random value is 2 (25% of the time), color is assigned "blue". Otherwise (50% of the time), color is assigned "red".

Which of the following describes the possible values of ans as a result of executing the code segment?

Any integer value from 7 to 16, inclusive

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 numeric test score is to be converted to a letter grade of A, B, or C according to the following rules: A score greater than 90 is considered an A; a score between 80 and 90, inclusive, is considered a B; and any other score is considered a C. Which of the following code segments will assign the correct letter grade to grade based on the value of the variable score ?

Code segment I does not work correctly because it is not possible for "C" to be the value of grade at the end of the code segment. Code segment II correctly assigns "A" when the numeric score is greater than 90, or "B" if the numeric score is not greater than 90 but is greater than or equal to 80, or "C" otherwise. Code segment III assigns "C" when the numeric score is less than 80, or "B" if the numeric score is not less than 80 but is less than or equal to 90, or "A" otherwise. 2 and 3 only

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 ? Select two answers.

IF(score > 100) { bonus ← score * 10 } ELSE { IF(score ≥ 50) { bonus ← score } ELSE { bonus ← 0 } } IF(score < 50) { bonus ← 0 } ELSE { IF(score > 100) { bonus ← score * 10 } ELSE { bonus ← score } }

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.

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?

If scoreA is greater than both scoreB and scoreC (the first two IF clauses), then Team A wins. If scoreA is greater than scoreB but not greater than scoreC, then scoreC is greater than both scoreA and scoreB and Team C wins. If scoreB is greater than scoreA (the outer ELSE clause) and scoreC (the IF clause in the outer ELSE), then Team B wins. If scoreB is greater than scoreA but not greater than scoreC, then scoreC is greater than both scoreA and scoreB and Team C wins. (answer choice A)

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? Responses

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.

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

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?

THREE

In a certain game, a player may have the opportunity to attempt a bonus round to earn extra points. In a typical game, a player is given 1 to 4 bonus round attempts. For each attempt, the player typically earns the extra points 70% of the time and does not earn the extra points 30% of the time. The following code segment can be used to simulate the bonus round.

The player had 3 bonus round attempts and 7 of them earned extra points.

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

Consider the following code segment. What is displayed as a result of executing the code segment?

false false false

Consider a game where a player spins a wheel divided into four identical sections, labeled A, B, C, and D. If the player spins A, the score is 10. If the player spins B, the score is 5. If the player spins C or D, the score is -1. The following code segment is intended to implement the game. Which of the following could be used as a replacement for <MISSING STATEMENT> so the code segment works as intended?

random 1,4

A spinner contains 12 regions of equal size. The regions are numbered 1 to 12. Which of the following code segments can be used to simulate the results of spinning the spinner three times and assigns the sum of the values obtained by the three spins to the variable sum ?

sum ← RANDOM(1, 12) + RANDOM(1, 12) + RANDOM(1, 12)

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

temp = num1 num1 = num2 num2 = temp

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

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

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


Ensembles d'études connexes

Combined Oral Contraceptives (aka "The Pill")

View Set

Chapter 1: Sociological Perspectives on Social Problems

View Set

English Language Arts 020, OAE 020 Exam Terms, OAE 020 Practice Assessments

View Set