Big Ideas 1 & 2 Flashcards
:,D (45 cards)
Which of the following best describes the behavior of the code segment?
result <- 2
{
repeat 3 times
{result <- result *5}
}
Display result
The code segment displays the vale of 2(5^3) by intializing results to 2 and then multiplying result 5 by a total of three times.
Assume that the parameter x is an integer.
procedure mystery [x]
y <- [x < 0]
{
if y
display [y]
}
It displays true if x is negative and displays nothing otherwise.
Which of the folloiwng best describes one of the benefits of using an iterative and incremental process of program development?
It helps programmers identify errors as components are added to a working program.
Which of the following actions are generally helpful in program development?
i. Consulting potential users of the program to identify their concerns
ii. Writing and testing small code segments before adding them to the program.
iii. Collaborating with other individuals when developing a large program
i, ii, and iii
Central High School keeps a database of information about each student, including the numeric variabels numberOfAbsences and gradePointAverage. The expression below is used to determine whether a student is eligible to receive an academic award.
(numberofAbsences </= 5) AND (gradePointAverage > 3.5)
Which of the following pairs of values indicates that a student is eligible to receive an academic award?
numberOfAbsences = 5, gradePointAverage = 3.8
Assume that the list originalList contains integer values and that the list newList is initially empty. The following code segment is intended to copy all even numbers from originalList to newList so that the numbers in newList appear in the same relative order as in originalList. the code segment may or may not work as intended.
Line 1: FOR EACH number IN originalList
Line 2: {
Line 3: IF (number MOD 2 = 0)
Line 4: {
Line 5: INSERT (newList, 1, number)
Line 6: }
Line 7: }
Which of the following changes, if any, can be made so that the code segment works as intended?
Changing lline 5 to APPEND (newList, number)
A program is created to perform arithmetic operations on positive and negative integers. The program contains the following incorrect procedure, which is intended to return the product of the integers x and y.
PROCEDURE Multiply (x,y)
{count <- 0
result <- 0
REPEAT UNTIL (count = y)
{
result <- result + x
count <- count + 1
}
RETURN (result)
}
A programmers suspects that an error in the program is caused by this procedure.
Under which of the following condtions will procedure NOT return the correct product?
TWO ANSWERS
b. When the values of x is positive and the value of y is negative.
d. When the values of x and y are both negative.
DineOutHelper is a mobile application that people can use to select a restaurant for a group meal. Each user creates a profile with a uique username and a list of food allergies or dietary restrictions. Each user can then build a contact list of other users of the app.
Which of the following data are needed for DineOutHelper to recommend a restaurant for the group?
i. Each group member’s list of food allergies or dietary restrictions.
ii. Alejandra’s geographic locations
iii. The usernames of the people on Brandon and Cynthia’s contact lists.
I and II only (list of food restrictions and Alejandra’s geographic locations)
Which of the following data is not provided by Alejandra but is necessary for DineOutHelper to recommend a restaurant for the group?
i. Brandon’s contact list
ii. Info about which restaurants Brandon and Cynthia have visited in the past
iii. Info about which food allergies and dietary restrictions can be accommodated at different restaurants near Alejandra
III only
(info about which food allergies and dietary restrictions can be accomodated at different restaurants near Alejandra)
Which of the folloiwng data must be collected from a user’s smartphone in order for RunRoutr to suggest a running route?
The user’s geographic location
Adriana uses RunRoutr to suggest a running route. All compatible users near Adriana 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 current locations of other RunRoutr users.
sum <- numList [1]
FOR EACH value 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.
OG system: “start -> customers hears prerecorded message w/ answers to common questions -> customer hears list of departments and selects one using a phone keypad…”
The upgraded system uses a directory containing additional information not supplied by the customer. The directory is used to help direct calls effectively. Which of the following is LEAST likely to be included in the directory.
A list of computers the company owns and the computers’ corresponding IP addresses
Og system: “start -> customers hears prerecorded message w/ answers to common questions -> customer hears list of departments and selects one using a phone keypad…”
To direct a call to the appropriate destination, which of the following input data is needed by the upgraded system that was NOT needed by the original system?
i. Audio signal of the customer’s voice
ii. The customer’s keypad selection
iii. The customer’s phone number
i only (audio signal of the customer’s voice)
PROCEDURE printNums(max)
{
count <-1
REPEAT UNTIL (count > max)
{ DISPLAY (count)
count <- count + 2
}
}
Which of the following is the most appropriate documentation to appear with the printNums procedure?
B. Prints all positive odd integers that are less than or equal to max.
PROCEDURE calculate [x,y]
result <- x + y
result <- result/x
DISPLAY result
C. Displays the value of (x+y)/x; the value of the parameter x must not be 0.
PROCUEDURE swapListElements (numList, j, k)
{
newList <- numList
newL [j] <-numList[k]
newList [k] <- numList[j]
RETURN (newList)
}
Which of the following is the msot appropriate documentation to appear with the swapListElements procedure?
B. Returns a copy of numList with the elements at indices j and k interchanged.
The values of j and k must both be between 1 and Length(numList), inclusive.
A local router is configured to limit the bandwidth of guest users connecting to the Internet.
Which of the following best explains the result of this configuration as compared to a configuration in which the router does not limit the bandwidth?
D. Guest users will be restricted in the maximum amount of data that they can send and receive per second.
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: }
B. Line 8
C. Line 10
PROCEDURE AnyPairs (x, y, z)
{
IF (x = y)
{
RETURN (true)
}
ELSE
{
RETURN (y = z)
}
}
For which of the following procedure calls does the procedure NOT return the intended value?
C. AnyPairs (“bat”, “cat”, “bat”)
Line 1: i
1
Line 2: sum
0
Line 3: REPEAT UNTIL (i > 10)
Line 4: {
Line 5: i
i + 1
Line 6: sum
sum + nums[i]
Line 7: }
Line 8: DISPLAY (sum)
C. Line 5 and 6 should be interchanged.
Line 01: PROCEDURE countNumOccurences(myList, val)
Line 02: {
Line 03: FOR EACH item IN myList
Line 04: {
Line 05: count <- 0
Line 06: IF(item = val)
Line 07: {
Line 08: count <-count + 1
Line 09: }
Line 10: }
Line 11: RETURN(count)
Line 12: }
C. Moving the statement in line 5 (count <- 0) so that it appears between lines 2 (empty) and 3(FOR EACH item in myList).
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: }
Lines 8 and 12 should be interchanged
Line 1: currentNum <-start
Line 2: count <-0
Line 3: REPEAT UNTIL (currentNum > end)
Line 4: {
Line 5: count <-count + 1
Line 6: IF (IsPerfect (currentNum))
Line 7: {
Line 8: count <-count + 1
Line 9: currentNum <-currentNum + 1
Line 10: }
Line 11: currentNum <-currentNum + 1
Line 12: }
Line 13: DISPLAY (count)
Which two lines of code should be removed so that the program will work as intended? (Select 2 answers)
A. Line 5
C. Line 9