APCSP TEST

Ace your homework & exams now with Quizwiz!

A programmer completes the user manual for a video game she has developed and realized she had 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? Selected Answer: [None Given]Answers: First, change all occurrences of "goats" to "sheep."Then, change all occurrences of "sheep" to "goats."Last, change all occurrences of "foxes" to "sheep." First, change all occurrences of "goats" to "foxes."Then, change all occurrences of "sheep" to "goats."Last, change all occurrences of "foxes" to "sheep." First, change all occurrences of "goats" to "foxes."Then, change all occurrences of "foxes" to "sheep."Last, change all occurrences of "sheep" to "goats." First, change all occurrences of "goats" to "sheep."Then, change all occurrences of "sheep" to "goats."

First, change all occurrences of "goats" to "foxes."Then, change all occurrences of "sheep" to "goats."Last, change all occurrences of "foxes" to "sheep."

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 ? Selected Answer: [None Given]Answers: (score ≤ target + 10) AND (target + 10 ≤ score) (target + 10 ≤ score) AND (score ≤ target - 10) (score ≤ target - 10) AND (score ≤ target + 10) (target - 10 ≤ score) AND (score ≤ target + 10)

(target - 10 ≤ score) AND (score ≤ target + 10)

Which of the following are true statements about digital certificates in Web browsers? Digital certificates are used to verify the ownership of encrypted keys used in secured communication. Digital certificates are used to verify that the connection to a Web site is fault tolerant. Selected Answer: [None Given]Answers: I only Neither I nor II I and II II only

1

A photographer has a collection of digital pictures, each using the same file-naming format: a date tag, followed by a description, followed by the file extension ".jpg". The photographer wants to write a code segment to extract the description from each file name, as shown in the following table. Original File NameExtracted Description2016-05-22-Andrews-Graduation.jpgAndrews-Graduation2016-07-04-Fireworks.jpgFireworks​2017-10-18-Grandmas-Birthday.jpgGrandmas-Birthday The photographer has the following procedures available. Procedure CallExplanation​TrimLeft (str, n)Returns a copy of the string str with the n leftmost characters removed. For example, TrimLeft ("keyboard", 3) returns "board".TrimRight (str, n)Returns a copy of the string str with the n rightmost characters removed. For example, TrimRight ("keyboard", 3) returns "keybo". Let an original file name be stored in the string variable original. Which of the following statements will correctly extract the description and store it in the string variable descr ? descr ← TrimLeft (TrimRight (original, 4), 11) descr ← TrimLeft (TrimRight (original, 11), 4) descr ← TrimRight (TrimLeft (original, 11), 4) Selected Answer: [None Given]Answers: II only I and III II and III I only

1 & 3

In the following procedure, the parameter str is a string and the parameter num is a number. PROCEDURE printArgs(str, num) { DISPLAY(num) DISPLAY(str) DISPLAY(num) } Consider the following code segment. printArgs("**", 1) printArgs("*", 2) What is displayed as a result of executing the code segment? Selected Answer: [None Given]Answers: 1 * 1 2 ** 2 1 ** 1 2 * 2 ** 1 ** * 2 * * 1 * ** 2 **

1 ** 1 2 * 2

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? Selected Answer: [None Given]Answers: 1 1 1 2 2 3 3 2

2 3

The diagram below shows a circuit composed of three logic gates. Each gate takes two inputs and produces a single output. For which of the following input values will the circuit have an output of true ? Selected Answer: [None Given]Answers: A = true, B = true, C = true, D = false A = false, B = true, C = true, D = true A = false, B = false, C = true, D = true A = true, B = false, C = false, D = true

A = false, B = true, C = true, D = true

Substitution Ciphers... Selected Answer: [None Given]Answers: were used in an astronomical text by the English poet Geoffrey Chaucer. are often 'cracked' using frequency analysis. were employed by Mary Queen of Scots in a plot against Queen Elizabeth I. All of the above are true.

All of the above are true.

The figure below shows a circuit composed of two logic gates. The output of the circuit is true. Which of the following is a true statement about input A? Selected Answer: [None Given]Answers: There is no possible value of input A that will cause the circuit to have the output true. Input A must be false. Input A can be either true or false. Input A must be true.

Input A must be true.

Byte pair encoding is a data encoding technique. The encoding algorithm looks for pairs of characters that appear in the string more than once and replaces each instance of that pair with a corresponding character that does not appear in the string. The algorithm saves a list containing the mapping of character pairs to their corresponding replacement characters. For example, the string can be encoded as by replacing all instances of with and replacing all instances of with . For which of the following strings is it NOT possible to use byte pair encoding to shorten the string's length? Selected Answer: [None Given]Answers: "NEITHER_HERE_NOR_THERE" "MEET_ME_LATER" "BANANA" "LEVEL_UP"

LEVEL_UP

Which of the following Boolean expressions are equivalent to the expression ? Select two answers. Selected Answers: [None Given]Answers:

Not (Num < 15) (Not > 15) or (Num equal 15)

A gate is a type of logic gate that produces an output of only when both of its two inputs are . Otherwise, the gate produces an output of . Which of the following Boolean expressions correctly models a gate with inputs and ? Selected Answer: [None Given]Answers:

Not (p aNd q)

A programmer notices the following two procedures in a library. The procedures do similar, but not identical, things. Procedure MaxTwo (x, y) returns the greater of its two integer parameters. Procedure MaxThree (x, y, z) returns the greatest of its three integer parameters. Which of the following procedures is a generalization of the MaxTwo and MaxThree procedures? Selected Answer: [None Given]Answers: Procedure OverMax (numList, max), which returns the number of integers in numList that exceed the integer value max Procedure MaxFour (w, x, y, z), which returns the greatest of its four integer parameters Procedure Max (numList), which returns the maximum value in the list of integers numList Procedure Min (x, y), which returns the lesser of its two integer parameters

Procedure Max (numList), which returns the maximum value in the list of integers numList

A certain computer game is played between a human player and a computer-controlled player. Every time the computer-controlled player has a turn, the game runs slowly because the computer evaluates all potential moves and selects the best one. Which of the following best describes the possibility of improving the running speed of the game? Selected Answer: The game's running speed might be improved by using a process that finds approximate solutions every time the computer-controlled player has a turn. Answers: The game's running speed cannot be improved because computers can only be programmed to find the best possible solution. The game's running speed can only be improved if the game is played between two human players instead of with the computer-controlled player. The game's running speed might be improved by using a process that finds approximate solutions every time the computer-controlled player has a turn. The game's running speed cannot be improved because the game is an example of an algorithm that does not run in a reasonable time.

The game's running speed might be improved by using a process that finds approximate solutions every time the computer-controlled player has a turn.

The following code segment is intended to display a randomly generated integer between 1 and 100 and whether it is even or not even. a ← RANDOM (1,100) DISPLAY (a) IF ( <MISSING CODE> ) { DISPLAY ("This integer is even") } ELSE { DISPLAY ("This integer is not even") } Which of the following could replace <MISSING CODE> so that the code segment works as intended? Selected Answer: [None Given]Answers: a MOD 2 = 0 a / 2 = 1 a MOD 2 = 1 a / 2 = 0

a MOD 2 = 0

The diagram below shows a circuit composed of three logic gates. Each gate takes two inputs and produces a single output. For which of the following input values will the circuit have an output of ? Selected Answer: [None Given]Answers:

a- true B false c false d false

A finite sequence of steps designed to solve a problem is called a(n) _________. Selected Answer: [None Given]Answers: protocol expression algorithm procedure

algorithm

In a flowchart, the ____ symbol is used to indicate that a decision needs to be made. Selected Answer: diamond Answers: arrow rectangle parallelogram diamond

diamond

In the following program, 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? Selected Answer: [None Given]Answers: too low too high out of range in range

out of range

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 ? Selected Answer: [None Given]Answers:

ticketprice - 12 age <equal 12 or age >equal 60 ticketprice 9 if is3d ticketprice - ticketprice plus 5

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. VariableDescriptiononFloor1set to true if the elevator is stopped on floor 1; otherwise set to falseonFloor2set to true if the elevator is stopped on floor 2; otherwise set to falsecallTo1set to true if the elevator is called to floor 1; otherwise set to falsecallTo2set to true if the elevator is called to floor 2; otherwise set to false 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. Selected Answer: [None Given]Answers: (onFloor1 AND callTo2) OR (onFloor2 AND callTo1) (onFloor1 AND callTo2) AND (onFloor2 AND callTo1) (onFloor1 OR callTo2) AND (onFloor2 OR callTo1) (onFloor1 OR callTo2) OR (onFloor2 OR callTo1)

(onFloor1 AND callTo2) OR (onFloor2 AND callTo1)

The procedure Draw (length, direction) is used to draw a line segment length units long in a given direction (left, right, up, or down), starting at the current cursor position. The cursor is then repositioned at the end of the line segment that was drawn. Consider the following program, where the cursor starts in the upper left corner of a grid of dots. The dots are spaced one unit apart. Draw (1, right) Draw (2, down) Draw (1, left) Draw (1, right) Draw (1, up) Draw (1, left) Which of the following represents the figure that is drawn by the program?

3

A person wants to transmit an audio file from a device to a second device. Which of the following scenarios best demonstrates the use of lossless compression of the original file? Selected Answer: [None Given]Answers: A device transmits the original audio file to a second device. The second device plays the transmitted file as is. A device transmits the original audio file to a second device. The second device removes metadata from the file before playing it. A device compresses the audio file by removing details that are not easily perceived by the human ear. The compressed file is transmitted to a second device, which plays it. A device compresses the audio file before transmitting it to a second device. The second device restores the compressed file to its original version before playing it.

A device compresses the audio file before transmitting it to a second device. The second device restores the compressed file to its original version before playing it.

Which of the following programs is most likely to benefit from the use of a heuristic? Selected Answer: [None Given]Answers: A program that calculates a student's grade based on the student's quiz and homework scores A program that finds the shortest driving route between two locations on a map A program that encrypts a folder of digital files A program that sorts a list of numbers in order from least to greatest

A program that finds the shortest driving route between two locations on a map

There are 32 students 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? Selected Answer: [None Given]Answers: Algorithm A always calculates the correct average, but Algorithm B does not. Algorithm B always calculates the correct average, but Algorithm A does not. Both Algorithm A and Algorithm B always calculate the correct average. Neither Algorithm A nor Algorithm B calculates the correct average.

Both Algorithm A and Algorithm B always calculate the correct average.

Byte pair encoding is a data encoding technique. The encoding algorithm looks for pairs of characters that appear in the string more than once and replaces each instance of that pair with a corresponding character that does not appear in the string. The algorithm saves a list containing the mapping of character pairs to their corresponding replacement characters. For example, the string can be encoded as by replacing all instances of with and replacing all instances of with . Which of the following statements about byte pair encoding is true? Selected Answer: [None Given]Answers: Byte pair encoding is an example of a lossless transformation because an encoded string can be restored to its original version. Byte pair encoding is an example of a lossy transformation because it discards some of the data in the original string. Byte pair encoding is an example of a lossy transformation because some pairs of characters are replaced by a single character. Byte pair encoding is an example of a lossless transformation because it can be used to transmit messages securely.

Byte pair encoding is an example of a lossless transformation because an encoded string can be restored to its original version.

Digital images are often represented by the red, green, and blue values (an RGB triplet) of each individual pixel in the image. A photographer is manipulating a digital image and overwriting the original image. Which of the following describes a lossless transformation of the digital image? Selected Answer: [None Given]Answers: Creating the negative of an image by creating a new RGB triplet for each pixel in which each value is calculated by subtracting the original value from 255. The negative of an image is reversed from the original; light areas appear dark, and colors are reversed. Creating the gray scale of an image by averaging the amounts of red, green, and blue in each pixel and assigning this new value to the corresponding pixel in the new image. The new value of each pixel represents a shade of gray, ranging from white to black. Modifying part of the image by taking the pixels in one part of the picture and copying them to the pixels in another part of the picture. Compressing the image in a way that may lose information but will suffer only a small loss of image quality.

Creating the negative of an image by creating a new RGB triplet for each pixel in which each value is calculated by subtracting the original value from 255. The negative of an image is reversed from the original; light areas appear dark, and colors are reversed.

Which of the following is true about EDRs (Event Data Recorders)? Selected Answer: [None Given]Answers: EDRs are installed in most airplanes, sometimes called 'black boxes.' EDRs are installed in all new and used U.S. automobiles, sometimes called 'black boxes.' Installation of EDRs results in Second Amendment implications. All of the above are true.

EDRs are installed in most airplanes, sometimes called 'black boxes.'

Which of the following actions are generally helpful in program development? Consulting potential users of the program to identify their concerns Writing and testing small code segments before adding them to the program Collaborating with other individuals when developing a large program Selected Answer: [None Given]Answers: I and II only I, II, and III I and III only II and III only

I, II, and III

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? (age ≥ 16) AND (age ≤ 18) (age ≥ 16) AND (NOT(age ≥ 18)) (age < 18) AND (NOT(age < 16)) Selected Answer: [None Given]Answers: II only II and III only I and II only I and III only

II and III only

Which of the following best describes one of the benefits of using an iterative and incremental process of program development? Selected Answer: [None Given]Answers: It eliminates the need for programmers to test completed programs. It allows programmers to implement algorithmic solutions to otherwise unsolvable problems. It enables programmers to create programs that use the lowest-level abstractions available. It helps programmers identify errors as components are added to a working program.

It helps programmers identify errors as components are added to a working program.

Which of the following Boolean expressions are equivalent to the expression num 15 ? Select two answers. Selected Answers: [None Given]Answers: (num > 15) AND (num = 15) NOT (num < 15) NOT (num < 16) (num > 15) OR (num = 15)

NOT (num < 15) NOT (num < 16) (num > 15) OR (num = 15)

In the program below, the initial value of x is 5 and the initial value of y is 10. IF (x < 0){ DISPLAY ("Foxtrot") }ELSE{ IF (x > y){ DISPLAY ("Hotel") }ELSE{ IF (y > 0){ DISPLAY ("November") }ELSE{ DISPLAY ("Yankee") } } } What is displayed as a result of the running program? Selected Answer: November Answers: Yankee November Hotel Foxtrot

November

A programmer notices the following two procedures in a library. The procedures do similar, but not identical, things. Procedure returns the value . Procedure returns the value . Which of the following procedures is a generalization of the procedures described above? Selected Answer: [None Given]Answers: Procedure , which returns the value Procedure , which returns the value Procedure , which returns the value Procedure , which returns the value n + m

Procedure , which returns the value

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. Which of the following best describes the result of running the procedure? Selected Answer: [None Given]Answers: The procedure returns no matter what the input value is. The procedure returns no matter what the input value is. The procedure returns when the user inputs the value and returns otherwise. The procedure returns when the user inputs the value and returns otherwise.

The procedure returns no matter what the input value is.

Which of the following statements is true? Selected Answer: [None Given]Answers: There exist problems that no algorithm will ever be able to solve for all possible inputs. Every problem can be solved with an algorithm for all possible inputs, in a reasonable amount of time, using a modern computer. Every problem can be solved with an algorithm for all possible inputs, but some of these algorithms have not been discovered yet. Every problem can be solved with an algorithm for all possible inputs, but some will take more than 100 years, even with the fastest possible computer.

There exist problems that no algorithm will ever be able to solve for all possible inputs.

A media librarian at a movie studio is planning to save digital video files for archival purposes. The movie studio would like to be able to access full-quality videos if they are needed for future projects. Which of the following actions is LEAST likely to support the studio's goal? Selected Answer: [None Given]Answers: Using storage media that can be expanded for additional data capacity Using video file formats that conform to published standards and are supported across many differentdevices Using a system that incorporates redundancy to handle disk failure Using lossy compression software to reduce the size requirements of the data being stored

Using lossy compression software to reduce the size requirements of the data being stored

Complete the following sentence: A(n) ______________ is a set of steps we follow to complete a task while a(n) ____________ is a procedure intended to provide a reasonable, though not necessarily best, solution. Selected Answer: [None Given]Answers: heuristic, algorithm algorithm, heuristic abstraction, heuristic heuristic, abstraction

algorithm, heuristic

Ticket prices for a science museum are shown in the following table. Type of TicketGeneral Admission Cost(in dollars)Guided Tour Cost(in dollars)Regular (ages 13 and up)810Child (ages 12 and below)68 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? Selected Answer: [None Given]Answers:

cost - 6 if age > 12 cos - cost plus 2 if icludes tour cost - cost 2 display cost

A flowchart is a way to visually represent an algorithm. The flowchart below is used by an apartment rental Web site to set the variable to for apartments that meet certain criteria. Which of the following statements is equivalent to the algorithm in the flowchart? Selected Answer: [None Given]Answers:

iNclude - floor > 10 or bedrooms equal 3

A snack bar has a frequent customer program in which every 10th purchase is free. Customers are enrolled in the program when they make their first purchase. A programmer is writing a program to implement the frequent customer program. In one code segment, is set to for every 10th purchase by a given customer. The programmer will use the procedure , which returns the total number ofpurchases a customer has made since enrolling in the frequent customer program, including his or her first purchase. Which of the following code segments will set to for every 10th purchase a customer makes after enrolling in the frequent customer program? Selected Answer: Answers:

if (cout mod100)

In the following statement, val1, val2, and result are Boolean variables. Which of the following code segments produce the same result as the statement above for all possible values of val1 and val2 ? Select two answers. Selected Answers: [None Given]Answers:

if val1 if val2 result - false result - true result false

Consider a game in which a player flips a fair coin three times. If all three coin flips have the same result (either all heads or all tails) the player wins. Otherwise, the player loses. Which of the following code segments best simulates the behavior of the game? Selected Answer: [None Given]Answers:

spi 1/6 spi equal 1 yellow spi equal 2 lue red

A code segment will be used to swap the values of the variables a and b using a temporary variable temp. Which of the following code segments correctly swaps the values a and b? Selected Answer: [None Given]Answers: temp ab tempa b a btemp ab temp temp aa bb temp temp aa tempa b

temp - a a - b b temp

Consider the following procedures. PROCEDURE proc1(str) { DISPLAY(str) DISPLAY("happy") } PROCEDURE proc2(str1, str2) { proc1(str2) DISPLAY(str1) } What is displayed as a result of the procedure call proc2("birthday", "to you") ? Selected Answer: [None Given]Answers: birthday happy birthday birthday happy to you to you birthday happy to you happy birthday

to you happy birthday

You are writing a function called swap (list, x, y) which will exchange the position of the two values at indexes x and y in the list. Example: before and after a call to swap (list, 2, 3) on the list shown below The function header is defined below. Choose the three lines of code that will perform the swap correctly procedure swap (list, x, y) { <MISSING CODE> } Selected Answer: [None Given]Answers:list[x] ← temp;var temp ← list[y];list[y] ← list[x]; list[y] ← list[x];var temp ← list[y];list[x] ← temp; var temp ← list[y];list[x] ← temp; list[y] ← list[x]; var temp ← list[y];list[y] ← list[x];list[x] ← temp

var temp ← list[y]; list[y] ← list[x]; list[x] ← temp;

A flowchart is a way to visually represent an algorithm. The flowchart below is used by an application to set the Boolean variable available to true under certain conditions. The flowchart uses the Boolean variable weekday and the integer variable miles. BlockExplanationOvalThe start or end of the algorithmDiamondA conditional or decision step, where execution proceeds to the side labeled true if the condition is true and to the side labeled false otherwiseRectangleOne or more processing steps, such as a statement that assigns a value to a variable Which of the following statements is equivalent to the algorithm in the flowchart? Selected Answer: [None Given]Answers:

weekday ad miles < 20

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? Selected Answer: [None Given]Answers: x = 1, y = 2, z = 3 x = 3, y = 2, z = 1 x = 1, y = 3, z = 2 x = 2, y = 3, z = 1

x = 3, y = 2, z = 1

Assume that the Boolean variable x is assigned the value true and the Boolean variable y is assigned the value false. Which of the following will display the value true ? Select two answers. Selected Answers: [None Given]Answers:

x or y display x x display x or y


Related study sets

Enterprise Networking, Security, and Automation chapters 3-5

View Set

MIE CH 2: Strategic human resources management

View Set

Professionalism and Ethics for RBTs

View Set

BUS Chapter 6: Business Formation

View Set