AP Computer Science Unit 6 Test

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

The following question uses a robot in a grid of squares. The robot is represented by a triangle, which is initially facing up. Which of the following programs will move the robot to the gray square following the path shown on the grid? a. Repeat 2 times Repeat 3 times Move_Foward Turn Left b. Repeat 3 times Repeat 3 times Move_Foward Turn Left c. Repeat 2 times Repeat 2 times Move_Foward Turn Left d. Repeat 3 times Repeat 2 times Move_Foward Turn Left

a. Repeat 2 times Repeat 3 times Move_Foward Turn Left

ageList and gradeList contain information about students in a classroom. A programmer has already written the following code with that information. var ages = [16,17,18, 17] var names = ["Beni", "Analise", "Ricardo", "Tanya"] var filteredNames = []; Which of the following programs will result in filteredNames only containing the names of students who are 17 or older? a. for(var i = 0; i < ages.length; i++){ age = ages[i]; if(age >= 17){ appendItem(filteredNames, names[i])} b. for(var i = 0; i < ages.length; i++){ age = ages[i]; if(age < 17){ appendItem(filteredNames, names[i])} c. for(var i = 0; i < ages.length; i++){ age = ages[i]; if(age < 17){ appendItem(filteredNames, age)} d. for(var i = 0; i < ages.length; i++){ age = ages[i]; if(age >= 17){ appendItem(filteredNames, age)}

a. for(var i = 0; i < ages.length; i++){ age = ages[i]; if(age >= 17){ appendItem(filteredNames, names[i])}

What will the following program display in the console? var sum = 0; for(var i = 0; i < 5; i++){ sum = sum + i; } console.log(sum); a. 10 b. 0 c. 15 d. 5

a. 10

A programmer has a need to round many numeric values to the nearest integer. Which of the following best explains the benefit of using a list as a data abstraction in this situation? a. Keeping the numeric values in a list makes it easier to apply the same computation to every data element. b. Keeping the numeric values in a list makes it easier to prevent a program from attempting to access an index beyond the length of the list. c. Keeping the numeric values in a list makes it easier to round a number to the nearest integer. d. Keeping the numeric values in a list makes it easier to prevent a program from unintentionally changing the value of a variable.

a. Keeping the numeric values in a list makes it easier to apply the same computation to every data element.

Which of the following algorithms display all integers between 1 and 20, inclusive, that are not divisible by 3? Select two answers. a. Step 1: Set x to 0.Step 2: Increment x by 1.Step 3: If x is not divisible by 3, then display x.Step 4: Repeat steps 2 and 3 until x is 20. b. Step 1:Set x to 1. Step 2: If x is divisible by 3, then do nothing; otherwise display x.Step 3:Increment x by 1. Step 4: Repeat steps 2 and 3 until x is greater than 20. c. Step 1:Set x to 0.Step 2: If x is divisible by 3, then display x.Step 3:Increment x by 1. Step 4: Repeat steps 2 and 3 until x is greater than 20. d. Step 1:Set x to 1. Step 2: If x is divisible by 3, then do nothing; otherwise display x.Step 3:Increment x by 1. Step 4: Repeat steps 2 and 3 until x is 20.

a. Step 1: Set x to 0.Step 2: Increment x by 1.Step 3: If x is not divisible by 3, then display x.Step 4: Repeat steps 2 and 3 until x is 20. b. Step 1:Set x to 1. Step 2: If x is divisible by 3, then do nothing; otherwise display x.Step 3:Increment x by 1. Step 4: Repeat steps 2 and 3 until x is greater than 20.

var words = ["apple","bug","car","dream","ear", "food"] var filteredWords = []; for(var i = 0; i < words.length; i++){ var word = words[i]; if (word.length < 4){ appendItem(filteredWords,word) } console.log(filteredWords); If the program above is run, what will be displayed in the console? a. [bug, car, ear] b. [bug, car, ear, food] c. [apple, dream, food] d. [apple, dream]

a. [bug, car, ear]

A program is designed to determine the minimum value in a list of positive numbers called numList. The following program was written var minimum = <MISSING CODE> for(var i = 0; i < numList.length; i++){ if (numList[i] < minimum){ minimum = numList[i]; } console.log("The minimum is" + minimum); Which of the following can be used to replace <MISSING CODE> so that the program works as intended for every possible list of positive numbers a. numList[0] b. 0 c. numList.length d. 1000000

a. numList[0]

A restaurant knows from historical data that 60 out of 100 of its customers purchase a full meal while 40 out of 100 only order a side dish. The program below is intended to simulate the orders of 1000 customers. fullMeal 0 sideDish 0 REPEAT 1000 TIMES { IF (<MISSING CODE>) { fullMeal fullMeal + 1 } ELSE { sideDish sideDish + 1 } } DISPLAY (fullMeal) DISPLAY ("full meals were ordered,") DISPLAY (sideDish) DISPLAY ("side dishes were ordered.") Which of the following can be used to replace <MISSING CODE> so that the simulation works as intended? a. random(1,100) <= 60 b. random(1,100) = 40 c. random(1,100) = 60 d. random(1,100) <= 40

a. random(1,100) <= 60

Consider the following code segment. What is displayed as a result of executing the code segment? a. true true true b. true true false c. true false false d. true false true

a. true true true

What will the following program display in the console? for(var i = 0; i < 4; i++){ console.log(i); } a. 1 2 3 4 b. 0 1 2 3 c. 0 1 2 3 4 d. 1 2 3

b. 0 1 2 3

What will be displayed when this program finishes running? var numbersList = [20, 10, 5] appendItem(numbersList, 50) appendItem(numbersList,100) removeItem(numbersList,1) insertItem(numbersList, 0, 30) console.log(numbersList.length) a. 3 b. 5 c. 6 d. 7

b. 5

Which of the following is a benefit of using a simulation instead of an experiment to make a prediction? Select two answers. a. A simulation always produces the same output, so its results can be verified. b. A simulation can be used to model real-world events that are impractical for experiments. c. A simulation produces results that are more accurate than experimental results. d. A simulation allows investigation of a phenomenon without the real-world limitations on time, safety, or budget.

b. A simulation can be used to model real-world events that are impractical for experiments. d. A simulation allows investigation of a phenomenon without the real-world limitations on time, safety, or budget.

The following grid contains a robot represented as a triangle, which is initially facing right. The following code segment is intended to move the robot to the gray square. <MISSING STATEMENT> { REPEAT 4 TIMES { MOVE_FORWARD() ROTATE_RIGHT() } ROTATE_LEFT() MOVE_FORWARD() ROTATE_RIGHT() } Which of the following can be used as a replacement for <MISSING STATEMENT> so that the code segment works as intended? a. REPEAT 3 TIMES b. REPEAT 2 TIMES c. REPEAT 4 TIMES d. REPEAT 1 TIMES

b. REPEAT 2 TIMES

A job placement agency helps match job seekers with potential employers. The agency would like to design a simulation in order to help predict the likely job placement outcomes for job seekers based on historical trends and patterns. Which of the following is most likely to be a benefit of the simulation? a. The computer simulation will be able to precisely predict the real-world outcomes for each job seeker. b. The computer simulation could be used to test hypotheses about patterns in the job placement process that are costly or time consuming to observe in reality. c. The computer simulation will remove the bias that may arise in the real-world job placement process. d. The computer simulation will be able to include more details and complexity than the real-world job placement process.

b. The computer simulation could be used to test hypotheses about patterns in the job placement process that are costly or time consuming to observe in reality.

Consider the following code segment. What are the contents of yourList after the code segment is executed? a. [10, 30, 50, 70, 20, 40, 60, 80] b. [10, 30, 50, 70] c. [20, 40, 60, 80] d. [20, 40, 60, 80, 10, 30, 50, 70]

b. [10, 30, 50, 70]

list = [10, 5, 15]; for(var i = 0; <INSERT CODE>; i++){ console.log(list[i]); } Which of the following will NOT result in an error if placed where the program reads <INSERT CODE> and the program is run? a. i < list[list.length] b. i < list.length c. i < list[0] d. i < list[1]

b. i < list.length

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 (right)) { MOVE_FORWARD () } ROTATE_RIGHT () b. REPEAT UNTIL (CAN_MOVE (forward) = false) { ROTATE_RIGHT () } MOVE_FORWARD () c. REPEAT UNTIL (CAN_MOVE (forward) = false) { MOVE_FORWARD () } ROTATE_RIGHT () d. REPEAT UNTIL (CAN_MOVE (right)) { ROTATE_RIGHT () } MOVE_FORWARD ()

c. REPEAT UNTIL (CAN_MOVE (forward) = false) { MOVE_FORWARD () } ROTATE_RIGHT ()

What will be displayed in the console when this program runs? var numList = [10,20,30]; console.log(numList[numlist.length-1]); a. 3 b. 2 c. 30 d. 20

c. 30

The list wordList contains a list of 10 string values. Which of the following is a valid index for the list? a. "hello" b. 2.5 c. 4 d. -1

c. 4

Suppose a large group of people in a room were all born in the same year. Consider the following three algorithms, which are each intended to identify the people in the room who have the earliest birthday based on just the month and day. For example, a person born on February 10 is considered to have an earlier birthday than a person born on March 5. Which of the three algorithms will identify the correct people? a. I only b. II and III c. II only d. I and II

c. II only

What will be displayed in the console when the following program runs? var count = 0 while (count != 5){ console.log(count); count = count + 2; } a. 0 2 4 b. 0 2 4 6 c. The program will result in an infinite loop d. 2 4 6

c. The program will result in an infinite loop

Consider the following code segment. firstList ← ["guitar", "drums", "bass"] secondList ← ["flute", "violin"] thirdList ← [] thirdList ← firstList firstList ← secondList secondList ← thirdList What are the contents of secondList after the code segment is executed?^ a. ["flute", "violin", "guitar", "drums", "bass"] b. [] c. ["guitar", "drums", "bass"] d. ["flute", "violin"]

c. ["guitar", "drums", "bass"]

Assume that both lists and strings are indexed starting with index 1. The list wordList has the following contents. ["abc", "def", "ghi", "jkl"] Let myWord be the element at index 3 of wordList. Let myChar be the character at index 2 of myWord. What is the value of myChar ? a. "f" b. "i" c. "e" d. "h"

d. "h"

A car manufacturer uses simulation software during the design process for a new car. Which of the following are reasons to use simulation software in this context? - Using simulation software can save the company money by helping to compare designs early in the process, before prototype cars are built. - Using simulation software can help to identify safety issues by providing data about how different mechanical components will interact in a wide variety of situations. - The manufacturer can present simulation software to customers to demonstrate different design possibilities. a. II and III only b. I and II only c. I and III only d. I, II, and III

d. I, II, and III

Which of the following is a benefit of using a list as a data abstraction in a program? a. Lists convert all elements to strings so that they can be inspected character-by-character. b. Lists are used to store all input data so that there is a running record of all user input. c. Lists prevent duplicate data values from appearing in the list. d. Lists often allow their size to be easily updated to hold as many data values as needed.

d. Lists often allow their size to be easily updated to hold as many data values as needed.

A school is developing a program to keep track of information about students and their class schedules. In which of the following instances would a data abstraction be most helpful? a. A program includes multiple comments that could be combined into a single comment b. A program includes repeated code that could be moved inside a function. c. A program includes repeated programming statements that could be moved inside a loop d. The program includes individual variables to store the names of each student rather than a single list of students.

d. The program includes individual variables to store the names of each student rather than a single list of students.

A 2-sided coin has an equal likelihood of landing on each side. One side is called "heads" and the other is called "tails". The program below simulates randomly flipping that coin many times. var heads = 0; var tails = 0; var rolls = 100; for(var i = 0; i < rolls; i++){ if(randomNumber(0,1) == 0){ heads++ } else { tails++ } } Which of the following is NOT a possible combination of values of the variables in this program when it finishes running? a. tails has a value of 0 and heads has a value of 100 b. tails has a value of 100 and heads has a value of 0 c. tails has a value of 50 and heads has a value of 50 d. tails has a value of 20 and heads has a value of 20

d. tails has a value of 20 and heads has a value of 20

wordList is a list of words that currently contains the values ["tree", "rock", "air"] Which of the following lines will result in the list containing the values ["air", "rock", "air"] a. removeItem(wordList,0) b. wordList[2] = wordList[0] c. insertItem(wordList, 0, "air") d. wordList[0] = wordList[2]

d. wordList[0] = wordList[2]


Ensembles d'études connexes

Prep U for Brunner and Suddarth's Textbook of Medical Surgical Nursing, 13th Edition Chapter 65: Assessment of Neurologic Function

View Set

Pharmacology Chapter 9 Antibiotics

View Set

Personal Finance Exam 2 (Ch.5-8)

View Set

Econ 488: International Trade & Finance

View Set