Algorithms and Programming | Quiz 2

Algorithms and Programming | Quiz 2

Assessment

Quiz

Computers

University

Practice Problem

Hard

Created by

Jeremy L

FREE Resource

Student preview

quiz-placeholder

7 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

2 mins • 4 pts

Media Image

Regina is writing a program to process user-inputted phone numbers. The program relies on multiple operations (left). Here is a snippet of her code (right). What value does the 'usPhone' variable store?

"+1 202-555-0183"

"+1202-555-0183"

"+1 202-555-0183 "

"+1-202-555-0183"

"+1202-555-0183 "

2.

MULTIPLE CHOICE QUESTION

2 mins • 3 pts

Media Image

Matching Pennies is a game where players are awarded points based on whether their coins match. Here is an algorithm that simulates one round of the game:

  1. 1. Randomly set 'coin1' to either "heads" or "tails".

  2. 2. Randomly set 'coin2' to either "heads" or "tails".

  3. 3. If 'coin1' matches 'coin2', increment 'score1' by 1.

  4. 4. Otherwise, increment 'score2' by 1.

Imagine that the algorithm is repeated three times to simulate three rounds of the game. This table shows the values for the coin variables in each round. 'score1' and 'score2' start at 0. What will be the values of 'score1' and 'score2' after the three rounds?

'score1' will be 1 and 'score2' will be 1

'score1' will be 1 and 'score2' will be 2

'score1' will be 2 and 'score2' will be 1

'score1' will be 2 and 'score2' will be 2

3.

MULTIPLE CHOICE QUESTION

2 mins • 4 pts

Media Image

Jing is working with a game level designer on a new video game. The designer sends them this flow chart. He must implement that logic in code, using the variables 'enemyStrength' and 'playerHealth'. Which of these code snippets implements the logic in that flow chart?

Media Image
Media Image
Media Image
Media Image
Media Image

4.

MULTIPLE CHOICE QUESTION

2 mins • 3 pts

Ryland is creating an article about commonly used compression algorithms for an online educational site. He is debating whether to express each algorithm in natural language; diagrams; pseudocode; or C++, a general-purpose programming language. Which of these statements is a good argument for expressing the algorithm in pseudocode?

Pseudocode can run on any computer, so all his readers will be able to run the algorithm themselves.

Pseudocode can express more detail than natural language, diagrams, and C++.

Pseudocode can be understood by anyone without any programming experience.

Psuedocode does not depend on the syntax and subtleties of a particular programming language, so his readers will be able to understand as long as they know at least one language.

5.

MULTIPLE CHOICE QUESTION

2 mins • 4 pts

Media Image

A visual artist is programming an 8 ⛌ 8 light-emitting diode display. This is their program so far. The code relies on the procedure 'fillPixel(row, column, color)': lights up the pixel at the given 'row' and 'column' with the given 'color' (specified as a string). The top-most row is row 1 and the left-most column is column 1. What will the output of their program look like?

Media Image
Media Image
Media Image
Media Image
Media Image

6.

MULTIPLE SELECT QUESTION

2 mins • 8 pts

Media Image

This program determines if seafood is safe to consume. In which situations will 'rating' be "safe"? There is at least one correct answer.

When 'seafood' is "tuna" and 'daysFrozen' is 3

When 'seafood' is "salmon" and 'daysFrozen' is 7

When 'seafood' is "mollusk" and 'daysFrozen' is 9

When 'seafood' is "mollusk" and 'daysFrozen' is 1

When 'seafood' is "salmon" and 'daysFrozen' is 6

7.

MULTIPLE CHOICE QUESTION

2 mins • 4 pts

Media Image

This program assigns the variable 'mystery' to a value. 'x' is set to 4 and 'y' to 8. What value will the 'mystery' variable store after running this code?

2

4

8

12

32

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?