COMP SCI UNIT 4

अब 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? A ((age ≥ 13) OR (grade ≥ 9)) AND (age ≤ 18) B ((age ≥ 13) OR (grade ≥ 9)) AND (age < 18) C ((age ≥ 13) OR (grade ≥ 9)) OR (age ≤ 18) D ((age ≥ 13) OR (grade ≥ 9)) OR (age < 18)

((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)? A n = (n MOD 100) B (n ≥ 10) AND (n < 100) C (n < 10) AND (n ≥ 100) D (n > 10) AND (n < 99)

(n ≥ 10) AND (n < 100)

Consider the following code segment. What is the value of r as a result of executing the code segment? A 10 B 20 C 30 D 40

20

Consider the following code segment. 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? A -2 B 2 C 8 D Nothing will be displayed.

A -2

Consider the following code segment. What is displayed as a result of executing the code segment? A true true true B false false false C true false true D false false true

B false false false

Consider the following code segment. What is displayed as a result of executing the code segment? A 10 20 30 40 B 21 30 40 50 C 21 40 30 40 D 21 40 30 50

D 21 40 30 50

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? A val1 = true, val2 = true B val1 = true, val2 = false C val1 = false, val2 = true D val1 = false, val2 = false

D val1 = false, val2 = false

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 IF [numUnits <= 25] cost <-- numUnits x 5 ELSE cost <-- numUnits x 7 B IF [numUnits <= 25] cost <-- numUnits x 5 ELSE cost <-- (numUnits - 25) x 7 C IF [numUnits <= 25] cost <-- numUnits x 5 ELSE cost <-- 25 x 5 + (numUnits - 25) x 7 D IF [numUnits <= 25] cost <-- numUnits x 5 ELSE cost <-- 25 x 7 + (numUnits - 25) x 5

D IF [numUnits <= 25] cost <-- numUnits x 5 ELSE cost <-- 25 x 7 + (numUnits - 25) x 5

Consider the following code segment. What are the values of first and second as a result of executing the code segment? A The value of first is true, and the value of second is true. B The value of first is true, and the value of second is false. C The value of first is false, and the value of second is true. D The value of first is false, and the value of second is false.

The value of first is true, and the value of second is false.

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 ? A When the value of exam is 70 and the value of presentation is 50 B When the value of exam is 70 and the value of presentation is 80 C When the value of exam is 80 and the value of presentation is 60 D When the value of exam is 80 and the value of presentation is 80

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

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 Boolean B number C string D list

number

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? A temp ←← word1 word3 ←← word1 word1 ←← temp B temp ←← word1 word1 ←← word3 word3 ←← temp C temp ←← word1 word1 ←← word2 word2 ←← word3 word3 ←← temp D temp ←← word3 word3 ←← word2 word2 ←← word1 word1 ←← temp

temp ←← word1 word1 ←← word3 word3 ←← temp

Consider the following code segment with integer variables x and y. 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? A ONE B TWO C THREE D FOUR

three

Which of the following code segments can be used to interchange the values of the variables num1 and num2 ? A num1 <- num2 num2 <- num2 B temp <- num 1 num1 <- temp C temp <- num1 num2 <- num1 num1 <- temp D temp <- num1 num <- num2 num2 <- temp

D temp <- num1 num <- num2 num2 <- temp

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? A (overallGPA > 3.0) AND (scienceGPA > 3.2) B (overallGPA > 3.0) AND (scienceGPA ≥ 3.2) C (overallGPA ≥ 3.0) AND (scienceGPA > 3.2) D (overallGPA ≥ 3.0) AND (scienceGPA ≥ 3.2)

(overallGPA ≥ 3.0) AND (scienceGPA > 3.2)

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? A 3 B 4 C 5 D 7

5

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 ? Select two answers. A [maxPS <-- 50] IF time > 120 (maxPS <-- 30) B IF time > 120 (maxPS <-- 30) [maxPS <-- 50] C IF time > 120 (maxPS <-- 50) ELSE (maxPS <-- 30) D IF time > 120 (maxPS <-- 30) ELSE (maxPS <-- 50)

A [maxPS <-- 50] IF time > 120 (maxPS <-- 30) D IF time > 120 (maxPS <-- 30) ELSE (maxPS <-- 50)

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? A 70000 B 80000 C true D false

C true

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? A x only B y only C x and z only D x, y, and z

C x and z only

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? A 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. B 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. C 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. D 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.

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.

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. 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 ←← score * 10 } ELSE { bonus ←← score } }

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? A If num is greater than the minimum, set the minimum equal to num. Otherwise, if num is greater than the maximum, set the maximum equal to num. B 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. C 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. D If num is greater 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 less than the minimum, set the minimum equal to num. Otherwise, if num is greater than the maximum, set the maximum equal to num.

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? A 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 n and 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 n and display the student's name. B 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:Generate a new random integer n from 1 to 30.Step 5:Select the student who is currently assigned integer n and display the student's name. C 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 n and 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 n and display the student's name. D 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.

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 Which of the following algorithms displays the correct distance for all possible values of num1 and num2 ? A Step 1:Add num1 and num2 and store the result in the variable sum. Step 2: Take the absolute value of sum and display the result. B 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. C 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. D 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.

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.


संबंधित स्टडी सेट्स

Chapter 17 Unit 13 Earth's Interior

View Set

Hinkle and Cheever prep U chapter 46

View Set

The Periodic Table of Elements 1-25

View Set

Patho Chapter 15 Disorders of motor function (Part 1), Porth's Patho Ch. 16: Disorders of Brain Function, Porth's Patho Ch. 15: Disorders of motor function

View Set