AP CSP

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Directions: The question or incomplete statement below is followed by four suggested answers or completions. Select the one that is best in each case. The code segment below is intended to display all multiples of 5 between the values Start and End , inclusive. For example, if Start has the value 35 and End has the value 50 , the code segment should display the values 35,40 ,45 , and 50. Assume that Start and End are multiples of 5 and that Start is less than End . Which of the following could replace < missing Expression> in line 2 so that the code segment works as intended?

A end - start + 1 В end - start + 6 с ( end - start) / 5) + 1 D 5 * (end - start) + 1 Answer с

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?

A (age ≥ 12) AND ((height ≥ 50) AND (height ≤ 80)) B (age ≥ 12) AND ((height ≤ 50) AND (height ≥ 80)) C (age ≥ 12) AND ((height ≤ 50) OR (height ≥ 80)) D (age ≥ 12) OR ((height ≥ 50) AND (height ≤ 80)) Answer A

An office building has two floors. A computer program is used to control an elevator that travels between the two floors. Physical sensors are used to set the following Boolean variables. The elevator moves when the door is closed and the elevator is called to the floor that it is not currently on. Which of the following Boolean expressions can be used in a selection statement to cause the elevator to move?

A (onFloor1 AND callTo2) AND (onFloor2 AND callTo1) B (onFloor1 AND callTo2) OR (onFloor2 AND callTo1) C (onFloor1 OR callTo2) AND (onFloor2 OR callTo1) D (onFloor1 OR callTo2) OR (onFloor2 OR callTo1) Answer B

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) Answer C

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 ?

A (score ≤ target + 10) AND (target + 10 ≤ score) B (target + 10 ≤ score) AND (score ≤ target - 10) C (score ≤ target - 10) AND (score ≤ target + 10) D (target - 10 ≤ score) AND (score ≤ target + 10) Answer D

Consider the following code segment. IF X > Y DISPLAY X + Y ELSE DISPLAY X - Y 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. Answer A

What is the value of r as a result of executing the code segment?

A 10 B 20 C 30 D 40 Answer B

Directions: The question or incomplete statement below is followed by four suggested answers or completions. Select the one that is best in each case. A bank customer receives an e-mail from a sender claiming to be a bank employee. The e-mail asks the customer to provide personal information and to call a phone number if he or she has any questions. The customer suspects the e-mail might be a phishing attempt. Which of the following responses is most likely to be a privacy risk for the bank customer?

A Calling the bank at its official phone number to ask whether the request for personal information is legitimate B Calling the phone number given in the e-mail and providing the personal information over the phone C Checking that the domain name of the sender's e-mail address is associated with the bank D Conducting aWeb search to see if other people have received similar requests for personal information Answer B

The following procedure is intended to return the number of times the value val appears in the list myList. The procedure does not work as intended. Line 01: PROCEDURE countNumOccurences(myList, val) Line 02: { Line 03: FOR EACH item IN myList Line 04: { Line 05: count ←← 0 Line 06: IF(item = val) Line 07: { Line 08: count ←← count + 1 Line 09: } Line 10: } Line 11: RETURN(count) Line 12: } Which of the following changes can be made so that the procedure will work as intended?

A Changing line 6 to IF(item = count) B Changing line 6 to IF(myList[item] = val) C Moving the statement in line 5 so that it appears between lines 2 and 3 D Moving the statement in line 11 so that it appears between lines 9 and 10 Answer C

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

Assume that the variables alpha and beta each are initialized with a numeric value. Which of the following code segments can be used to interchange the values of alpha and beta using the temporary variable temp ?

A I and II only B I and III only C II and III only D I, II, and III Answer B

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 ?

Answer B

In which of the following situations would it be most appropriate to choose lossy compression over lossless compression?

Storing music files on a smartphone in order to maximize the number of songs that can be stored

Consider the following code segment, which uses the variables r, s, and t. r ← 1 s ← 2 t ← 3 r ← s s ← t DISPLAY (r) DISPLAY (s) What is displayed as a result of running the code segment?

A 1 1 B 1 2 C 2 3 D 3 2 Answer C

Consider the following code segment, which is intended to store ten consecutive even integers, beginning with 2, in the list evenList. Assume that evenList is initially empty. i ←← 1 REPEAT 10 TIMES { <MISSING CODE> } Which of the following can be used to replace <MISSING CODE> so that the code segment works as intended?

A APPEND(evenList, i) i ←← i + 2 B i ←← i + 2 APPEND(evenList, i) C APPEND(evenList, 2 * i) i ←← i + 1 D i ←← i + 1 APPEND(evenList, 2 * i) Answer C

A Web site uses several strategies to prevent unauthorized individuals from accessing user accounts. Which of the following is NOT an example of multifactor authentication?

A Each employee for a company is issued a USB device that contains a unique token code. To log into a company computer, an employee must insert the USB device into the computer and provide a correct password. B After logging into an account from a new device, a user must enter a code that is sent via e-mail to the e-mail address on file with the account. C In order to log into an account, a user must provide both a password and a fingerprint that is captured using the user's device. D When a user enters an incorrect password more than two times in a row, the user is locked out of the account for 24 hours. Answer D

The grid below contains a robot represented as a triangle, initially facing right. The robot can move into a white or gray square but cannot move into a black region. The code segment below uses the procedure GoalReached, which evaluates to true if the robot is in the gray square and evaluates to false otherwise. REPEAT UNTIL (GoalReached ()) { <MISSING CODE> } Which of the following replacements for <MISSING CODE> can be used to move the robot to the gray square?

A REPEAT UNTIL (CAN_MOVE (forward) = false) { ROTATE_RIGHT () } MOVE_FORWARD () B REPEAT UNTIL (CAN_MOVE (forward) = false) { MOVE_FORWARD () } ROTATE_RIGHT () C REPEAT UNTIL (CAN_MOVE (right)) { ROTATE_RIGHT () } MOVE_FORWARD () D REPEAT UNTIL (CAN_MOVE (right)) { MOVE_FORWARD () } ROTATE_RIGHT () Answer B

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?

A [-3, -2, -1] B [-2, -1, 0] C [-1, 0, 1] D [1, 2, 3] Answer C

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 Answer C

Directions: The question or incomplete statement below is followed by four suggested answers or completions. Select the one that is best in each case. In the program below, y is a positive integer (e.g., 1, 2, 3, ...). What is the value of result after running the program?

A y + 3 B 3y C D Answer B

A code segment is intended to display the following output. up down down down up down down down Which of the following code segments can be used to display the intended output?

Answer A Repeat 2 times display up repeat 3 times display down

Directions: The question or incomplete statement below is followed by four suggested answers or completions. Select the one that is best in each case. The ticket prices at a movie theater are given below. A programmer is creating an algorithm to set the value of based on the information in the table. The programmer uses the integer variable for the age of the moviegoer. The Boolean variable is when the movie is 3-D and otherwise. Which of the following code segments correctly sets the value of ?

Code C: ticketPrice<--12 IF age <= 12 or age >= 60 ticketPrice<--9 if is 3D ticketPrice<--ticketprice +5

In the following code segment, assume that the variable n has been initialized with an integer value. Which of the following is NOT a possible value displayed by the program?

A "artichoke" B "broccoli" C "carrot" D "daikon" Answer C

What is displayed as a result of executing the code segment? numlist <--- 100,20,300,40,500,60 FOR EACH item IN numlist IF item >= 90 Display ITem

A 1 3 5 B 5 3 1 C 100 300 500 D 500 300 100 Answer C

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 Answer D

Consider the following code segment. What is the value of sum after the code segment is executed?

A 12 B 14 C 16 D 18 Answer C

A flowchart provides a way to visually represent an algorithm and uses the following building blocks. BlockExplanationOvalThe start or end of the algorithmRectangleOne or more processing steps, such as a statement that assigns a value to a variableDiamondA conditional or decision step, where execution proceeds to the side labeled true if the condition is true and to the side labeled false otherwiseParallelogramDisplays a message In the flowchart below, assume that j and k are assigned integer values. Based on the algorithm represented in the flowchart, what value is displayed if j has the initial value 3 and k has the initial value 4 ?

A 7 B 9 C 10 D 12 Answer D

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 Answer C

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 A string variable named s and a Boolean variable named a B A string variable named s and a numeric variable named n C A string variable named studentName and a Boolean variable named isAbsent D A string variable named studentName and a numeric variable named numAbsences Answer C

A user purchased a new smart home device with embedded software and connected the device to a home network. The user then registered the device with the manufacturer, setting up an account using a personal e-mail and password. Which of the following explains how a phishing attack could occur against the user of the smart home device?

A A vulnerability in the device's software is exploited to gain unauthorized access to other devices on the user's home network. B A vulnerability in the device's software is exploited to install software that reveals the user's password to an unauthorized individual. C The user is sent an e-mail appearing to be from the manufacturer, asking the user to confirm the account password by clicking on a link in the e-mail and entering the password on the resulting page. D The user's account is sent an overwhelming number of messages in an attempt to disrupt service on the user's home network. Answer C

There are 32 students standing in a classroom. Two different algorithms are given for finding the average height of the students. Algorithm A Step 1: All students stand. Step 2: A randomly selected student writes his or her height on a card and is seated. Step 3: A randomly selected standing student adds his or her height to the value on the card, records the new value on the card, and is seated. The previous value on the card is erased. Step 4: Repeat step 3 until no students remain standing. Step 5: The sum on the card is divided by 32. The result is given to the teacher. Algorithm B Step 1: All students stand. Step 2: Each student is given a card. Each student writes his or her height on the card. Step 3: Standing students form random pairs at the same time. Each pair adds the numbers written on their cards and writes the result on one student's card; the other student is seated. The previous value on the card is erased. Step 4: Repeat step 3 until one student remains standing. Step 5: The sum on the last student's card is divided by 32. The result is given to the teacher. Which of the following statements is true?

A Algorithm A always calculates the correct average, but Algorithm B does not. B Algorithm B always calculates the correct average, but Algorithm A does not. C Both Algorithm A and Algorithm B always calculate the correct average. D Neither Algorithm A nor Algorithm B calculates the correct average. Answer C

The code segment below uses the procedure IsFound (list, item), which returns true if item appears in list and returns false otherwise. The list resultListis initially empty. FOR EACH item IN inputList1 ( IF (IsFound (inputList2, item) { APPEND (resultList, item) } Which of the following best describes the contents of resultList after the code segment is executed?

A All elements in inputList1 followed by all elements in inputList2 B Only elements that appear in both inputList1 and inputList2 C Only elements that appear in either inputList1 or inputList2 but not in both lists D Only elements that appear in inputList1 but not in inputList2 Answer B

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. For which of the following procedure calls does the procedure NOT return the intended value?

A AnyPairs ("bat", "cat", "rat") B AnyPairs ("bat", "bat", "rat") C AnyPairs ("bat", "cat", "bat") D AnyPairs ("bat", "cat", "cat") Answer C

Directions: The question or incomplete statement below is followed by four suggested answers or completions. Select the one that is best in each case. A student wrote the following code for a guessing game. While debugging the code, the student realizes that the loop never terminates. The student plans to insert the instruction WIN <-- TRUE somewhere in the code. Where could WIN <-- TRUE be inserted so that the code segment works as intended?

A Between line 6 and line 7 B Between line 9 and line 10 C Between line 20 and 21 D Between line 21 and 22 Answer B

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 Answer B

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?

A Changing line 1 to IF(score < 0) B Changing line 1 to IF(score + penalty < 0) C Changing line 7 to score ←← score + penalty D Interchanging lines 3 and 7 Answer D

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?

A First, change all occurrences of "goats" to "sheep." Then, change all occurrences of "sheep" to "goats." B First, change all occurrences of "goats" to "sheep." Then, change all occurrences of "sheep" to "goats." Last, change all occurrences of "foxes" to "sheep." C First, change all occurrences of "goats" to "foxes." Then, change all occurrences of "sheep" to "goats." Last, change all occurrences of "foxes" to "sheep." D First, change all occurrences of "goats" to "foxes." Then, change all occurrences of "foxes" to "sheep." Last, change all occurrences of "sheep" to "goats." Answer C

Directions: The question or incomplete statement below is followed by four suggested answers or completions. Select the one that is best in each case. The procedure below searches for the value target in list. It returns true if target is found and returns false otherwise. Procedure contains List, Target Which of the following are true statements about the procedure? I. It implements a binary search. II. It implements a linear search. III. It only works as intended when is sorted.

A I only B II only C I and III D II and III Answer B

A biologist wrote a program to simulate the population of a sample of bacteria. The program uses the following procedures.

A I only B II only C III only D I and II Answer A

The grid below contains a robot represented as a triangle, initially facing toward the top of the grid. The robot can move into a white or gray square but cannot move into a black region. The code segment below uses the procedure goalReached, which evaluates to true if the robot is in the gray square and evaluates to false otherwise. REPEAT UNTIL(goalReached()) { <MISSING CODE> } Which of the following replacements for <MISSING CODE> can be used to move the robot to the gray square?

A IF(CAN_MOVE(left)) { ROTATE_LEFT() MOVE_FORWARD() } B IF(CAN_MOVE(forward)) { MOVE_FORWARD() ROTATE_LEFT() } C IF(CAN_MOVE(left)) { ROTATE_LEFT() } MOVE_FORWARD() D IF(CAN_MOVE(forward)) { MOVE_FORWARD() } ELSE { ROTATE_LEFT() } Answer C

A list of numbers is considered increasing if each value after the first is greater than or equal to the preceding value. The following procedure is intended to return true if numberList is increasing and return false otherwise. Assume that numberList contains at least two elements. Line 1: PROCEDURE isIncreasing(numberList) Line 2: { Line 3: count ←← 2 Line 4: REPEAT UNTIL(count > LENGTH(numberList)) Line 5: { Line 6: IF(numberList[count] < numberList[count - 1]) Line 7: { Line 8: RETURN(true) Line 9: } Line 10: count ←← count + 1 Line 11: } Line 12: RETURN(false) Line 13: } Which of the following changes is needed for the program to work as intended?

A In line 3, 2 should be changed to 1. B In line 6, < should be changed to ≥. C Lines 8 and 12 should be interchanged. D Lines 10 and 11 should be interchanged. Answer C

A student wrote the following program to remove all occurrences of the strings "the" and "a" from the list wordList. Line 1: index ←← LENGTH (wordList) 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?

A Inserting index ←← index + 1 between lines 6 and 7 B Inserting index ←← index + 1 between lines 7 and 8 C Inserting index ←← index - 1 between lines 6 and 7 D Inserting index ←← index - 1 between lines 7 and 8 Answer D

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. Which change, if any, is needed for the program to work as intended?

A Lines 1 and 2 should be interchanged. B Line 3 should be changed to REPEAT UNTIL (i ≥ 10). C Lines 5 and 6 should be interchanged. D No change is needed; the program works correctly. Answer C

Which of the following is an example of a phishing attack?

A Loading malicious software onto a user's computer in order to secretly gain access to sensitive information B Flooding a user's computer with e-mail requests in order to cause the computer to crash C Gaining remote access to a user's computer in order to steal user IDs and passwords D Using fraudulent e-mails in order to trick a user into voluntarily providing sensitive information Answer D

Which of the following activities poses the greatest personal cybersecurity risk?

A Making a purchase at an online store that uses public key encryption to transmit credit card information B Paying a bill using a secure electronic payment system C Reserving a hotel room by e-mailing a credit card number to a hotel D Withdrawing money from a bank account using an automated teller machine (ATM) Answer C

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 Answer C

Which of the following is a true statement about the use of public key encryption in transmitting messages?

A Public key encryption enables parties to initiate secure communications through an open medium, such as the Internet, in which there might be eavesdroppers. B Public key encryption is not considered a secure method of communication because a public key can be intercepted. C Public key encryption only allows the encryption of documents containing text; documents containing audio and video must use a different encryption method. D Public key encryption uses a single key that should be kept secure because it is used for both encryption and decryption. Answer A

The following algorithm is intended to determine the average height, in centimeters, of a group of people in a room. Each person has a card, a pencil, and an eraser. Step 2 of the algorithm is missing. Step 1: All people stand up. Step 2: (missing step) Step 3: Each standing person finds another standing person and they form a pair. If a person cannot find an unpaired standing person, that person remains standing and waits until the next opportunity to form pairs. Step 4: In each pair, one person hands their card to the other person and sits down. Step 5: At this point, the standing person in each pair is holding two cards. The standing person in each pair replaces the top number on their card with the sum of the top numbers on the two cards and replaces the bottom number on their card with the sum of the bottom numbers on the two cards. The sitting partner's card is discarded. Step 6: Repeat steps 3-5 until there is only one person standing. Step 7: The last person standing divides the top number by the bottom number to determine the average height. Which of the following can be used as step 2 so that the algorithm works as intended?

A Step 2: Each person writes their height, in centimeters, at the top of the card and writes the number 1 at the bottom of the card. B Step 2: Each person writes their height, in centimeters, at the top of the card and writes the number 2 at the bottom of the card. C Step 2: Each person writes the number 1 at the top of the card and writes their height, in centimeters, at the bottom of the card. D Step 2: Each person writes the number 2 at the top of the card and writes their height, in centimeters, at the bottom of the card. Answer A

A city's police department has installed cameras throughout city streets. The cameras capture and store license plate data from cars driven and parked throughout the city. The authorities use recorded license plate data to identify stolen cars and to enforce parking regulations. Which of the following best describes a privacy risk that could occur if this method of data collection is misused?

A The cameras may not be able to read license plates in poor weather conditions. B Local business owners could lose customers who are unwilling to park in the city. C Traffic personnel who work for the city could lose their jobs if their services are no longer needed. D The vehicle location data could be used to monitor the movements of city residents. Answer D

A programmer wrote the program below. The program uses a list of numbers called numList. The program is intended to display the sum of the numbers in the list. 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?

A The conclusion is correct; the program works as intended. B 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. D The conclusion is incorrect; using the test case [0, 1, 4, 5] only confirms that the program works for lists in increasing order. Answer C

Directions: The question or incomplete statement below is followed by four suggested answers or completions. Select the one that is best in each case. A student wrote the procedure below, which is intended to ask whether a user wants to keep playing a game. The procedure does not work as intended. PROCEDURE KeepPlaying ( ) DISPLAY ("Do you want to continue playing (y/n)?") INPUT ( ) response IF ( response e = "y") AND (response = "yes")) { RETURN (true) } ELSE RETURN (false) Which of the following best describes the result of running the procedure?

A The procedure returns when the user inputs the value and returns otherwise. B The procedure returns when the user inputs the value and returns otherwise. C The procedure returns no matter what the input value is. D The procedure returns no matter what the input value is. Answer D

Directions: The question or incomplete statement below is followed by four suggested answers or completions. Select the one that is best in each case. Consider the following program. Count<-- 1 Sum<--0 Repeat 10 Times: Sum <-- sum + count Count<-- count +2 Display Sum Which of the following describes the result of executing the program?

A The program displays the sum of the even integers from 0 to 10. B The program displays the sum of the even integers from 0 to 20. C The program displays the sum of the odd integers from 1 to 9. D The program displays the sum of the odd integers from 1 to 19. Answer D

Which of the following describes the result of executing the program?

A The program displays the sum of the even integers from 2 to 10. B The program displays the sum of the even integers from 2 to 20. C The program displays the sum of the odd integers from 1 to 9. D The program displays the sum of the odd integers from 1 to 19. Answer B

Directions: The question or incomplete statement below is followed by four suggested answers or completions. Select the one that is best in each case. In public key cryptography, the sender uses the recipient's public key to encrypt a message. Which of the following is needed to decrypt the message?

A The sender's public key B The sender's private key C The recipient's public key D The recipient's private key Answer A

Which of the following best exemplifies the use of multifactor authentication to protect an online banking system?

A When a user resets a password for an online bank account, the user is required to enter the new password twice. B When multiple people have a shared online bank account, they are each required to have their own unique username and password. C After entering a password for an online bank account, a user must also enter a code that is sent to the user's phone via text message. D An online bank requires users to change their account passwords multiple times per year without using the same password twice. Answer C

The algorithm below is used to simulate the results of flipping a coin 4 times. Consider the goal of determining whether the simulation resulted in an equal number of heads and tails. Step 1: Initialize the variables heads_counter and flip_counter to 0. Step 2: A variable coin_flip is randomly assigned a value of either 0 or 1. If coin_flip has the value 0, the coin flip result is heads, so heads_counter is incremented by 1. Step 3: Increment the value of flip_counter by 1. Step 4: Repeat steps 2 and 3 until flip_counter equals 4. Following execution of the algorithm, which of the following expressions indicates that the simulation resulted in an equal number of heads and tails?

A coin_flip = 1 B flip_counter = 1 C flip_counter = 2 D heads_counter = 2 Answer D

Ticket prices for a science museum are shown in the following table. A programmer is creating an algorithm to display the cost of a ticket based on the information in the table. The programmer uses the integer variable age for the age of the ticket recipient. The Boolean variable includesTour is true when the ticket is for a guided tour and is false when the ticket is for general admission. Which of the following code segments correctly displays the cost of a ticket?

A cost ←← 6 IF ((age > 12) OR includesTour) { cost ←← cost + 2 } DISPLAY (cost) B cost ←← 6 IF (age > 12) { cost ←← cost + 2 } IF (includesTour) { cost ←← cost + 2 } DISPLAY (cost) C cost ←← 6 IF (age > 12) { IF (includesTour) { cost ←← cost + 2 } } DISPLAY (cost) D cost ←← 6 IF (age > 12) { cost ←← cost + 2 } ELSE { IF (includesTour) { cost ←← cost + 2 } } DISPLAY (cost) Answer B

Consider the following procedure. Procedure Call: drawCircle(xPos, yPos, rad) Explanation: Draws a circle on a coordinate grid with center (xPos, yPos) and radius rad The drawCircle procedure is to be used to draw the following figure on a coordinate grid. Let the value of the variable x be 2, the value of the variable y be 2, and the value of the variable r be 1. Which of the following code segments can be used to draw the figure?

A drawCircle(x, y, r) drawCircle(x, y + 2, r) drawCircle(x + 2, y, r) drawCircle(x + 2, y + 2, r) B drawCircle(x, y, r) drawCircle(x, y + 3, r) drawCircle(x + 3, y, r) drawCircle(x + 3, y + 3, r) C drawCircle(x, y, r + 2) drawCircle(x, y + 2, r + 2) drawCircle(x + 2, y, r + 2) drawCircle(x + 2, y + 2, r + 2) D drawCircle(x, y, r + 3) drawCircle(x, y + 3, r + 3) drawCircle(x + 3, y, r + 3) drawCircle(x + 3, y + 3, r + 3) Answer B

A student's overall course grade in a certain class is based on the student's scores on individual assignments. The course grade is calculated by dropping the student's lowest individual assignment score and averaging the remaining scores. For example, if a particular student has individual assignment scores of 85, 75, 90, and 95, the lowest score (75) is dropped. The calculated course grade is (85+90+95)/3=90. A programmer is writing a program to calculate a student's course grade using the process described. The programmer has the following procedures available. The student's individual assignment scores are stored in the list scores. Which of the following can be used to calculate a student's course grade and store the result in the variable finalGrade?

A finalGrade ←← Sum (scores) / LENGTH (scores) finalGrade ←← finalGrade - Min (scores) B finalGrade ←← Sum (scores) / (LENGTH (scores) - 1) finalGrade ←← finalGrade - Min (scores) C finalGrade ←← Sum (scores) - Min (scores) finalGrade ←← finalGrade / LENGTH (scores) D finalGrade ←← Sum (scores) - Min (scores) finalGrade ←← finalGrade / (LENGTH (scores) - 1) Answer D

What are the values of first and second as a result of executing the code segment?

A first = 100, second = 100 B first = 100, second = 200 C first = 200, second = 100 D first = 200, second = 200 Answer A

Consider the following code segment. Which of the following replacements for <MISSING CONDITION> will result in an infinite loop?

A j = 6 B j ≥ 6 C j = 7 D j > 7 Answer A

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) Answer B

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 Answer B

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 Answer D

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?

A x = 1, y = 2, z = 3 B x = 1, y = 3, z = 2 C x = 2, y = 3, z = 1 D x = 3, y = 2, z = 1 Answer D

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

Directions: The question or incomplete statement below is followed by four suggested answers or completions. Select the one that is best in each case. The grid below contains a robot represented as a triangle, initially facing up. The robot can move into a white or gray square but cannot move into a black region. The code segment below uses the procedure , which evaluates to if the robot is in the gray square and evaluates to otherwise. Which of the following replacements for can be used to move the robot to the gray square?

Answer A

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?

Answer A if scoreA > scoreB If scoreA> scoreC Display TeamA Wins Else Display TeamC wins Else If scoreB > scoreC Display Team B wins Else Display Team C wins

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?

Answer C IF Numunits <= 25 cost<--numunits *5 Else Cost<--25 * 5 + Numunits-25)*7

The program segment below is intended to move a robot in a grid to a gray square. The program segment uses the procedure GoalReached, which evaluates to true if the robot is in the gray square and evaluates to false otherwise. The robot in each grid is represented as a triangle and is initially facing left. The robot can move into a white or gray square but cannot move into a black region. REPEAT UNTIL (GoalReached ()) { IF (CAN_MOVE (forward) ) { MOVE_FORWARD ( ) } IF (CAN_MOVE (right)) { ROTATE_RIGHT ( ) } IF (CAN_MOVE (left)) { ROTATE_LEFT ( )

Answer D


Kaugnay na mga set ng pag-aaral

Quiz 8: Visual Communication, Film/Video, and Digital Art

View Set

unit 4- photosynthesis and cellular respiration

View Set

Biomechanics for a Dancer: Chapter 3

View Set

Ch.30 Head-to-Toe Assessment of the Adult

View Set

the constitution guard against tyranny PART 2

View Set

Chapter 15: Psychological Disorders

View Set