3.4 AP Classroom Questions

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Let n be an integer value. Which of the following expressions evaluates to true if and only if n is a two-digit integer (i.e., in the range from 10 to 99, inclusive)?

(n ≥ 10) AND (n < 100)

To qualify for a particular scholarship, a student must have an overall grade point average of 3.0 or above and must have a science grade point average of over 3.2. Let overallGPA represent a student's overall grade point average and let scienceGPA represent the student's science grade point average. Which of the following expressions evaluates to true if the student is eligible for the scholarship and evaluates to false otherwise?

(overallGPA ≥ 3.0) AND (scienceGPA > 3.2)

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 ?

(target - 10 ≤ score) AND (score ≤ target + 10)

# of Correct Answers: 9-10, 7-8, Under 7 Grade: Check Plus, Check, Check Minus If (NumCorrect > 7) { if (NumCorrect >9) { display "check plus" } else { display "check minus" } else { display "check" } For which of the following values of numCorrect does the code segment NOT display the intended grade?

8 and 6

{ IF (x = y) { RETURN (true) } ELSE { RETURN (y = z) } } For which of the following procedure calls does the procedure NOT return the intended value?

AnyPairs ("bat", "cat", "bat")

IF (OnTime) { DISPLAY ("Hello") } Else { IF (absent) { DISPLAY ("Is Anyone there?") } Else { DISPLAY ("Better late than ever") } } If the variables onTime and absent both have the value false, what is displayed as a result of running the code segment?

Better late than ever

Line 1: IF (a = 0) Line 2: { Line 3: b←a + 10 Line 4: } Line 5: ELSE Line 6: { Line 7: b←a + 20 Line 8: } Which of the following changes will NOT affect the results when the code segment is executed?

Changing line 3 to b←10

For which of the following grids does the program NOT correctly move the robot to the gray square? Repeat until (GoalReached) { IF (Can_Move (foreward)) { Move_Forward } If ( Can_Move (right)) { Rotate_Right { IF (Can_Move (Left)) { Rotate_Left

G W W B W B W W B W B B W W W

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. For Each child IN morningList { MISSING CODE } Which of the following could replace <MISSING CODE> so that the code segment works as intended?

IF (Is Found (afternoonList, child) { APPEND (lunchList, child) }

Assume that the Boolean variable hot is assigned the value true and the Boolean variable humid is assigned the value false. Which of the following will display the value true ?

IF (NotHumid) { DISPLAY (hot or humid) } AND IF (hot or humid) { DISPLAY (hot) }

BBBWBB BBBWBB WWWWW WBBWBB WBBWBB GBBWBB 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()

If score is greater than 100, bonus is assigned a value that is 10 times score. If score is between 50 and 100 inclusive, bonus is assigned the value of score. If score is less than 50, bonus is assigned a value of 0. Which of the following code segments assigns bonus correctly for all possible integer values of score ?

IF(score > 100) { bonus ← score * 10 } ELSE { IF(score ≥ 50) { bonus ← score } ELSE { bonus ← 0 } } IF(score < 50) { bonus ← 0 } ELSE { IF(score > 100) { bonus ← score * 10 } ELSE { bonus ←score } }

Grade←C 1. if (score >90) { grade←A } Else { grade←B } 2. if (score > 90) { grade←A } Else { If (score >/= 80) { grade←B } Else { grade←C } 3. if score < 80 { grade←C } Else { score </= 90 { grade←B } Else { grade←A }

II and III only

Which of the following expressions evaluates to true if the person is old enough to drive but not old enough to vote, and evaluates to false otherwise? (age ≥ 16) AND (age ≤ 18) (age ≥ 16) AND (NOT(age ≥ 18)) (age < 18) AND (NOT(age < 16))

II and III only

For the first 25 units of electricity, the cost is $5 per unit. For units of electricity after the first 25, the cost is $7 per unit. Which of the following code segments correctly sets the value of the variable cost to the cost, in dollars, of using numUnits units of electricity?

If (numUnits </= 25) { cost←numunits * 5 } Else { cost←25 * 5 + (numUnits - 25) * 7

Procedure Multiply [x, y] { count←0 resut←0 { Repeat Until (count > y) { result←result + x count←count + 1 } Return [result] } For which of the following procedure calls does the procedure NOT return the intended value?

Multiply [2, -5] Multiply [-2, -5]

IF (x < 0) { DISPLAY ("Foxtrot") } Else { IF (x > y) { DISPLAY ("Hotel") } Else { IF (y > 0) { DISPLAY ("November") } Else { DISPLAY ("Yankee") } } } What is the displayed result of running he program?

November

IF (x > 10) { IF (y < 10) { DISPLAY ("One") } Else { DISPLAY ("TWO") } Else { IF (y > 3) { DISPLAY ("Three") } Else { DISPLAY ("Four") } }

THREE

sum←numList [1] For eachvalue in NumList { sum←sum + value } Display [sum] 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.

procedure KeepPlaying { display ("Do you want to continue playing (y/n)?") response←INPUT If (respnse= "y") AND (Response = "yes") { return (true) } Else { return (false0 } Which of the following best describes the result of running the procedure?

The procedure returns FALSE no matter what the input value is.

Type of Ticket- Reg, Child (12 and under), Senior (60 and up) price- $12, $9, $9 A programmer is creating an algorithm to set the value of TICKETPRICE based on the information in the table. The programmer uses the integer variable AGE for the age of the moviegoer. The Boolean variable IS3D is TRUE when the movie is 3-D and FALSE otherwise. Which of the following code segments correctly sets the value of TICKETPRICE?

TicketPrice←12 If [(age </= 12) OR (age >/= 60)] { Ticketprice←9 } If (is3D) { TicketPrice←TicektPrice + 5 }

IF((exam > 90) AND (presentation > 80)) { grade ← "A" } IF((exam > 80) OR (presentation > 75)) { grade ← "B" } ELSE { IF((exam > 70) OR (presentation > 60)) { grade ← "C" } ELSE { IF(exam > 60) { grade ← "D" } ELSE { grade ← "F" } } } Under which of the following conditions will the value "C" be assigned to the variable grade ?

When the value of exam is 80 and the value of presentation is 60

Procedure Multiply (x, y) { count←0 result←0 Repeat Until (count = y) { result←result + x count←count + 1 } Return (result) } A programmer suspects that an error in the program is caused by this procedure. Under which of the following conditions will the procedure NOT return the correct product?

When the values of is positive and the value of is negative. When the values of and are both negative.

The following procedure is intended to return true if the list of numbers myList contains only positive numbers and is intended to return false otherwise. The procedure does not work as intended. PROCEDURE allPositive(myList) { index ← 1 len ← LENGTH(myList) REPEAT len TIMES { IF(myList[index] > 0) { RETURN(true) } index ← index + 1 } RETURN(false) } For which of the following contents of myList does the procedure NOT return the intended result?

[-1, 0, 1]

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?

[10, 10, 20, 20, 10, 10] [30, 50, 40, 10, 20, 40]

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 ?

bonus←500 IF (timer >/= 30) { bonus←bonus + 500 } If (timer > 60) { bonus←bonus + 500 } If (timer > 60) { bonus←1500 } If (timer >/= 30) and (imer </= 60) { bonus←1000 } If (timer < 30) { bonus←500 }

Type of ticket - Reg (13 and up), Child (12 and under) Gneral Addmisions Cost - $8, $6 Guided Tour Cost - $10, $8 Which of the following code segments correctly displays the cost of a ticket?

cost ← 6 IF (age > 12) { cost ← cost + 2 } IF (includesTour) { cost ← cost + 2 } DISPLAY (cost)

Grid 1: G W W B B W W W W W B B W W W Grid 2: G W W B W B W W B W B B W W W Repeat Until (Goal_Reached) { If (Can_Move (right)) { Rotate right } Else { If (Can_Move (left)) { Rotate left } } If (Can-Move (forward)) { Move forward } }

grid 2 only

Three teams (Team A, Team B, and Team C) are participating in a trivia contest. Let scoreA represent the number of correct questions for Team A, scoreB represent the number of correct questions for Team B, and scoreC represent the number of correct questions for Team C. Assuming no two teams get the same number of correct questions, which of the following code segments correctly displays the team with the highest number of correct questions?

if (scoreA > scoreB) { if (scoreA > score) { Display "Team A wins" } Else { Display "Team C Wins" } Else { if (scoreB > scoreC) { Display "Team B Wins" } Else { Display "Team C Wins" } }

In a certain video game, the variable maxPS represents the maximum possible score a player can earn. The maximum possible score depends on the time it takes the player to complete the game. The value of maxPS should be 30 if time is greater than 120 and 50 otherwise. Which of the following code segments correctly sets the value of maxPS based on the value of time ?

maxPS←50 If (timer> 120) { maxPS←30 } If (timer > 120) { maxPs←30 } Else { maxPS←50

result←val1 and (NotVal20 Which of the following code segments produce the same result as the statement above for all possible values of val1 and val2 ?

result←false IF (val1) { IF (NotVal2) { result←true } IF (Val1) { IF (Val2) { result←false } result←true } Else { result←false }

Procedure Smallest (numbers) { min←number [1] For each number IN numbers { IF (number < min) { Return (number) } } return (min) } For which of the following values of will NOT return the intended value?

theList← [30, 40, 20, 10] TheList←[40, 30, 20, 10]

Procedure Numoccurence [wordList, targetWord] { count←0 { For each Word in wordList { count←0 { If (word = targetWord) { count←count + 1 } } } Return Count } For which of the following code segments will the call to NumOccurrences NOT return the intended value?

treeList←['birch", "maple", "birch"] NumOccurence [treeList, "birch"] treeList←["birch', "maple", "oak'] NumOccurence [treeList, "maple"]

If [(x > y) AND (x > z)] { max←x } If [(y > x) AND (y > z)] { max←y } Else { max←z } Which of the following initial values for x, y, and z can be used to show that the code segment does not work as intended?

x = 3, y = 2, z = 1


Kaugnay na mga set ng pag-aaral

Introduction to Neuroscience, Part 3

View Set

Unit 5: States of Consciousness: 5.2 Hypnosis

View Set