UNIT 2 2.1 -2.5 test

¡Supera tus tareas y exámenes ahora con Quizwiz!

In a flowchart, a typical decision symbol has what type of output?

boolean (true/false)

The following lines of code can be used are part of a program which is designed to calculate the total a person will pay for a meal which costs mealTotal before a tax and tip is paid. The final amount should include tax on the original mealTotal at a percentage of taxRate and a tip at a percentage of tipRate on the original mealTotal. mealTotal ← mealTotal + tip + tax tip ← mealTotal * tipRate / 100 tax ← mealTotal * taxRate / 100 DISPLAY mealTotal In which of the following orders could the lines I-IV be placed if the program is to run as intended? Select two answers.

1. III, II, I, IV 2. II, III, I, IV

Which is NOT true about comments in programs?

All published programs have their comments available.

What will be displayed when the code segment below, using the variables a, b, and c, is run? a ← 0 b ← 1 c ← a a ← 2 b ← a DISPLAY (b) DISPLAY (c)

2 0

Consider the given code using variables a, b, and c. What will be the output of this code? a ← 2 b ← 6 c ← 12 a ← b b ← c DISPLAY(a) DISPLAY(c)

6 12

Consider the following code segments designed to find the area of a triangle using the formula A = ½ bh. Which of the following statements about the above programs is true?

Both programs will work as intended, but Program B is more readable

Consider the code segment below. Line 1: IF (b ≠ 0) Line 2: { Line 3: a ← a/b Line 4: } Line 5: ELSE Line 6: { Line 7: a ← a*b Line 8: } Which of the following changes will NOT affect the results when the code segment is executed?

Changing line 7 to a ← 0

Which of the following is used in the instructions below to determine how the task of "having breakfast" will be performed? Dump cereal in bowl Pour milk in bowl Eat cereal and milk Place spoon and bowl in dishwasher I. Sequencing II. Selection III. Iteration

I only

Line 1: MOVE_FORWARD () Line 2: MOVE_FORWARD () Line 3: IF(CAN_MOVE (right)) Line 4: { Line 5: MOVE_FORWARD () Line 6: MOVE_FORWARD () Line 7: ROTATE_RIGHT () Line 8: } Line 9: ROTATE_LEFT () Line 10: ROTATE_LEFT () Which 2 lines of code in the segment above must be switched in order for the program to correctly move a robot from the starting position to the ending position? Select two answers. (this question has 2 boxes)

Line 5 and 7

What is displayed as a result of running the following program? a ← 6 b ← 11 IF (a = b) { DISPLAY ("January") } ELSE { IF (a > b) { DISPLAY ("February") } ELSE { IF (a > 0) { DISPLAY ("March") } ELSE { DISPLAY ("April")

March

Using the FLOWCHART below, what value when entered for Y will generate a mathematical error and prevent our flowchart from being completely executed?

None of these values will produce a mathematical error

Which of the following best describes the type of language used in the below algorithm? Prompt user for number if number is greater than or equal to 0 Output "Positive" else Output "Negative" Repeat 4 times

Pseudocode

Consider the following code: n ← 4 x ← -2.5 IF(n < 3) { DISPLAY("Team A") } ELSE { IF(n < 2) { DISPLAY("Team B") } ELSE { IF(x > -2) { DISPLAY("Team C") } ELSE { DISPLAY("Team D") } } } Which of the following is the output of the code?

Team D

This question references a robot in a grid of squares. The robot is represented by the triangle in the bottom left-hand corner and is facing toward the top. (this question has a box) Based on the following program, what would the robot's final position be? MOVE_FORWARD MOVE_FORWARD IF (CAN_MOVE(right)) { ROTATE_RIGHT MOVE_FORWARD MOVE_FORWARD } IF (CAN_MOVE(left)) { ROTATE_LEFT MOVE_FORWARD ROTATE_LEFT

answer is the arrow that is above the middle block facing left

What outputs would be the best choice to substitute in for "missing output 1" and "missing output 2", based on the condition? (this question has a picture)

missing output 1: value does not equal 4 missing output 2: value is equal to 4

Step 1: Initialize the variables odd_counter and roll_counter to 0. Step 2: A variable dice_roll is randomly assigned an integer value between 1 and 6 inclusive. If dice_roll has a value of 1, 3 or 5, then odd_counter is incremented by 1. Step 3: Increment the value of roll_counter by 1. Step 4: Rep

odd_counter>2

The block of code below is supposed to display "Multiple of 5" if the positive number value is in fact a multiple of 5. (this question has a picture)

(value MOD 5) = 0

Consider the following code segment that is intended to accept two integers, x and y, as input, and then display "yes" if and only if x is greater than y and y is less than or equal to 20. Otherwise, it should display "no". Unfortunately, the above code does not perform as intended. Identify two different options that a programmer might choose, either of which will correct the code so that it performs as intended. Select two answers.

1. Swap the two DISPLAY blocks (i.e., DISPLAY "yes" and DISPLAY "no" ) 2. Change the condition in the IF block to be: IF (x > y) AND (y ≤ 20)

Sam and Emma are creating a multiplayer tic-tac-toe game. Below is a segment of their code that is used so that the Sprite on screen can tell the user whose turn it is. Before each user's turn, this set of code is run. What would condition 1 need to be so that this part of the program runs correctly? The variable turn is initialized as 0 at the start and player 1 always goes first.

turn MOD 2 = 1

A student developed a program that outputs the name of a fruit that begins with a letter, dependent upon the variable keyPressed, which stores the letter (from A to Z only) a user types on the keyboard. Below is a section of code from her program: Which of the following descriptions below would be a way that this student might have written the rest of her code so that it executes as intended? Select two answers.

Use 25 nested IF/ELSE blocks where the IF portion is formatted like the code segment above (changing the letters of the alphabet and fruits) and the else simply holding the next IF portion until the last ELSE, which displays a fruit that begins with Z. Use 26 IF blocks formatted similarly to the one above (changing the letters of the alphabet and fruits).


Conjuntos de estudio relacionados

AP World History Period 4: Global Interactions (c. 1450 to c. 1750)

View Set

Chapter 62: Concepts of Care for Patients with Kidney Disorders

View Set

OAE practice questions professional knowledge pk-12 test 004

View Set

Intro to Business Module 7 - Business Ownership

View Set

Pre-Cal Linear, Absolute Value, and Reciprocal Functions Unit 3 Lesson 5

View Set

Chapter 1 - 3 Midterm Study Guide

View Set

Immunology - B cells and immunoglobulins

View Set