Chapter 6: More About Loops and Decisions

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

Complete the test condition to allow the following pseudocode that validates the input data. Declare Number As Float While Number _______ Int(Number) ‎ ‎ ‎ ‎ ‎ ‎ Write "Enter an integer: " ‎ ‎ ‎ ‎ ‎ ‎ Input Number End While

!=

If Num = 4.22, what value would be displayed as a result of the following assignment? Set Num = Ceiling(Num) Write Num

5

If Number is an integer value, what would be value displayed as a result of the following assignment? (Note: if there are any spaces, it is assumed to be one space.) Set Number = Length_Of("Hello") Write Number

5

Complete the random generator code for the following pseudocode that simulates rolling a die 10 times by generating and displaying 10 random integers, with a range of 1 to 6. Declare Die, X As Integer For (X = 1; X <= 10; X++) ‎ ‎ ‎ ‎Set Die = Floor(Random()*______ )+ _______ ‎ ‎ ‎ ‎Write "Die face: " + Die End For

6 , 1

If Num1 = 5.6 and Num2 = 3, what value would be displayed as a result of the following assignment? Set Number = Floor(Num1 + Num2) Write Number

8

If Number is an integer value, what would be displayed as a result of the following assignment? (Note: if there are any spaces, it is assumed to be one space.) Set Number = Length_Of("Good-bye!") Write Number

9

Complete the test condition for the following pseudocode that validates the input data. Declare Number As Float Repeat ‎ ‎ ‎ ‎ ‎‎Write "Enter a negative number: " ‎ ‎ ‎ ‎ ‎‎Input Number Until Number __________

??? < 0

What is the output of code corresponding to the following pseudocode? (In the answer options, new lines are separated by commas.) Declare A As Integer Declare B As Float Set A = 2 While A <= 3 ‎ ‎ ‎ ‎ ‎‎Set B = 2.5 * A ‎ ‎ ‎ ‎ ‎‎Write B ‎ ‎ ‎ ‎ ‎‎Set B = Int(B) ‎ ‎ ‎ ‎ ‎‎Write B ‎ ‎ ‎ ‎ ‎‎Set A = A + 1 End While A) 5, 7 B) 5, 5, 7.5, 7 C) 5, 5, 7, 7 D) 2, 3, 5, 7

B) 5, 5, 7.5, 7

What does the following program segment do? Declare Count As Integer Declare Sum As Integer Set Sum = 0 For (Count = 1; Count < 50; Count++) ‎ ‎ ‎ ‎ Set Sum = Sum + Count End For A) It sums all the integers from 0 through 50 B) It sums all the integers from 1 through 49 C) It does nothing since there is no Write statement D) It sums all the integers from 1 through 50

B) It sums all the integers from 1 through 49

What is the output of the code corresponding to the pseudocode shown? Declare G As Integer Declare H As Integer Set G = 7 While G <= 8 ‎ ‎ ‎ ‎ ‎‎Set H = 6 ‎ ‎ ‎ ‎ ‎‎While H <= 7 ‎ ‎ ‎ ‎ ‎‎‎ ‎ ‎ ‎‎‎Write G + H ‎ ‎ ‎ ‎ ‎‎‎ ‎ ‎ ‎ ‎‎Set H = H + 1 ‎ ‎ ‎ ‎ ‎‎End While(H) ‎ ‎ ‎ ‎ ‎‎Set G = G + 1 End While(G) A) 13, 14, 15 B) 7, 6, 7, 8 C) 7, 6, 7, 7, 8, 6, 8, 7 D) 13, 14, 14, 15

D) 13, 14, 14, 15

If MyNumber = 7.82, what is the value of Int(MyNumber/2)+ 0.5? A) 4.41 B) 3.91 C) 4.5 D) 3.5

D) 3.5

In a program with nested loops, the outer loop is completed __________ (before/after) the inner loop.

after

If Number = 4, what is the range of possible numbers that can result from the following? (Note, this question has 2 parts; you must answer each part correctly to receive full marks. Enter only the numbers in the space provided.) ‎ ‎ ‎ ‎ ‎ ‎ Floor(Random() * Number) The range starts at _____ . The range ends at _____ .

0 , 3

The random generator code Floor(Random()*6) produces the numbers ______ through ______ .

0 , 5

If Number = 6, what is the range of possible numbers that can result from the following? Floor(Random() * (Number + 3)) The range starts at _____. The range ends at ______.

0 , 8

If Number is an integer value, what would be displayed as a result of the following assignment? (Note: if there are any spaces, it is assumed to be one space.) Set Number = Length_Of(" ") Write Number

1

Complete the test condition for the following pseudocode that simulates flipping a coin 25 times by generating displaying 25 random integers, each of which is either 1 or 2. (Note, this question has 2 parts; you must answer each part correctly to receive full marks. Enter only the numbers in the space provided.) Declare Coin As Integer Declare X As Integer For (X = ______ ; X <= ______ ; X++) ‎ ‎ ‎ Set Coin = Floor(Random() * 2) + 1 ‎ ‎ ‎ Select Case Of Coin ‎ ‎ ‎ ‎ ‎ ‎ Case 1: ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ Write "Heads" ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ Break ‎ ‎ ‎ ‎ ‎ ‎ Case 2: ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ Write "Tails" ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ Break ‎ ‎ ‎ ‎ ‎ ‎ Default: Break ‎ ‎ ‎ End Case End For

1 , 25

If Num1 = 5.6 and Num2 = 3, what value would be displayed as a result of the following assignment? Set Number = Floor(Num1 * Num2) Write Number

16

If Number is an integer value, what would be displayed as a result of the following assignment? (Note: if there are any spaces, it is assumed to be one space.) Set Number = Length_Of("Hermione Hatfield") Write Number

17

How many times will the Write statement be executed based on the following pseudocode? Declare HelloCount As Integer Set HelloCount = 1 Repeat ‎ ‎ ‎ ‎Repeat ‎ ‎ ‎ ‎‎ ‎ ‎ ‎Write "Hello" ‎ ‎ ‎ ‎‎ ‎ ‎ ‎Set HelloCount = HelloCount + 1 ‎ ‎ ‎ ‎Until HelloCount <=1 Until HelloCount == 2

2

What is the first and last output corresponding to the following pseudocode? (Note, this question has 2 parts; you must answer each part correctly to receive full marks. Enter only the numbers in the space provided.) The first value displayed is ______. The last value displayed is ______. For (N = 4; N <= 9; N + 4) ‎ ‎ ‎ Set X = 10/N ‎ ‎ ‎ Write X ‎ ‎ ‎ Set X = Int(X) ‎ ‎ ‎ Write X End For

2.5 , 1

If Number = 6, what is the range of possible numbers that can result from the following? Floor(Random() * Number) + 3 The range starts at _______ . The range ends at _______ .

3 , 8

What is the first and second output corresponding to the following pseudocode? (Note, this question has 2 parts; you must answer each part correctly to receive full marks. Enter only the numbers in the space provided.) The first value displayed is ______ . The second value displayed is ______. Declare I, J as Integer For (I = 1; I <= 3; I++) ‎ ‎ ‎ ‎ ‎‎For (J = 4; J <= 5; J++) ‎ ‎ ‎ ‎ ‎‎‎ ‎ ‎ ‎ ‎‎Write I * J ‎ ‎ ‎ ‎ ‎‎End For (J) End For (I)

4 , 10

What is the output of the code corresponding to the following pseudocode? (In the answer options, new lines are separated by commas.) Declare Y As Integer Declare X As Integer For (Y = 1; Y <=2; Y++) ‎ ‎ ‎ ‎ ‎‎For (X = 1; X <= 2; X++) ‎ ‎ ‎ ‎ ‎‎‎ ‎ ‎ ‎ ‎‎Write Y * X ‎ ‎ ‎ ‎ ‎‎End For(X) End For(Y) A) 3, 4, 6, 8 B) 4, 5, 5, 6 C) 1, 2, 2, 4 D) None of these are correct output

C) 1, 2, 2, 4

What is the output of the code corresponding to the following pseudocode? (In the answer options, new lines are separated by commas.) Declare X As Integer Declare Y As Integer For (X = 1; X <=2; X++) ‎ ‎ ‎ ‎ ‎‎For (Y = 3; Y <= 4; Y++) ‎ ‎ ‎ ‎ ‎‎‎ ‎ ‎ ‎ ‎‎Write X * Y ‎ ‎ ‎ ‎ ‎‎End For(Y) End For(X) A) 4, 5, 5, 6 B) 1, 3, 2, 4 C) 3, 4, 6, 8 D) None of these are correct output

C) 3, 4, 6, 8

Which statement would produce an output of one of the following numbers: 5, 6, 7, 8, 9, 10 A) Floor(Random() * 9) - 5 B) Floor(Random()) + 5 C) Floor(Random() * 6) + 5 D) Floor(Random() * 5) + 5

C) Floor(Random() * 6) + 5

What will be displayed after code corresponding to the following pseudocode is run? (The '>' means indent again) Declare A As Integer Declare B As Integer Declare C As Integer Set A = 3 While A <= 6 ‎ ‎ ‎ ‎ ‎‎Set B = (2 * A) - 1 ‎ ‎ ‎ ‎Write B ‎ ‎ ‎ ‎ ‎‎Set C = A ‎ ‎ ‎ ‎ ‎‎While C <= (A+1) ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎‎Write C ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ Set C = C + 1 ‎ ‎ ‎ ‎ ‎‎End While(C) ‎ ‎ ‎ ‎ ‎‎Set A = A + 2 End While(A) A) 5, 3, 9, 5 B) 3, 5, 4, 5, 9, 5 C) 5, 3, 3, 9, 5, 5 D) 5, 3, 4, 9, 5, 6

D) 5, 3, 4, 9, 5, 6

What is wrong with the following pseudocode? Declare Count As Integer Declare TheNumber As Integer Set TheNumber = 12 For (Count = 10; Count>TheNumber; Count--) ‎ ‎ ‎ ‎ ‎‎Write TheNumber + Count End For A) The loop will never be entered since the initial value of Count is less than the test condition. B) A counter must start at 0 or 1. C) The limit condition in a For loop cannot be a variable. D) The loop will never end since the test condition will never be met.

D) The loop will never end since the test condition will never be met.

Which of the following loops cannot be nested in a For loop? A) For B) Repeat ... Until C) While D) Do ... While E) All of these can be nested in a For loop

E) All of these can be nested in a For loop

If Number = 64, what would be the result of the following conditional statement? True or false? Floor(Sqrt(Number/2)) == Sqrt(Floor(Number/2))

False

The _____________ function takes a string or a string variable inside the parentheses and returns the number of characters in that string.

Length_Of()

The function that returns the number of characters in a string is the __________ function. (For your answer, enter only the function, not any parameters that the function can carry.)

Length_Of()

If a counter named MyCount in a For loop has the value of 5 on the first pass, 10 on the second pass, 15 on the third pass, and so on, the increment would be written as __________. (Do not include spaces in your answer).

MyCount+5

Write a random generator statement that produces random integers in the following range; store the result in a variable called Range. (Do not include spaces in your answer.) 1 through 4

Range=Floor(Random()*4)+1

The ___________ function computes square roots. (For your answer, enter only the function, not any parameters that the function can carry.)

Sqrt()

If Number = 25, what would be the result of the following conditional statement? True or false? Sqrt(Number) == Floor(Sqrt(Number))

True

If Number = 7, what would be the result of the following conditional statement? True or false? Sqrt(Number * Number) == Int(Sqrt(Number * Number))

True

It's possible to __________ out of a loop if the user has entered an incorrect value that would cause an error or a problem within the loop, or if the user has entered a required response end the program can continue without further iterations of the loop.

break

If one For loop is nested within another, then the counter variables for the two loops should be _________.

different

The ___________ function converts a floating point number to an integer by dropping the fractional part of the number. (For your answer, enter only the function, not any parameters that the function can carry.)

floor

When one loop is contained within another loop, we say these are __________ loops.

nested

Numbers that form an unpredictable sequence in which each number is equally likely to occur are called __________ numbers.

random

The starting value of an algorithm used to generate a range of numbers is called the _________.

seed

A conditional statement within a loop can be used for ___________ so the program can only continue when the users enters appropriate data.

validation

The __________ statement indicates output to the screen with the assumption that each new statement would begin on a new line.

write


Set pelajaran terkait

Module 4 HESI/ Saunders Psychosocial Alterations

View Set

Individual Protective Equipment C-11A08

View Set

Chapter 12- The Presidency - Test Study Guide

View Set

Florida laws and rules pertinent to insurance 18/8

View Set

Accidental health and sickness module 5

View Set

Cognitive Psychology (Chapter 3)

View Set

Unit 8: Nursing Care: Neurological Alterations

View Set

Peripheral Nerve and Spinal Cord Problems

View Set