comp sci unit 6 and 7

Ace your homework & exams now with Quizwiz!

The drawCircle procedure is to be used to draw the following figure on a coordinate grid. Which of the following code segments can be used to draw the figure? Select two answers.

B. x ← 4 y ← 1 r ← 0 REPEAT 3 TIMES { r ← r + 1 y ← y + 1 drawCircle(x, y, r) } C x ← 4 y ← 4 r ← 3 REPEAT 3 TIMES { drawCircle(x, y, r) y ← y - 1 r ← r - 1

rograms I and II below are each intended to calculate the sum of the integers from 1 to n. Assume that n is a positive integer (e.g., 1, 2, 3, ...). Which of the following best describes the behavior of the two programs?

Both program I and program II display the correct sum.

Which of the following statements describes a limitation of using a computer simulation to model a real-world object or system?

Computer simulations usually make some simplifying assumptions about the real-world object or system being modeled.

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.

I, II, and III

Consider the following code segment with an integer variable num. IF(num > 0) { DISPLAY("positive") } IF(num < 0) { DISPLAY("negative") } IF(num = 0) { DISPLAY("zero") } Which of the following code segments is equivalent to the code segment above?

IF(num < 0) { DISPLAY("negative") } ELSE { IF(num = 0) { DISPLAY("zero") } ELSE { DISPLAY("positive") } }

The following code segment is intended to create lunchList, which is initially empty. It uses the procedure IsFound (list, name), which returns true if name is found in list and returns false otherwise.Which of the following could replace <MISSING CODE> so that the code segment works as intended?

If(isFound(afternoonList, child)) append(lunchList, child)

Which of the following is a benefit of using a list as a data abstraction in a program?

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

Which of the following best describes the result of running the program code?

Nothing is displayed; the program results in an infinite loop.

Which of the following is a correct implementation of the getRange procedure?

PROCEDURE getRange(min, max, promptString) { DISPLAY(promptString) x ← INPUT() REPEAT UNTIL(x ≥ min AND x ≤ max) { DISPLAY(promptString) x ← INPUT() } RETURN(x) }

The game program's author would like to write a procedure that could be used to update any variable in the game (myScore) that has a maximum value (myLimit) by a given amount (myAmount). A correct call of the procedure is shown below. myScore ← updateScore(myScore, myAmount, myLimit) Which of the following is a correct implementation of updateScore ?

PROCEDURE updateScore(score, amount, limit) { score ← score + amount IF(score > limit) { score ← limit } RETURN(score) }

Which of the following are benefits of procedural abstraction? Select two answers.

Procedural abstraction makes it easier for people to read computer programs. D Procedural abstraction provides an opportunity to give a name to a block of code that describes the purpose of the code block.

Which of the following code segments can be used to move the robot to the gray square?

REPEAT 3 TIMES { MOVE_FORWARD() } ROTATE_LEFT() REPEAT 2 TIMES { MOVE_FORWARD() } ROTATE_RIGHT() REPEAT 3 TIMES { MOVE_FORWARD() }

A list of numbers has n elements, indexed from 1 to n. The following algorithm is intended to display the number of elements in the list that have a value greater than 100. The algorithm uses the variables count and position. Steps 3 and 4 are missing. Step 1Set count to 0 and position to 1.Step 2If the value of the element at index position is greater than 100, increase the value of count by 1.Step 3(missing step)Step 4(missing step)Step 5Display the value of count. Which of the following could be used to replace steps 3 and 4 so that the algorithm works as intended?

Step 3 Increase the value of position by 1. Step 4 Repeat steps 2 and 3 until the value of position is greater than n.

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?

The conclusion is incorrect; using the test case [0, 1, 4, 5] is not sufficient to conclude the program is correct.

A city planner is using simulation software to study crowd flow out of a large arena after an event has ended. The arena is located in an urban city. Which of the following best describes a limitation of using a simulation for this purpose?

The model used by the simulation software often omits details so that it is easier to implement.

In the procedure Mystery below, the parameter number is a positive integer. Which of the following best describes the result of running the procedure Mystery?

The procedure returns true when the initial value of number is even, and it otherwise returns false.

The transportation department plans to build a new high-speed train route between two cities. The transportation department wants to implement a simulation of the train before any construction begins on this project. Which of the following statements is true about the use of a simulation for this project?

Using a simulation may expose potential safety issues that can be corrected before construction begins.

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?

["guitar","drums","bass"]

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

Procedure CallExplanationconcat(str1, str2)Returns a single string consisting of str1 followed by str2. For example, concat("key", "board") returns "keyboard".substring(str, start, length)Returns a substring of consecutive characters from str, starting with the character at position start and containing length characters. The first character of str is located at position 1. For example,substring("delivery", 3, 4) returns "live".len(str)Returns the number of characters in str. For example, len("pizza") returns 5. Assume that the string oldString contains at least 4 characters. A programmer is writing a code segment that is intended to remove the first two characters and the last two characters from oldString and assign the result to newString. For example, if oldString contains "student", then newString should contain "ude". Which of the following code segments can be used to assign the intended string to newString ?

a. newString ← substring(oldString, 3, len(oldString) - 4) c.tempString ← substring(oldString, 3, len(oldString) - 2) newString ← substring(tempString, 1, len(tempString) - 2)

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?

b

In the following code segment, assume that x and y have been assigned integer values. sum ← 0 REPEAT x TIMES { REPEAT y TIMES { sum ← sum + 1 } } At the end of which of the following code segments is the value of sum the same as the value of sum at the end of the preceding code segment? Select two answers.

b. sum ← 0 z ← x * y REPEAT z TIMES { sum ← sum + 1 d. sum ← 0 REPEAT y TIMES { REPEAT x TIMES { sum ← sum + 1 } }

The student later decides to modify the procedure to calculate the sum of the integers from 1 to max, which represents any positive integer greater than 1. Which of the following changes should be made to the procedure to meet the student's goal? The procedure should take max as an input parameter. The condition in the REPEAT UNTIL block should be changed to count > max. The condition in the REPEAT UNTIL block should be changed to max < 5.

c. I and II

In which of the following scenarios is using a simulation more beneficial than performing a calculation? Select two answers.

c. Investigating ways to reduce the amount of trash in the ocean d. Studying the effect of a genetic change in a population

A student is developing a program that allows users to look up the definitions of words that appear in a book. The student plans to perform a large number of searches through a dictionary containing words and their definitions. The student will use a procedure written by a computer scientist to quickly search the dictionary (and knows that the procedure will return a definition if one is available). The student cannot modify the search procedure written by the computer scientist but can call the procedure by supplying a word. Which of the following is a true statement about the student's use of the computer scientist's search procedure?

c. The student is reusing the computer scientist's procedural abstraction by knowing what the procedure does without knowing how it does it.

Consider the following code segment. theList ← [-2, -1, 0, 1, 2] count1 ← 0 count2 ← 0 FOR EACH value IN theList { IF(value > 0) { count1 ← count1 + 1 } ELSE { count2 ← count2 + 1 } } What are the values of count1 and count2 as a result of executing the code segment?

count1 = 2, count2 = 3

For which of the following problems is using a simulation LEAST likely to be beneficial?

determining the longest word in a textbook

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?

drawCircle(x, y, r) drawCircle(x, y + 3, r) drawCircle(x + 3, y, r) drawCircle(x + 3, y + 3, r)

Let the value of the variable xVal be 6 and the value of the variable yVal be 5. Which of the following code segments can be used to draw the figure?

drawLine(1, 5, xVal, yVal) drawline(1, 5, xVal, yVal + 2) drawline(1, 5, xVal, yVal - 2)

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

j=6

A computer science student completes a program and asks a classmate for feedback. The classmate suggests rewriting some of the code to include more procedural abstraction. Which of the following is NOT a benefit of procedural abstraction?

making the code run faster

Consider the procedure MoveAndTurn below.

move and turn 2,1 move and turn 4,3 move and turn 2,0

Which of the following code segments will correctly create newList ?

newList ← Combine (list1, list2) newList ← Sort (newList) newList ← RemoveDuplicates (newList)

Consider the goal of using the device to produce the following drawing, where each line shown has a length of 10 units and the horizontal lines are 10 units apart. The device is positioned at the upper-left corner of a sheet of paper and is facing right. Which of the following code segments will produce the drawing shown?

penDown() goForward(10) penUp() turnRight(90) goForward(10) turnRight(90) penDown() goForward(10)

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?

repeat 2 times

A new bank plans to make customer convenience a priority by minimizing the amount of time a customer waits in line. The bank is considering two options: a single line where the customer at the front waits for the next available teller, or separate lines for each teller. The bank decides to use a computer simulation of these two options to determine the average wait time for customers. Which of the following is NOT true about the bank's plan?

the simulation will not produce usable results because actual customer data are not available.

Consider the following procedure. PROCEDURE doSomething(num1, num2) { DISPLAY(num1) RETURN(num1) DISPLAY(num2) } Consider the following statement. DISPLAY(doSomething(10, 20)) What is displayed as a result of executing the statement above?

10 10

Consider the following code segment. Assume that index1 is a number between 1 and LENGTH(theList), inclusive, and index2 is a number between 2 and LENGTH(theList) - 1, inclusive. theList ← [9, -1, 5, 2, 4, 8] x ← theList[index1] + theList[index2] What is the largest possible value that the variable x can have after the code segment executes?

14

What is the value of result after the code segment is executed?

15

Which of the following initial values of the variable y would result in the variable z being set to 2 after the code segment is executed?

3

In the program below, y is a positive integer (e.g., 1, 2, 3, ...). What is the value of after running the program?

3y

The list wordList contains a list of 10 string values. Which of the following is a valid index for the list?

4

Consider the following program, which is intended to display the number of times a number target appears in a list. Which of the following best describes the behavior of the program?

A The program correctly displays the number of times target appears in the list.

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.

A and D

In which of the following scenarios would a simulation be the LEAST beneficial?

A retail company wants to determine the most popular item that was sold on the company's Web site last month.


Related study sets

Exam 4 Chapter 14 Interpersonal Attraction

View Set

Principles of Management Chapter 9

View Set

Chapter 28: The Child with Cerebral Dysfunction

View Set

Chapter 32 Cholinergic Agonists PrepU

View Set

PSYCH 3100 Personality Psychology - Chapter 8

View Set

Human Origins and the Neolithic Revolution

View Set

THERE IS, THERE ARE......SOME, ANY. Se pueden sustituir por cualquier cardinal

View Set

Unit 1: The Living World - Ecosystems

View Set