Rédigé par des étudiants ayant réussi Disponible immédiatement après paiement Lire en ligne ou en PDF Mauvais document ? Échangez-le gratuitement 4,6 TrustPilot
logo-home
Document preview thumbnail
Aperçu 2 sur 13 pages
Examen

APCSP 2 Questions and Answers

Document preview thumbnail
Aperçu 2 sur 13 pages

APCSP 2 Questions and Answers 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 In a flowchart, a typical decision symbol has what type of output? boolean (true/false) Which is NOT true about comments in programs? All published programs have their comments available. 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 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: 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") } } } Team D 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). The following program segment is intended to move a robot from the starting position to the ending position as shown above. However, the program segment does not work correctly. 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. Line 7 Line 5 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 Sequencing Selection Iteration I only Consider the following code segments designed to find the area of a triangle using the formula A = ½ bh. Program A Program B Which of the following statements about the above programs is true? Both programs will work as intended, but Program B is more readable. What will be displayed when the code segment below, using the variables a, b, and c, is run? 2 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. Change the condition in the IF block to be: IF (x y) AND (y ≤ 20) Swap the two DISPLAY blocks (i.e., DISPLAY "yes" and DISPLAY "no" ) 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. II, III, I, IV III, II, I, IV The block of code below is supposed to display "Multiple of 5" if the positive number value is in fact a multiple of 5. (value MOD 5) = 0 This is a section of code taken from a larger program. What outputs would be the best choice to substitute in for "missing output 1" and "missing output 2", based on the condition? missing output 1: value does not equal 4 missing output 2: value is equal to 4 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. 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_LEF -- 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 The algorithm below is used to simulate the results of rolling a standard 6-sided die 5 times. Consider the goal of determining whether the simulation resulted in more results which were odd than results which were even. 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:Repeat steps 2 and 3 until roll_counter equals 5. Following the execution of the algorithm, which of the following expressions indicates that the simulation resulted in more results which were odd than results which were even? odd_counter2 Consider the given code: 1 integer ← 22 2 lowtemp ← 0 3 4 IF(integer 10) 5 { 6 lowtemp ← lowtemp - 5 7 } 8 ELSE 9 { 10 lowtemp ← lowtemp + 10 11 } 12 13 DISPLAY(lowtemp) What is the best description of the structure implied by line 4? Selection Consider the given code fragment. Determine the output of the program fragment. m ← 2 REPEAT UNTIL(m 500) { DISPLAY(m) m ← m + 2 } All even numbers 2 4 6 8 ... 500 Consider the following code segment that appears in the middle of a program. Which of the following can replace the missing statement in the REPEAT UNTIL block so that the user will be required to enter the correct password of "swordfish" before they can continue on with the rest of the program. userPassword = "swordfish"

Aperçu du contenu

APCSP 2 Questions and Answers
Using the flowchart below, what value when entered for Y will generate a mathematical
error and prevent our flowchart from being completely executed? - answer None of
these values will produce a mathematical error

In a flowchart, a typical decision symbol has what type of output? - answer boolean
(true/false)

Which is NOT true about comments in programs? - answer All published programs
have their comments available.

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 - answer Pseudocode

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) - answer 6 12

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") } } } - answer
Team D

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

The following program segment is intended to move a robot from the starting position to
the ending position as shown above. However, the program segment does not work
correctly.
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. - answer Line 7
Line 5

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? - answer 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
Sequencing
Selection
Iteration - answer I only

Consider the following code segments designed to find the area of a triangle using the
formula A = ½ bh.
Program A
Program B
Which of the following statements about the above programs is true? - answer Both
programs will work as intended, but Program B is more readable.

What will be displayed when the code segment below, using the variables a, b, and c, is
run? - answer 20

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

Infos sur le Document

Publié le
4 janvier 2025
Nombre de pages
13
Écrit en
2024/2025
Type
Examen
Contient
Questions et réponses
$13.49

Mauvais document ? Échangez-le gratuitement Dans les 14 jours suivant votre achat et avant le téléchargement, vous pouvez choisir un autre document. Vous pouvez simplement dépenser le montant à nouveau.
Rédigé par des étudiants ayant réussi
Disponible immédiatement après paiement
Lire en ligne ou en PDF

Seller avatar
Les scores de réputation sont basés sur le nombre de documents qu'un vendeur a vendus contre paiement ainsi que sur les avis qu'il a reçu pour ces documents. Il y a trois niveaux: Bronze, Argent et Or. Plus la réputation est bonne, plus vous pouvez faire confiance sur la qualité du travail des vendeurs.
Pogba119
3.9
(14)
Vendu
62
Abonnés
2
Éléments
5513
Dernière vente
5 jours de cela




Pourquoi les étudiants choisissent Stuvia

Créé par d'autres étudiants, vérifié par les avis

Une qualité sur laquelle compter : rédigé par des étudiants qui ont réussi et évalué par d'autres qui ont utilisé ce document.

Le document ne convient pas ? Choisis un autre document

Aucun souci ! Tu peux sélectionner directement un autre document qui correspond mieux à ce que tu cherches.

Paye comme tu veux, apprends aussitôt

Aucun abonnement, aucun engagement. Paye selon tes habitudes par carte de crédit et télécharge ton document PDF instantanément.

Student with book image

“Acheté, téléchargé et réussi. C'est aussi simple que ça.”

Alisha Student

Vous travaillez sur vos références ?

Créez des citations précises en APA, MLA et Harvard avec notre générateur de sources gratuit.

Vous travaillez sur vos références ?

Foire aux questions