AP CPS

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

A large spreadsheet contains the following information about local restaurants. A sample portion of the spreadsheet is shown below. A Restaurant Name B Price Range C Number of Customer Ratings D Average Customer Rating E Accepts Credit Cards 1 Joey Calzone's Pizzeria lo 182 3.5 false 2 78th Street Bistro med 41 4.5 false 3 Seaside Taqueria med 214 4.5 true 4 Delicious Sub Shop II lo 202 4.0 false 5 Rustic Farm Tavern hi 116 4.5 true 6 ABC Downtown Diner med 0 -1.0 true In column B, the price range represents the typical cost of a meal, where "lo" indicates under $10, "med" indicates $11 to $30, and "hi" indicates over $30. In column D, the average customer rating is set to -1.0 for restaurants that have no customer ratings. A student wants to count the number of restaurants in the spreadsheet whose price range is $30 or less and whose average customer rating is at least 4.0. For a given row in the spreadsheet, suppose prcRange contains the price range as a string and avgRating contains the average customer rating as a decimal number. Which of the following expressions will evaluate to true if the restaurant should be counted and evaluates to false otherwise?

(avgRating ≥ 4.0) AND ((prcRange = "lo") OR (prcRange = "med"))

A flowchart provides a way to visually represent an algorithm and uses the following building blocks. Block Explanation Oval The start or end of the algorithm Rectangle One or more processing steps, such as a statement that assigns a value to a variable Diamond A conditional or decision step, where execution proceeds to the side labeled true if the condition is true and to the side labeled false otherwise Parallelogram Displays a message In the flowchart below, assume that j and k are assigned integer values. The figure presents a flow chart of an algorithm. Beginning at the top of the flow chart, the algorithm begins with a step labeled Start, which flows into a processing step labeled result ← 0, which flows into a conditional step labeled k = 0. If the condition is true, the process flows into a processing step labeled DISPLAY (result), which flows into a step labeled End. If the condition is false, the process flows into a processing step labeled result ← result + j and k ← k - 1, which flows back into the conditional step labeled k = 0. Based on the algorithm represented in the flowchart, what value is displayed if j has the initial value 3 and k has the initial value 4 ?

12

Consider the following code segment. The figure presents 5 lines of code. Throughout the code there are nested blocks of code, as follows. Line 1: [begin block] integerList ← [begin block] 4, 2, 5, 4, 2, 3, 1 [end block] [end block] Line 2: [begin block] result ← 0 [end block] [Begin Block] Line 3: FOR EACH item IN integerList [Begin Block] Line 4: [begin block] result ← result + (item MOD 2) [end block] [End block] [End Block] [begin block] Line 5: DISPLAY [begin block] result [end block] [end block] What value is displayed as a result of executing the code segment?

3

A game is played by moving a game piece left or right along a horizontal game board. The board consists of spaces of various colors, as shown. The circle represents the initial location of the game piece. Yellow Black Green Green Red Yellow Black Black Yellow Black ● The following algorithm indicates how the game is played. The game continues until the game is either won by landing on the red space or lost when the piece moves off either end of the board. Step 1: Place a game piece on a space that is not red and set a counter to 0. Step 2: If the game piece is on a yellow space, move the game piece 3 positions to the left and go to step 3. Otherwise, if the game piece is on a black space, move the game piece 1 position to the left and go to step 3. Otherwise, if the game piece is on a green space, move the game piece 2 positions to the right and go to step 3. Step 3: Increase the value of the counter by 1. Step 4: If game piece is on the red space or moved off the end of the game board, the game is complete. Otherwise, go back to step 2. If a game is begun by placing the game piece on the rightmost black space for step 1, what will be the value of the counter at the end of the game?

4

The following code segment is intended to remove all duplicate elements in the list myList. The procedure does not work as intended. j ← LENGTH(myList) REPEAT UNTIL(j = 1) { IF(myList[j] = myList[j - 1]) { REMOVE(myList, j) } j ← j - 1 } For which of the following contents of myList will the procedure NOT produce the intended results? Select two answers.

A and C

The following procedures are available for string manipulation. Procedure Call Explanation substring(str, start, end) Returns a substring of consecutive characters of str starting with the character at position start and ending with the character at position end. The first character of str is considered position 1. For example, substring("delivery", 3, 6) returns "live". concat(str1, str2) Returns a single string consisting of str1 followed by str2. For example, concat("key", "board") returns "keyboard". len(str) Returns the number of characters in str. For example, len("key") returns 3. A programmer wants to create a new string by removing the character in position n of the string oldStr. For example, if oldStr is "best" and n is 3, then the new string should be "bet". Assume that 1 < n < len(oldStr). Which of the following code segments can be used to create the desired new string and store it in newStr ? Select two answers.

A and C

The following table shows the value of expression based on the values of input1 and input2. Value of input1 Value of input2 Value of expression true true false true false true false true true false false true Which of the following expressions are equivalent to the value of expression as shown in the table? Select two answers.

A and D

The following question uses a robot in a grid of squares. The robot is represented by a triangle, which is initially facing right. The figure presents a robot in a grid of squares with 7 columns and 6 rows. The robot is represented by a triangle, which is initially in the bottom left square of the grid, facing rightwards. A path of arrows shows the robot's movement from its initial location to a gray square in the top right square of the grid. The path the robot takes is as follows. The robot moves 2 squares to the right, turns upwards, moves 2 squares upwards, turns rightwards, moves 4 squares to the right, turns upwards, moves 3 squares upwards where it turns rightwards and ends. Consider the following procedure. The figure presents a block of code that consists of 7 lines. Throughout the code there are nested blocks of code, as follows. [Begin Block] Line 1: PROCEDURE botStepper [begin block] n [end block] [Begin Block] Line 2: [Begin Block] REPEAT n TIMES [Begin Block] Line 3: [begin block] MOVE_FORWARD [end block] [End Block] [End Block] Line 4: [begin block] ROTATE_LEFT [end block] [Begin Block] Line 5: REPEAT n TIMES [Begin Block] Line 6: [begin block] MOVE_FORWARD [end block] [End block] [End Block] Line 7: [begin block] ROTATE_RIGHT [end block] [End Block] [End Block] Which of the following code segments will move the robot to the gray square along the path indicated by the arrows?

C

a certain video game, players are awarded bonus points at the end of a level based on the value of the integer variable timer. The bonus points are awarded as follows. If timer is less than 30, then 500 bonus points are awarded. If timer is between 30 and 60 inclusive, then 1000 bonus points are awarded. If timer is greater than 60, then 1500 bonus points are awarded. Which of the following code segments assigns the correct number of bonus points to bonus for all possible values of timer ? Select two answers.

D

The figure below represents a network of physically linked devices labeled A through I. A line between two devices indicates that the devices can communicate directly with each other. Any information sent between two devices that are not directly connected must go through at least one other device. For example, in the network represented below, information can be sent directly between A and B, but information sent between devices A and G must go through other devices. The figure presents a network of physically linked devices, labeled A through I. Connections are represented by lines between the devices, as follows. Device A is connected to B and C. Device B is connected to A, D, E, and G. Device C is connected to A, D, F, and I. Device D is connected to B, C, and F. Device E is connected to B, F, G, and H. Device F is connected to C, D, E, H, and I. Device G is connected to B and E. Device H is connected to E and F. Device I is connected to C and F. What is the minimum number of connections that must be broken or removed before device B can no longer communicate with device C?

Four

The grid below contains a robot represented as a triangle, initially facing toward the top of the grid. The robot can move into a white or gray square but cannot move into a black region. The figure presents a robot in a grid of squares surrounded by black regions. The robot is represented by a triangle which is initially facing the top of the grid. The path that the robot can take is as follows. Note: Assume all squares are white unless otherwise indicated. The robot can move 3 squares forward, at which point it reaches an intersection of squares. It can then either move 2 squares to the right, 2 squares forward, or 3 squares to the left. If the robot moves 3 squares to the left, it can then move 3 squares downwards at which point it will reach a gray square. 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?

IF(CAN_MOVE(left)) { ROTATE_LEFT() } MOVE_FORWARD()

The figure below represents a network of physically linked devices labeled A through I. A line between two devices indicates that the devices can communicate directly with each other. Any information sent between two devices that are not directly connected must go through at least one other device. For example, in the network represented below, information can be sent directly between A and B, but information sent between devices A and G must go through other devices. The figure presents a network of physically linked devices, labeled A through I. Connections are represented by lines between the devices, as follows. Device A is connected to B and C. Device B is connected to A, D, E, and G. Device C is connected to A, D, F, and I. Device D is connected to B, C, and F. Device E is connected to B, F, G, and H. Device F is connected to C, D, E, H, and I. Device G is connected to B and E. Device H is connected to E and F. Device I is connected to C and F. Which of the following statements is true about the network?

If devices B and F fail, then device A will not be able to communicate with device G.

In the following procedure, the parameter age represents a person's age. The procedure is intended to return the name of the age group associated with age. People who are under 18 are considered minors, people who are 65 and older are considered senior citizens, and all other people are considered adults. The procedure does not work as intended. Line 1: PROCEDURE ageGroup(age) Line 2: { Line 3: result ← "adult" Line 4: IF(age ≥ 65) Line 5: { Line 6: result ← "senior citizen" Line 7: } Line 8: RETURN(result) Line 9: Line 10: result ← "adult" Line 11: IF(age < 18) Line 12: { Line 13: result ← "minor" Line 14: } Line 15: RETURN(result) Line 16: } Removing which two lines of code will cause the procedure to work as intended? Select two answers.

Line 8 and Line 10

A list of numbers is considered increasing if each value after the first is greater than or equal to the preceding value. The following procedure is intended to return true if numberList is increasing and return false otherwise. Assume that numberList contains at least two elements. Line 1: PROCEDURE isIncreasing(numberList) Line 2: { Line 3: count ← 2 Line 4: REPEAT UNTIL(count > LENGTH(numberList)) Line 5: { Line 6: IF(numberList[count] < numberList[count - 1]) Line 7: { Line 8: RETURN(true) Line 9: } Line 10: count ← count + 1 Line 11: } Line 12: RETURN(false) Line 13: } Which of the following changes is needed for the program to work as intended?

Lines 8 and 12 should be interchanged.

In a science experiment, result X is expected to occur 25% of the time and result Y is expected to occur the remaining 75% of the time. The following code segment is intended to simulate the experiment if there are 100 trials. Line 1: xCount ← 0 Line 2: yCount ← 0 Line 3: REPEAT 100 TIMES Line 4: { Line 5: IF(RANDOM(1, 4) = 1) Line 6: { Line 7: xCount ← xCount + 1 Line 8: } Line 9: IF(RANDOM(1, 4) > 1) Line 10: { Line 11: yCount ← yCount + 1 Line 12: } Line 13: } Line 14: DISPLAY("Result X occurred") Line 15: DISPLAY(xCount) Line 16: DISPLAY("times and result Y occurred") Line 17: DISPLAY(yCount) Line 18: DISPLAY("times.") A programmer runs the code segment, and the following message is displayed. Result X occurred 24 times and result Y occurred 70 times. The result shows that 94 trials were counted, rather than the intended 100 trials. Which of the following changes to the code segment will ensure a correct simulation of the experiment?

Replacing line 9 with ELSE

Which of the following statements about the Internet is true?

The Internet is designed to scale to support an increasing number of users.

In the following procedure, the parameter n is an integer greater than 2. The figure presents a block of code that consists of 7 lines. Throughout the code there are nested blocks of code, as follows. [Begin Block] Line 1: PROCEDURE compute [begin block] n [end block] [Begin Block] Line 2: [begin block] result ← 1 [end block] Line 3: [begin block] j ← 2 [end block] [Begin Block] Line 4: REPEAT UNTIL [begin block] j ˃ 2 [end block] [Begin Block] Line 5: [begin block] result ← result + j [end block] Line 6: [begin block] j ← j + 1 [end block] [End Block] [End Block] Line 7: [begin block] RETURN [begin block] result [end block] [end block] [End Block] [End Block] Which of the following best describes the value returned by the procedure?

The procedure returns the sum of the integers from 1 to n.

RunRoutr is a fitness tracking application for smartphones that creates suggested running routes so that users can run with each other. Upon downloading the application, each user creates a username, a personal profile, and a contact list of friends who also use the application. The application uses the smartphone's GPS unit to track a user's location, running speed, and distance traveled. Users can use the application to review information and statistics about their previous runs. At the beginning of a run, users indicate the distance they want to run from their current location, and the application suggests a running route. Once a user accepts a suggested route, the application shares the suggested route with other compatible users in the area so that they can run together. Users are considered compatible if they are on each other's contact lists or if they typically run at similar speeds. A basic RunRoutr account is free, but it displays advertisements that are targeted to individual users based on data collected by the application. For example, if a user's running route begins or ends near a particular store, the application may display an advertisement for that store. Users have the ability to pay a monthly fee for a premium account, which removes advertisements from the application. Adrianna uses RunRoutr to suggest a running route. All compatible users near Adrianna receive a notification that shows her running route. Which of the following data is not obtained using data collected from Adrianna's smartphone but necessary for RunRoutr to share Adrianna's running route?

The usernames on Adrianna's contact list

The question below uses a robot in a grid of squares. The robot is represented as a triangle, which is initially in the center square and facing toward the top of the grid. The figure presents a robot in a 5 by 5 grid of squares. The robot is represented by a triangle which is initially in the in the center (the third square from the left and third square from the bottom), and it is initially facing the top of the grid. The following code segment is used to move the robot in the grid. count ← 1 REPEAT 4 TIMES { REPEAT count TIMES { MOVE_FORWARD() } ROTATE_LEFT() count ← count + 1 } Which of the following code segments will move the robot from the center square along the same path as the code segment above?

count ← 0 REPEAT 4 TIMES { count ← count + 1 REPEAT count TIMES { MOVE_FORWARD() } ROTATE_LEFT() }

Consider the following code segment. The figure presents 5 lines of code, as follows. Line 1: [begin block] first ← 100 [end block] Line 2: [begin block] second ← 200 [end block] Line 3: [begin block] temp ← first [end block] Line 4: [begin block] second ← temp [end block] Line 5: [begin block] first ← second [end block] What are the values of first and second as a result of executing the code segment?

first = 100, second = 200

A flowchart provides a way to visually represent an algorithm and uses the following building blocks. Block Explanation Oval The start or end of the algorithm Rectangle One or more processing steps, such as a statement that assigns a value to a variable Diamond A conditional or decision step, where execution proceeds to the side labeled true if the condition is true and to the side labeled false otherwise Parallelogram Displays a message In the flowchart below, assume that j and k are assigned integer values. The figure presents a flow chart of an algorithm. Beginning at the top of the flow chart, the algorithm begins with a step labeled Start, which flows into a processing step labeled result ← 0, which flows into a conditional step labeled k = 0. If the condition is true, the process flows into a processing step labeled DISPLAY (result), which flows into a step labeled End. If the condition is false, the process flows into a processing step labeled result ← result + j and k ← k - 1, which flows back into the conditional step labeled k = 0. Which of the following initial values of j and k will cause the algorithm represented in the flowchart to result in an infinite loop?

j = 5, k = -5

A code segment is intended to transform the list utensils so that the last element of the list is moved to the beginning of the list. For example, if utensils initially contains ["fork", "spoon", "tongs", "spatula", "whisk"], it should contain ["whisk", "fork", "spoon", "tongs", "spatula"] after executing the code segment. Which of the following code segments transforms the list as intended?

len ← LENGTH(utensils) temp ← utensils[len] REMOVE(utensils, len) INSERT(utensils, 1, temp)

The player controls in a particular video game are represented by numbers. The controls and their corresponding binary values are shown in the following table. Control Binary Value ← 01000 ↑ 01001 → 01011 ↓ 01111 Jump 11000 Run 11001 Pause 11011 Reset 11111 The numeric values for the controls can also be represented in decimal (base 10). What control is represented by the decimal value 15 ?


Set pelajaran terkait

Series 6 Unit 2 Securities and Tax Regulations

View Set

DLC 111 Intro to grammar and writing

View Set

EMT - Chapter 20 Immunologic Emergencies.

View Set

Chapters #34, 35, 36, and 37: Ecology

View Set

Fordney Insurance Handbook - Chapter 8

View Set