CS Principles: Unit 4 AP Practice

¡Supera tus tareas y exámenes ahora con Quizwiz!

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 program contains the following procedures for string manipulation. Which of the following expressions can be used to generate the string ?

b

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? a) Making the code more readable b) Making the code run faster c) Providing more opportunities for code reuse d) Reducing the amount of duplicated code

b

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? a) Procedure Min (x, y), which returns the lesser of its two integer parameters b) Procedure Max (numList), which returns the maximum value in the list of integers numList c) Procedure MaxFour (w, x, y, z), which returns the greatest of its four integer parameters d) Procedure OverMax (numList, max), which returns the number of integers in numList that exceed the integer value max

d

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)

c

A student has a data file containing 10,000 numerical values. The student is writing a program to compute the average of the numbers contained in the file. Which of the following procedures is most likely to be useful in the student's program? a) A procedure that returns the quotient when dividing one value by another b) A procedure that returns the sum when adding one value to another c) A procedure that returns the sum of the values in the file d) A procedure that returns true if the file contains any duplicate values and returns false otherwise

b

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)

d

Consider the following procedures. What is displayed as a result of the procedure call proc2("birthday", "to you") ? a) birthday happy to you b) birthday happy birthday c) to you birthday happy d) to you happy birthday

a, d

Directions: For the question or incomplete statement below, two of the suggested answers are correct. For this question, you must select both correct choices to earn credit. No partial credit will be earned if only one correct choice is selected. Select the two that are best in each case. Which of the following are ways in which a programmer can use abstraction to manage the complexity of a program? Select two answers. a) Replacing each instance of repeated code with a call to a procedure b) Replacing longer variable names with shorter variable names to reduce typing errors c) Replacing several lines of documentation with a single line of documentation d) Replacing several lines of documentation with a single line of documentation name1, name2, name3, and name4 with a list of strings called names

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. A programmer notices the following two procedures in a library. The procedures do similar, but not identical, things. Procedure returns the value n^2. Procedure returns the value n^3. Which of the following procedures is a generalization of the procedures described above? a) Procedure Add(n, m) which returns the value n + m b) Procedure Fourth(n), which returns the value n^4 c) Procedure Polynomial(n), which returns the value n^3 + n^2 d) Procedure Power(n, m), which returns the value n^m

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. 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? a) The procedure returns true when the user inputs the value "y" and returns false otherwise. b) The procedure returns true when the user inputs the value "n" and returns false otherwise. c) The procedure returns true no matter what the input value is. d) The procedure returns false no matter what the input value is.

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. Consider the two programs below. Which of the following best compares the values displayed by programs A and B? a) Program A and program B display identical values. b) Program A and program B display the same values in different orders. c) Program A and program B display the same number of values, but the values differ. d) Program A and program B display a different number of values

c

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? a) The procedure returns true when the initial value of number is 2, and it otherwise returns false. b) The procedure returns true when the initial value of number is greater than 2, and it otherwise returns false. c) The procedure returns true when the initial value of number is even, and it otherwise returns false. d) The procedure returns true when the initial value of number is odd, and it otherwise returns false.

d

The following code segment is used to determine whether a customer is eligible for a discount on a movie ticket. 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

a, d

The following table shows the value of expression based on the values of input1 and input2. Which of the following expressions are equivalent to the value of expression as shown in the table? Select two answers. a) (NOT input1) OR (NOT input2) b) (NOT input1) AND (NOT input2) c) NOT (input1 OR input2) d) NOT (input1 AND input2)

b

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?

b

To attend a particular camp, a student must be either at least 13 years old or in grade 9 or higher, but must not yet be 18 years old. Let age represent a student's age and let grade represent the student's grade level. Which of the following expressions evaluates to true if the student is eligible to attend the camp and evaluates to false otherwise? a) ((age ≥ 13) OR (grade ≥ 9)) AND (age ≤ 18) b) ((age ≥ 13) OR (grade ≥ 9)) AND (age < 18) c) ((age ≥ 13) OR (grade ≥ 9)) OR (age ≤ 18) d) ((age ≥ 13) OR (grade ≥ 9)) OR (age < 18)

c, d

Which of the following are benefits of procedural abstraction? Select two answers. a) Procedural abstraction prevents programmers from accidentally using the intellectual property of other programmers. b) Procedural abstraction eliminates the need for programmers to document their code. c) 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.

b

Which of the following procedures would be most useful as part of a program to determine whether a word appears in two different text files? a) A procedure getWords, which takes a positive integer n and a text file as input and returns the first n words in the text file. b) A procedure isFound, which takes a word and a text file as input and returns true if the word appears in the text file c) A procedure textMatch, which takes two text files as input and returns true if the two text files are identical. d) A procedure sameSize, which takes two text files as input and returns true if the two text files contain the same number of words.


Conjuntos de estudio relacionados

AP World History - 10th Grade Midterm

View Set

Russian Words that start with B part 1

View Set

Nursing Psych Prep-U Practice Ch. 31: Addiction And Substance Related Disorders

View Set

ACC-205 Business Law - Worksheet 18.3: Piercing the Corporate Veil & Corporate Directors and Officers

View Set