Unit 5 Com Sci

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/14

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

15 Terms

1
New cards

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. The program includes individual variables to store the names of each student rather than a single list of students.

B. A program includes multiple comments that could be combined into a single comment

C. A program includes repeated programming statements that could be moved inside a loop

D. A program includes repeated code that could be moved inside a function.

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

2
New cards

var list = [10, 5, 15]; for(var i = 0; ; i++){ console.log(list[i]); }

Which of the following will result in ONLY all the items in list being printed to the console if placed where the program reads 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

3
New cards

3. 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. wordList[0] = wordList[2]

B. wordList[2] = wordList[0]

C. insertItem(wordList, 0, "air")

D. removeItem(wordList,0)

A. wordList[0] = wordList[2]

4
New cards

4.What will be displayed in the console when this program runs?

var numList = [10,20,30]; console.log(numList[numList.length-1]);

A. 2

B. 3

C. 20

D. 30

D. 30

5
New cards

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

C. 7

D. 5

D. 5

6
New cards

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

B. 024

C. 246

D. The program will result in an infinite loop

D. The program will result in an infinite loop

7
New cards

7.What will the following program display in the console?

for(var i = 0; i < 4; i++){ console.log(i); }

A. 0123

8
New cards

8.

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

B. 5

C. 10

D. 15

C. 10

9
New cards

9.

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.

B.

C.

D.

A.

10
New cards

0.

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 = []; var age;

Which of the following programs will result in filteredNames only containing the names of students who are 17 or older?

for(var =i =0; < ages.length;++){

age = age[i]

if(age >= 17){

appendItem(filteredNames, names[i])

}

11
New cards

11. 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. [apple, dream]

B. [bug, car, ear]

C. [bug, car, ear, food]

D. [apple, dream, food]

B. [bug, car, ear]

12
New cards

12.

A program is designed to determine the minimum value in a list of positive numbers called numList. The following program was written

var minimum = 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 so that the program works as intended for every possible list of positive numbers?

A. 0

B. 1000000

C. numList.length

D. numList[0]

D. numList[0]

13
New cards

13.

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 20 and heads has a value of 20

D. tails has a value of 50 and heads has a value of 50

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

14
New cards

14. 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 () { 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 so that the simulation works as intended?

A. random(1,100) = 40

B. random(1,100) = 60

C. random(1,100) <= 40

D. random(1,100) <= 60

D. random(1,100) <= 60

15
New cards

15.

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

C. The computer simulation will be able to precisely predict the real-world outcomes for each job seeker.

D. The computer simulation will remove the bias that may arise in 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.