computer final

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

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.

x <- 0 result <- 0 REPEAT UNTIL x > 5 result <- result + x result <- x+1 What is the value of result after the code segment is executed?

15

num1 <- 6 num2 <- 4 num3 <- 10 IF num1<num2 num1 <- num2 ELSE num3 <- num2 IF num2 >= num3 num1 <- num2+num3 sum <- num1 + num2 + num3 What is the value of sum after the code segment is executed? Responses

16

p = 10 q = 20 r = 30 s = 40 p = q q = r s = q r = p What is the value of r as a result of executing the code segment?

20

a <- 10 b <- 20 c <- 30 d <- 40 x <- 20 b <- x + b a <- x + 1 d <- c + d /2 DISPLAY a DISPLAY b DISPLAY c DISPLAY d What is displayed as a result of executing the code segment?

21 40 30 50

x <- 23 z <- x MOD y Which of the following initial values of the variable y would result in the variable z being set to 2 after the code segment is executed?

3

Consider a game where a player spins a wheel divided into four identical sections, labeled A, B, C, and D. If the player spins A, the score is 10. If the player spins B, the score is 5. If the player spins C or D, the score is -1. The following code segment is intended to implement the game. <MISSING STATEMENT> IF spin = 1 score <- 10 ELSE IF spin = 2 score <- 5 ELSE score <- -1 Which of the following could be used as a replacement for <MISSING STATEMENT> so the code segment works as intended?

spin <- RANDOM 1,4

In the following code segment, assume that x and y have been assigned integer values. sum ← 0 REPEAT x TIMES { REPEAT y TIMES { sum ← sum + 1 } } At the end of which of the following code segments is the value of sum the same as the value of sum at the end of the preceding code segment?

sum ← 0 z ← x * y REPEAT z TIMES { sum ← sum + 1 } and sum ← 0 REPEAT y TIMES { REPEAT x TIMES { sum ← sum + 1 } }

A spinner contains 12 regions of equal size. The regions are numbered 1 to 12. Which of the following code segments can be used to simulate the results of spinning the spinner three times and assigns the sum of the values obtained by the three spins to the variable sum ?

sum ← RANDOM(1, 12) + RANDOM(1, 12) + RANDOM(1, 12)

Which of the following code segments can be used to interchange the values of the variables num1 and num2 ?

temp <- num1 num1 <- num2 num2 <- temp

Consider the following code segment with integer variables x and y. IF x > 10 IF y < 10 DISPLAY "ONE" ELSE DISPLAY "TWO" ELSE IF y > 3 DISPLAY "THREE" ELSE DISPLAY "FOUR" If x has a value of 7 and y has a value of 20, what is displayed as a result of executing the code segment?

three

Consider the following procedures. PROCEDURE proc1(str) { DISPLAY(str) DISPLAY("happy") } PROCEDURE proc2(str1, str2) { proc1(str2) DISPLAY(str1) } What is displayed as a result of the procedure call proc2("birthday", "to you") ? Responses

to you happy birthday

In the following expression, the variable truckWeight has the value 70000 and the variable weightLimit has the value 80000. truckWeight < weightLimit What value does the expression evaluate to?

true

Consider the following code segment. Assume that index1 is a number between 1 and LENGTH(theList), inclusive, and index2 is a number between 2 and LENGTH(theList) - 1, inclusive. theList ← [9, -1, 5, 2, 4, 8] x ← theList[index1] + theList[index2] What is the largest possible value that the variable x can have after the code segment executes? Responses

14

The variable isOpen is to be used to indicate whether or not a store is currently open. Which of the following is the most appropriate data type for isOpen ?

boolean

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? Responses

((age ≥ 13) OR (grade ≥ 9)) AND (age < 18)

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)

IF x > y DISPLAY x + y ELSE DISPLAY x-y If the value of x is 3 and the value of y is 5, what is displayed as a result of executing the code segment?

-2

In the following procedure, the parameter str is a string and the parameter num is a number. PROCEDURE printArgs(str, num) { DISPLAY(num) DISPLAY(str) DISPLAY(num) } Consider the following code segment. printArgs("**", 1) printArgs("*", 2) What is displayed as a result of executing the code segment?

1 ** 1 2 * 2

i <- 1 REPEAT UNTIL i > 4 rand <- RANDOM 1,i DISPLAY rand i <- i + 1 Which of the following CANNOT be displayed as a result of executing the code segment?

1 3 2 4

Consider the following procedure. PROCEDURE doSomething(num1, num2) { DISPLAY(num1) RETURN(num1) DISPLAY(num2) } Consider the following statement. DISPLAY(doSomething(10, 20)) What is displayed as a result of executing the statement above?

10 10

numList <- 100, 20, 300, 40, 500, 60 FOR EACH item IN numLIST IF item >=90 DISPLAY item What is displayed as a result of executing the code segment?

100 300 500

The list wordList contains a list of 10 string values. Which of the following is a valid index for the list?

4

Consider the following code segment. result ← 1 IF(score1 > 500) { result ← result + 1 IF(score2 > 500) { result ← result + 1 } ELSE { result ← result + 2 } } ELSE { result ← result + 5 IF(score2 > 500) { result ← result + 1 } ELSE { result ← result - 1 } } If the value of score1 is 350 and the value of score2 is 210, what will be the value of result after the code segment is executed?

5

A teacher is writing a code segment that will use variables to represent a student's name and whether or not the student is currently absent. Which of the following variables are most appropriate for the code segment?

A string variable named studentName and a Boolean variable named isAbsent

Consider the following code segment, which is intended to store ten consecutive even integers, beginning with 2, in the list evenList. Assume that evenList is initially empty. i ← 1 REPEAT 10 TIMES { <MISSING CODE> } Which of the following can be used to replace <MISSING CODE> so that the code segment works as intended?

APPEND(evenList, 2 * i) i ← i + 1

ans <- RANDOM 1,3 + RANDOM 2,5 ans <- ans + RANDOM 4,8 Which of the following describes the possible values of ans as a result of executing the code segment?

Any integer value from 7 to 16, inclusive

A programmer is creating an algorithm that will be used to turn on the motor to open the gate in a parking garage. The specifications for the algorithm are as follows. The gate should not open when the time is outside of business hours. The motor should not turn on unless the gate sensor is activated. The motor should not turn on if the gate is already open. Which of the following algorithms can be used to open the gate under the appropriate conditions?

Check if the time is during business hours. If it is, check if the gate sensor is activated. If it is, check if the gate is open. If it is not, turn on the motor.

A company that develops educational software wants to assemble a collaborative team of developers from a variety of professional and cultural backgrounds. Which of the following is NOT considered a benefit of assembling such a team?

Collaboration that includes diverse backgrounds and perspectives can eliminate the need for software testing.

Shoppers at a mall were asked whether they preferred wearing gloves or mittens in cold weather. Shoppers' preferences were stored in the list voteList as strings, with the string "Gloves" representing a preference for gloves and the string "Mittens" representing a preference for mittens. The following code segment is intended to traverse the list and display the number of shoppers who chose gloves and the number of shoppers who chose mittens. numGlovesVotes ← 0 numMittensVotes ← 0 <MISSING CODE> { IF(vote = "Gloves") { numGlovesVotes ← numGlovesVotes + 1 } ELSE { numMittensVotes ← numMittensVotes + 1 } } DISPLAY(numGlovesVotes) DISPLAY(" shoppers chose gloves and") DISPLAY(numMittensVotes) DISPLAY(" shoppers chose mittens.") Which of the following should replace <MISSING CODE> so that the code segment works as intended?

FOR EACH vote IN voteList

Three students in different locations are collaborating on the development of an application. Which of the following strategies is LEAST likely to facilitate collaboration among the students?

Having all three students write code independently and then having one student combine the code into a program

A student wrote the following procedure to calculate the sum of the integers from 1 to 5. PROCEDURE sumOfInts sum <- 0 count <- 1 REPEAT UNTIL count > 5 sum <- sum + count count <- count + 1 RETURN sum The student later decides to modify the procedure to calculate the sum of the integers from 1 to max, which represents any positive integer greater than 1. Which of the following changes should be made to the procedure to meet the student's goal? The procedure should take max as an input parameter. The condition in the REPEAT UNTIL block should be changed to count > max. The condition in the REPEAT UNTIL block should be changed to max < 5.

I and II

The cost of a customer's electricity bill is based on the number of units of electricity the customer uses. 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

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 C DISPLAY "Team A wins." ELSE DISPLAY "Team C wins." ELSE IF scoreB > scoreC DISPLAY "Team B wins." ELSE DISPLAY "Team C wins."

Consider the following code segment with an integer variable num. IF(num > 0) { DISPLAY("positive") } IF(num < 0) { DISPLAY("negative") } IF(num = 0) { DISPLAY("zero") }

IF(num < 0) { DISPLAY("negative") } ELSE { IF(num = 0) { DISPLAY("zero") } ELSE { DISPLAY("positive") } }

In a certain game, the integer variable bonus is assigned a value based on the value of the integer variable score. 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 ? Select two answers.

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

Suppose a large group of people in a room were all born in the same year. Consider the following three algorithms, which are each intended to identify the people in the room who have the earliest birthday based on just the month and day. For example, a person born on February 10 is considered to have an earlier birthday than a person born on March 5. Which of the three algorithms will identify the correct people? All the people in the room stand up. All standing people form pairs where possible, leaving at most one person not part of a pair. For each pair, the person with the earlier birthday remains standing, while the other person in the pair sits down. If there is a tie, both people sit down. Any individual not part of a pair remains standing. Continue doing this until only one person remains standing. That person has the earliest birthday. All the people in the room stand up. All standing people form pairs with a

II only

A certain game keeps track of the maximum and minimum scores obtained so far. If num represents the most recent score obtained, which of the following algorithms correctly updates the values of the maximum and the minimum?

If num is less than the minimum, set the minimum equal to num. Otherwise, if num is greater than the maximum, set the maximum equal to num.

Three different numbers need to be placed in order from least to greatest. For example, if the numbers are ordered 9, 16, 4, they should be reordered as 4, 9, 16. Which of the following algorithms can be used to place any three numbers in the correct order?

If the first number is greater than the middle number, swap them. Then, if the middle number is greater than the last number, swap them. Then, if the first number is greater than the middle number, swap them.

The following code segment moves the robot around the grid. Assume that n is a positive integer. Line 1: count ← 0 Line 2: REPEAT n TIMES Line 3: { Line 4: REPEAT 2 TIMES Line 5: { Line 6: MOVE_FORWARD() Line 7: } Line 8: ROTATE_RIGHT() Line 9: } Consider the goal of modifying the code segment to count the number of squares the robot visits before execution terminates. Which of the following modifications can be made to the code segment to correctly count the number of squares the robot moves to?

Inserting the statement count ← count + 1 between line 6 and line 7

n 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

A programmer has a need to round many numeric values to the nearest integer. Which of the following best explains the benefit of using a list as a data abstraction in this situation?

Keeping the numeric values in a list makes it easier to apply the same computation to every data element.

Which of the following is a benefit of using a list as a data abstraction in a program?

Lists often allow their size to be easily updated to hold as many data values as needed.

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?

Making the code run faster

A computer program contains code in several places that asks a user to enter an integer within a specified range of values. The code repeats the input request if the value that the user enters is not within the specified range. A programmer would like to create a procedure that will generalize this functionality and can be used throughout the program. The correct use of the procedure is shown below, where min is the least acceptable value, max is the greatest acceptable value, and promptString is the string that should be printed to prompt the user enter a value. inputVal ← getRange(min, max, promptString) Which of the following is a correct implementation of the getRange procedure?

PROCEDURE getRange(min, max, promptString) { DISPLAY(promptString) x ← INPUT() REPEAT UNTIL(x ≥ min AND x ≤ max) { DISPLAY(promptString) x ← INPUT() } RETURN(x) }

A game program contains the following code to update three score variables, health, food, and knowledge. The maximum values for the three variables are 100, 80, and 25, respectively. health ← health + 10 IF(health > 100) { health ← 100 } food ← food + 1 IF(food > 80) { food ← 80 } knowledge ← knowledge + 5 IF(knowledge > 25) { knowledge ← 25 } The game program's author would like to write a procedure that could be used to update any variable in the game (myScore) that has a maximum value (myLimit) by a given amount (myAmount). A correct call of the procedure is shown below. myScore ← updateScore(myScore, myAmount, myLimit) Which of the following is a correct implementation of updateScore ?

PROCEDURE updateScore(score, amount, limit) { score ← score + amount IF(score > limit) { score ← limit } RETURN(score) }

Which of the following are benefits of procedural abstraction?

Procedural abstraction makes it easier for people to read computer programs. and Procedural abstraction provides an opportunity to give a name to a block of code that describes the purpose of the code block.

A teacher has a goal of displaying the names of 2 students selected at random from a group of 30 students in a classroom. Any possible pair of students should be equally likely to be selected. Which of the following algorithms can be used to accomplish the teacher's goal?

Step 1: Assign each student a unique integer from 1 to 30. Step 2: Generate a random integer n from 1 to 30. Step 3: Select the student who is currently assigned integer n and display the student's name. Step 4: The student who was selected in the previous step is assigned 0. All other students are reassigned a unique integer from 1 to 29. Step 5: Generate a new random integer n from 1 to 29. Step 6: Select the student who is currently assigned integer n and display the student's name.

Which of the following algorithms display all integers between 1 and 20, inclusive, that are not divisible by 3 ? Select two answers.

Step 1: Set x to 0. Step 2: Increment x by 1. Step 3: If x is not divisible by 3, then display x. Step 4: Repeat steps 2 and 3 until x is 20. and Step 1: Set x to 1. Step 2: If x is divisible by 3, then do nothing; otherwise display x.Step 3: Increment x by 1. Step 4: Repeat steps 2 and 3 until x is greater than 20.

In a certain game, a player may have the opportunity to attempt a bonus round to earn extra points. In a typical game, a player is given 1 to 4 bonus round attempts. For each attempt, the player typically earns the extra points 70% of the time and does not earn the extra points 30% of the time. The following code segment can be used to simulate the bonus round. success <- 0 attempts <- RANDOM 1,4 REPEAT attempts TIMES IF RANDOM 1,10 <= 7 success <- success + 1 DISPLAY "The player had" DISPLAY attempts DISPLAY "bonus round attempts and" DISPLAY success DISPLAY "of them earned extra points." Which of the following is NOT a possible output of this simulation? Responses

The player had 3 bonus round attempts and 7 of them earned extra points.

A student is developing a program that allows users to look up the definitions of words that appear in a book. The student plans to perform a large number of searches through a dictionary containing words and their definitions. The student will use a procedure written by a computer scientist to quickly search the dictionary (and knows that the procedure will return a definition if one is available). The student cannot modify the search procedure written by the computer scientist but can call the procedure by supplying a word. Which of the following is a true statement about the student's use of the computer scientist's search procedure?

The student is reusing the computer scientist's procedural abstraction by knowing what the procedure does without knowing how it does it.

first = true second = false second = first first = second What are the values of first and second as a result of executing the code segment?

The value of first is true, and the value of second is true.

Consider the following code segment, where exam and presentation are integer variables and grade is a string variable. 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

Consider the following code segment. firstList ← ["guitar", "drums", "bass"] secondList ← ["flute", "violin"] thirdList ← [] thirdList ← firstList firstList ← secondList secondList ← thirdList What are the contents of secondList after the code segment is executed?

["guitar", "drums", "bass"]

yourList <- 20,40,60,80 myList <- 10,30,50,70 yourList <- myList What are the contents of yourList after the code segment is executed?

[10, 30, 50, 70]

Consider the following code segment. theList ← [-2, -1, 0, 1, 2] count1 ← 0 count2 ← 0 FOR EACH value IN theList { IF(value > 0) { count1 ← count1 + 1 } ELSE { count2 ← count2 + 1 } } What are the values of count1 and count2 as a result of executing the code segment?

count1 = 2, count2 = 3

a <- true b <- false c <- true a<- not a OR b AND c c <- c AND a display a display b display c what is displayed?

false false false

Assume that both lists and strings are indexed starting with index 1. The list wordList has the following contents. ["abc", "def", "ghi", "jkl"] Let myWord be the element at index 3 of wordList. Let myChar be the character at index 2 of myWord. What is the value of myChar ? Responses

h

A teacher stores the most recent quiz scores for her class in the list scores. The first element in the list holds the maximum possible number of points that can be awarded on the quiz, and each remaining element holds one student's quiz score. Assume that scores contains at least two elements. Which of the following code segments will set the variable found to true if at least one student scored the maximum possible number of points on the quiz and will set found to false otherwise?

len <- LENGTH scores - 1 found <- false index <- 2 REPEAT len TIMES IF scores index = scores 1 found <- true index <- index + 1

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 ? Select two answers.

maxPS <- 50 IF time>120 maxPS <- 30 and IF time>120 maxPS <- 30 ELSE maxPS <- 50

The variable age is to be used to represent a person's age, in years. Which of the following is the most appropriate data type for age ?

number

The following code segment is used to determine whether a customer is eligible for a discount on a movie ticket. val1 ← (NOT (category = "new")) OR (age ≥ 65) val2 ← (category = "new") AND (age < 12) If category is "new" and age is 20, what are the values of val1 and val2 as a result of executing the code segment?

val1 = false, val2 = false

Consider the following code segment. x ← 25 y ← 50 z ← 75 x ← y y ← z z ← x Which of the variables have the value 50 after executing the code segment?

x and z only


Set pelajaran terkait

Chapter 24 Activity: The Great Depression and the New Deal, 1929-1939

View Set

COM 209 multiple choice final questions

View Set

Domain and Range of Trigonometric Functions

View Set

Крок М педіатрія(2 семестр)

View Set

environmental ethics first half of semester

View Set

Chapter 9: Federal Tax Considerations for Accident and Health Insurance

View Set

CSCI 211 Chapter 1-6, CSCI 211 Chapter 7-10 Questions, CSCI 211 Chapter 11-14 Questions

View Set

Giddens Ch 38 Interpersonal Violence EAQ

View Set

Chapter 27, Hygiene and Personal Care & Skin integrity/Wound Care

View Set