csp unit 4

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

In the following code segment, assume that the variable n has been initialized with an integer value. Which of the following is NOT a possible value displayed by the program?

"carrot"

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

(NOT input1) OR (NOT input2) NOT (input1 AND input2)

To be eligible for a particular ride at an amusement park, a person must be at least 12 years old and must be between 50 and 80 inches tall, inclusive. Let age represent a person's age, in years, and let height represent the person's height, in inches. Which of the following expressions evaluates to true if and only if the person is eligible for the ride?

(age ≥ 12) AND ((height ≥ 50) AND (height ≤ 80))

A large spreadsheet contains the following information about local restaurants. A sample portion of the spreadsheet is shown below. 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"))

Which of the following Boolean expressions are equivalent to the expression num ≥ 15 ? Select two answers.

(num > 15) OR (num = 15) NOT (num < 15)

The code fragment below is intended to display "odd" if the positive number num is odd. Which of the following can be used to replace <MISSING CONDITION> so that the code fragment will work as intended?

(num MOD 2) = 1

An office building has two floors. A computer program is used to control an elevator that travels between the two floors. Physical sensors are used to set the following Boolean variables. The elevator moves when the door is closed and the elevator is called to the floor that it is not currently on. Which of the following Boolean expressions can be used in a selection statement to cause the elevator to move?

(onFloor1 AND callTo2) OR (onFloor2 AND callTo1)

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)

Consider the following code segment, which uses the variables r, s, and t. r ← 1 s ← 2 t ← 3 r ← s s ← t DISPLAY (r) DISPLAY (s) What is displayed as a result of running the code segment?

2 3

Consider the following program, which uses the variables , , and . What is displayed as a result of executing the program?

3 4

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

A student is writing a program to model different real-world events using simulations. Which of the following simulations will generate a result that would best be stored using a Boolean variable?

A simulation of flipping a fair coin

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.

Consider the code segment below. IF (onTime) DISPLAY "Hello." ELSE IF (absent) DISPLAY "Is anyone there?" ELSE DISPLAY "Better lat than never." 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 never.

While debugging the code, the student realizes that the loop never terminates. The student plans to insert the instruction win <-- true somewhere in the code. Where could win <-- true be inserted so that the code segment works as intended?

Between line 9 and line 10

A programmer completes the user manual for a video game she has developed and realizes she has reversed the roles of goats and sheep throughout the text. Consider the programmer's goal of changing all occurrences of "goats" to "sheep" and all occurrences of "sheep" to "goats." The programmer will use the fact that the word "foxes" does not appear anywhere in the original text. Which of the following algorithms can be used to accomplish the programmer's goal?

C First, change all occurrences of "goats" to "foxes." Then, change all occurrences of "sheep" to "goats." Last, change all occurrences of "foxes" to "sheep."

Two grids are shown below. Each grid contains a robot represented as a triangle. Both robots are initially facing left. Each robot can move into a white or gray square, but cannot move into a black region. 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

Assume that the variables alpha and beta each are initialized with a numeric value. Which of the following code segments can be used to interchange the values of alpha and beta using the temporary variable temp ?

I and III only

In mathematics, a perfect number is a type of integer. The procedure IsPerfect (num) returns true if num is a perfect number and returns false otherwise. 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? Select two answers.

Line 5 Line 9

In the program below, the initial value of x is 5 and the initial value of y is 10. What is displayed as a result of running the program?

November

In a certain district, 20 percent of the voters are expected to vote for Candidate A in an election. The computer program below is intended to simulate the result of the election with voters, and display the number of votes received by Candidate A. Which of the following can be used to replace <MISSING CONDITION> in line 4 so that the program works as intended?

RANDOM (1, 5) = 1 RAANDOM (1, 10) ≤ 2

In a certain science experiment, 75percent of trials are expected to be successful and percent of trials are expected to be unsuccessful. The program below is intended to simulate the results of repeated trials of the experiment. Which of the following can be used to replace <MISSING CODE> so that the simulation works as intended?

RANDOM (1,100) ≤ 75

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

The following algorithm is intended to take a positive integer as input and display its individual digits in order from right to left. For example, if the input is 512, the algorithm should produce the output 2 1 5. Step 3 of the algorithm is missing. Step 1: Input a positive integer from the user and store it in the variable number. Step 2: Divide number by 10 and record the integer quotient and the remainder. The integer quotient is the quotient with any part after the decimal point dropped. For example, when 127 is divided by 10, the quotient is 12.7, the integer quotient is 12 and the remainder is 7. Step 3: (missing step) Step 4: Repeat steps 2 and 3 until number is 0. Which of the following can be used as step 3 so that the algorithm works as intended?Step 3: Display the remainder of number divided by 10 and store the integer quotient in number.

Step 3: Display the remainder of number divided by 10 and store the integer quotient in number.

A video-streaming Web site keeps count of the number of times each video has been played since it was first added to the site. The count is updated each time a video is played and is displayed next to each video to show its popularity. At one time, the count for the most popular video was about two million. Sometime later, the same video displayed a seven-digit negative number as its count, while the counts for the other videos displayed correctly. Which of the following is the most likely explanation for the error?

The count for the video became larger than the maximum value allowed by the data type used to store the count.

Which of the following are benefits of using well-named variables in a computer program? Select two answers.

The program will be easier for people to read. The program will be easier to modify in the future.

Ticket prices for a science museum are shown in the following table. A programmer is creating an algorithm to display the cost of a ticket based on the information in the table. The programmer uses the integer variable age for the age of the ticket recipient. The Boolean variable includesTour is true when the ticket is for a guided tour and is false when the ticket is for general admission. 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)

Consider the following code segment. What are the values of first and second as a result of executing the code segment?

first = 100, second = 100

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

In the following program, assume that the variable n has been initialized with an integer value. Which of the following is NOT a possible value displayed by the program?

out of range

The following code segment is intended to set max equal to the maximum value among the integer variables x, y, and z. The code segment does not work as intended in all cases. 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


Set pelajaran terkait

Chapter 28: Developmental and Genetic Influences on Child Health Promotion

View Set

Chapter 41, Nursing Management: Esophageal Disorders

View Set

Тема 2. Поняття етики ділового спілкування, її предмет та завдання

View Set

D & D Ch. 24 & 25 Surgical Supplies and Instruments

View Set