comp quiz

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

A computer program uses 3 bits to represent integers. When the program adds the decimal (base 10) numbers 5 and 3, the result is 0. Which of the following is the best explanation for the result?

An overflow error occurred.

The following procedure is intended to return true if at least two of the three parameters are equal in value and is intended to return false otherwise. 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? Responses

AnyPairs ("bat", "cat", "bat"); wouldnt work is x=z

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? Audio signal of the customer's voice The customer's keypad selection The customer's phone number

Audio signal of the customer's voice

In the following procedure, assume that the parameter x is an integer. Which of the following best describes the behavior of the procedure?

C It displays true if x is negative and displays nothing otherwise.

The procedure is intended to return the least value in the list . The procedure does not work as intended. For which of the following values of will NOT return the intended value?

C and D, anything where there are at least two numbers proceeding the first number that are smaller than the first number, because the program would just set that first smallest number to the minimum

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 line 5 to APPEND (newList, number) (same order)

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.

For his program to work, the first number has to be zero, or it is repeated. The conclusion is incorrect; using the test case [0, 1, 4, 5] is not sufficient to conclude the program is correct.

For each grid, the program below is intended to move the robot to the gray square. The program uses the procedure Goal_Reached ( ), which evaluates to true if the robot is in the gray square and evaluates to false otherwise. For which of the grids does the program correctly move the robot to the gray square?

Grid I only Grid 2 would rotate right before reaching the gray square

Which of the following data are needed for DineOutHelper to recommend a restaurant for the group? Each group member's list of food allergies or dietary restrictions Alejandra's geographic location The usernames of the people on Brandon and Cynthia's contact lists

I and II only

Which of the following data is not provided by Alejandra but is necessary for DineOutHelper to recommend a restaurant for the group? Brandon's contact list Information about which restaurants Brandon and Cynthia have visited in the past Information about which food allergies and dietary restrictions can be accommodated at different restaurants near Alejandra Responses

III only

Which of the following best describes the behavior of the code segment? (set result to 2 then multiple by 5 3 times)

The code segment displays the value of 2(53) by initializing result to 2 and then multiplying result by 5 a total of three times.

A student wrote the following code segment, which displays true if the list myList contains any duplicate values and displays false otherwise. The code segment compares pairs of list elements, setting containsDuplicates to true if any two elements are found to be equal in value. Which of the following best describes the behavior of how pairs of elements are compared?

The code segment iterates through myList, comparing each element to all subsequent elements in the list.

A student is creating an application that allows customers to order food for delivery from a local restaurant. Which of the following is LEAST likely to be an input provided by a customer using the application?

The cost of a food item currently available for order

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

Which of the following data must be collected from a user's smartphone in order for RunRoutr to suggest a running route? Responses

The user's geographic position

A company that develops mobile applications wants to involve users in the software development process. Which of the following best explains the benefit in having users participate?

Users can provide feedback that can be used to incorporate a variety of perspectives into the software.

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. For which of the following contents of myList does the procedure NOT return the intended result? Responses

[-1, 0, 1] If a negative number comes in the list with a positive number last, it would not work because it is really only checking the last index.

A student wrote the following code for a guessing game. While debugging the code, the student realizes that the loop never terminates. The student plans to insert the instruction somewhere in the code. Where could be inserted so that the code segment works as intended?

between lines 9 and 10 (if guess = secretNumber, after displaying the winning message)

The program below is intended to count the number of prime numbers in a list called and display the result. The program uses the procedure , which returns if is a prime number and otherwise. The program does not work as intended. Which two lines of code should be removed so that the program will work as intended?

line 4, line 9 (sets count to 0, adds to count)

The following program is intended to count and display the number of perfect numbers between the integers start and end, inclusive. Assume that start is less than end. The program does not work as intended. 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?

lines 5 and 11

Central High School keeps a database of information about each student, including the numeric variables 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

The procedure below is intended to display the index in a list of unique names (nameList) where a particular name (targetName) is found. If targetName is not found in nameList, the code should display 0.

only works when the name that you are trying to find is last, or never in there at all because the foundindex is set back to 0 for each new index

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

value of y cannot be negetive: When the values of is positive and the value of is negative, When the values of and are both negative.

A homework assignment consists of 10 questions. The assignment is graded as follows. Let numCorrect represent the number of correct answers for a particular student. The following code segment is intended to display the appropriate grade based on numCorrect. The code segment does not work as intended in all cases. For which of the following values of numCorrect does the code segment NOT display the intended grade?

8 and 6 (does not work for a normal check above 7 (8) or a check minus)

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

A student wrote the following program to remove all occurrences of the strings "the" and "a" from the list wordList. Line 1: index ← LENGTH (wordList) Line 2: REPEAT UNTIL (index < 1) Line 3: { Line 4: IF ((wordList[index] = "the") OR (wordList[index] = "a")) Line 5: { Line 6: REMOVE (wordList, index) Line 7: } Line 8: } While debugging the program, the student realizes that the loop never terminates. Which of the following changes can be made so that the program works as intended?

Inserting index ← index - 1 between lines 7 and 8

In the following code segment, score and penalty are initially positive integers. The code segment is intended to reduce the value of score by penalty. However, if doing so would cause score to be negative, score should be assigned the value 0. For example, if score is 20 and penalty is 5, the code segment should set score to 15.If score is 20 and penalty is 30, score should be set to 0. The code segment does not work as intended. Line 1: IF(score - penalty < 0) Line 2: { Line 3: score ← score - penalty Line 4: } Line 5: ELSE Line 6: { Line 7: score ← 0 Line 8: } Which of the following changes can be made so that the code segment works as intended?

Interchanging lines 3 and 7

Which of the following 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.

Assume that the list of numbers nums has more than 10 elements. The program below is intended to compute and display the sum of the first 10 elements of nums. 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) Which change, if any, is needed for the program to work as intended?

Lines 5 and 6 should be interchanged becuase the code will stop running before adding the final value

In the following procedure, the parameter max is a positive integer. 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?

Prints all positive odd integers that are less than or equal to max. The procedure initializes count to 1. Inside the loop, the value of count is displayed, then count is incremented by 2 to the next odd integer.

Which of the following is a true statement about program documentation? Responses

Program documentation is useful during initial program development and also when modifications are made to existing programs.

n the following procedure, the parameter numList is a list of numbers and the parameters j and k are integers. PROCEDURE swapListElements(numList, j, k) { newList ← numList newList[j] ← numList[k] newList[k] ← numList[j] RETURN(newList) } Which of the following is the most appropriate documentation to appear with the swapListElements procedure?

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.

Which of the following actions are generally helpful in program development? Consulting potential users of the program to identify their concerns Writing and testing small code segments before adding them to the program Collaborating with other individuals when developing a large program

all of them]

The following procedure is intended to return the value of x times y, where x and y are integers. Multiplication is implemented using repeated additions. For which of the following procedure calls does the procedure NOT return the intended value?

anything when y is negative because the loop will never terminate (2, -5) and (-2, -5)

The procedure NumOccurrences is intended to count and return the number of times targetWord appears in the list wordList. The procedure does not work as intended.For which of the following code segments will the call to NumOccurrences NOT return the intended value? Select two answers. response - correct Responses

if the target word appears anywhere but the last word: birch, maple, birch (birch) and birch, maple, oak (maple)


Kaugnay na mga set ng pag-aaral

Chapter 8 - Portable Fire Extinguishers

View Set

BIOCHEM I MCAT SELF PREP plus KA notes from Biochem passages

View Set

Geography - Chapter 14 (The Caucasus. Central Asia, and South Asia)

View Set

NCLEX - Penicillins and Cephalosporins

View Set