JULIE ALANO: Welcome to AP Live Review
with Mrs. Julie Alano from Hamilton Southeastern High
School in Fishers, Indiana.
We are going to review questions for the AP Computer Science
Principles exam.
Remember for the AP Computer Science Principles exam,
you get an exam reference sheet.
You're seeing it here on the screen.
You can also access it on the College Board website.
You will get this entire packet to help
to explain the code that's on the AP exam, which is blocks
or text-based pseudocode.
It may not be the language that you learned in your class.
So if you want to reference that now,
we will see some code throughout these questions.
You are also able to access the questions
by accessing a PDF in the top right corner of this video
or in the description on YouTube.
So let's get started.
Let's take a look at our first question.
Question 1-- a numeric test score
is to be converted to a letter grade of A, B, or C
according to the following rules.
If the score is greater than 90, it's
considered an A. If the score is between 80 and 90 inclusive,
it's considered a B. And any other score is considered
a C. Which of the following code segments
will assign a correct letter grade to grade based
on the variable score?
We take a look at number 1.
We see that it assigns B in the else.
This is an if else.
That means one or the other of the options
will be processed in an if else.
So therefore, the grade of C will
be wiped out if the grade is not greater than 90.
So this is not a good choice.
That eliminates two of our answers already.
So if we look at the code on 2 and 3, question 2,
we see if it's greater than 90 we get an A,
if it's greater than or equal to 80, we get a B,
and otherwise, we get a C. That seems
to match what I have highlighted in the question there.
So we'll say that is one of the answers.
And then we'll look at option 3.
If the score is less than 80, we assign the grade C.
If the score is less than or equal to 90,
we assign the grade B. And otherwise, we
assign A. Again, that goes the other direction,
but it seems to assign the correct values.
And so we're going to say 3 is an answer as well.
So, 2 and 3 give us the correct answers.
So the answer here is D.
Question 2-- in the following procedure,
assume that the parameter x is an integer.
So we have x.
If x is negative in every single one of our answers-- so let's
think about if x is negative, that means y would
be assigned the value true.
So if y is assigned true, then our if is processed,
because it says if y.
That means if y is true, it will display y.
So therefore, I can look at my four options
and say, oh, A and B are eliminated
because it will display y.
So y is true, it displays true if x is negative.
And what does it do otherwise?
Nothing, because there is no else.
So therefore, our other part, it displays nothing.
That means our answer is C.
All right, question number 3--
a student wrote the code segment to the left,
which displays true if the list myList contains
any duplicate values and displays false otherwise.
The code segment compares pairs of list elements,
setting containsDuplicates to true
if any two elements are found to be equal in value.
Which of the following best describes
the behavior of how pairs of elements are compared?
So notice the code here.
We have two repeats.
We have two variables, j and k.
So clearly, the code segment iterates through myList.
And so I've underlined the parts of the answer choices
which are different.
So we are comparing each element to all other elements
in the list?
Are we comparing each element to all subsequent elements
in the list?
Or to just the element that immediately follows?
Or to the element that immediately precedes?
This k equals j plus 1 is really important here.
So we set j to 1 to begin with.
And then inside the first repeat, we set k to j
plus 1, which means it's the one after k.
And you notice that we are comparing in our if,
if myList j is equal to myList k.
So we really are concerned about those values j and k.
So if we set k to j plus 1, then we're
not dealing with the one immediately preceding it.
And so we are looking at the one after it.
But we're not just looking at it once.
That's in a loop, too.
So therefore, we can eliminate C and so now,
are we comparing it to all the other elements in the list.
If we set k to one more than j, then we're
just doing all the ones after it because we're not
comparing it to the one before.
And again, every time through the loop, j changes.
So every time, we just keep going to the subsequent values.
So therefore, our answer is B.
On to question 4--
a homework assignment consists of 10 questions.
The assignment is graded using the chart to the left.
Let numCorrect represent the number of correct answers
for a particular student.
The code segment to the left is intended
to display the appropriate grade based on numCorrect.
The code segment does not work as intended in all cases.
So, for which of the values of numCorrect
does it not display the intended grade?
And we have to select two answers.
So in this case, let's just try them.
So we try 9.
9's greater than 7.
9's greater than or equal to 9.
So it will display check plus.
That one seems to be accurate, which
means it's not one of our answers
because we're looking for one that does not
display the intended grade.
Moving on to 8--
8 is greater than 7.
And then we go into the second half.
8 is not greater than or equal to 9.
So else, it will display check minus.
That is not what A is supposed to display.
So therefore, it is one of our answers.
Now 7-- 7 is not greater than 7.
So then it will go to the else and display check.
That is what 7 is supposed to display according to the chart,
so that is not one of our answers.
Again, now 6-- 6 is not greater than 7.
That means it will go to that big else.
Display check.
6 is under 7, so it should be check minus.
That is not what is intended.
So our two answers are B and D. Don't really
worry about how to fix code.
All we need to do is find the two
that don't work as intended.
All right, question 5--
in the following code segment, score and penalty
are initially positive integers.
The code segment is intended to reduce the value of score
by penalty.
However, if doing so would cause score to be negative,
score should be assigned a value, 0.
So there's our important pieces of that first sentence.
For example, if score is 20 and penalty is 5,
the code segment should set score to 15.
If score is 20 and penalty is 30, score would be set to 0.
So let's take a look here at the code segment that
does not work as intended.
And we are trying to find which of the changes
that can be made to make it work as intended.
So it looks like our if is correct.
If score minus penalty is less than 0, we want to set it to 0.
Oh, but that doesn't look quite right.
So let's look at our answer choices.
So should we change line 1 to if score's less than 0?
Doesn't seem right, because score
should be positive to begin with and say, if we subtract,
is it less than 0?
So, not A. Change it to score plus penalty?
Both B and C talk about adding penalty to the score.
Nowhere in our question does it talk about adding the penalty.
So I'm going to eliminate choice B and choice C.
And then I see choice D. Oh, switch line 3 and 7?
That seems to be correct because if score minus penalty
is less than zero we want to set score to 0.
Otherwise, we want to go ahead and subtract like the choice
of the example of 20 minus 5.
So D is our answer, interchanging lines 3 and 7.
All right, question number 6--
consider the following code segment.
What is the value of R as a result of executing the code
segment?
Here's a big chart where we're just assigning values.
Remember, that arrow means to assign the value of.
Or you could say, get.
And so, during the exam, you should write this down
on your test booklet or on your scrap paper
and trace the values of the variables.
So here, I have p, q, r, and s.
And those first four lines of code
set them to 10, 20, 30, and 40.
So then I'm going to go on to where
p is assigned the value of 2.
On your paper, that means p gets wiped out
and is now assigned sound the value of 20.
So then we move on to the next line.
q is assigned the value of r.
So that means q gets wiped out and is assigned
the value of r, which is 30.
Next line-- s gets the value of q.
That means s gets wiped out and assigned
the value of q, which is 30.
And our final line, r gets the value of p.
So r gets wiped out, is assigned the value of 20.
And that is our answer because we want the value of r.
So that means our answer is B. So using your scrap paper
or your test booklet to write this down is very helpful.
Question number 7-- three words are
stored in the variables word1, word2, and word3.
The values of the variables are to be updated as shown
in the following table.
So you see we have word1, word2, wod3 three Notice their value
before and the value after.
So looking at this, word2 doesn't change.
So I can quickly determine which of the following code
segments-- or eliminate some of the following code
segments-- that need to update the values, as shown.
So word2 doesn't change.
Therefore, means I don't need to mess with word2.
So I can eliminate choices C and D. Now I'm down to and B
the difference between answers and B is that second line.
Really, the second line-- the third line is different too,
but it's really second line that makes a difference.
In both of them, the first line assigns the value word to temp.
So that means word1 has been saved
in the temporary variable.
So therefore, we need to now have
word1 get the value of word3, because we've saved word1.
So now we need it to store the value of word3.
And then we can put the temp into Word3.
And that will swap the two values--
again, a common piece of code that you've
probably seen before.
And so therefore, we need to use answer B,
because that assigns a value from word3 into word1,
and then the temp is stored in word3.
Question 8-- consider the following procedures
for string manipulation.
We have contact and we have prefix.
The variable initials is to be assigned a string consisting
of the first letter of the string firstName followed
by the first letter of the string lastName.
Which of the following assigns the correct string to initials?
So you see there, we've already eliminated one of the choices,
because we need to get the prefixes
and assign them to each one.
And so we know the first letter.
So we notice there, that prefix pulls off one character.
So we don't need two characters of the prefix.
So I eliminated choice B.
And then, also looking here at how concatenate works,
I need to do string one followed by string two.
Therefore, I can eliminate these because I don't
want to concatenate first.
I need to do that prefix first.
And so after looking at those numbers
and realizing that I need to get the prefixes, then connect,
that means our answer is going to be A.
On to question 9--
the following code segment is used
to determine whether a customer is
eligible for a discount on a movie ticket.
The category is new, so I'm just going to go ahead and replace
category with that value.
And the age is 20.
So if that is the case-- so I'm just going to write those in--
and if that is, what are the values
of val1 and val2 a result of executing this code segment?
So, we see first, this is true, because new equals new but.
Then it says not.
So that is false.
And then on the right, 20 is not greater than 65.
So that's false.
So I have false or false, which results in the entire segment
being false.
So next one, new is true.
New equals new is true, while 20 is not less than 12.
So that's false.
So true and false results in false.
So that means our answer is both of them are false, or D.
All right, question number 10--
a software development company has created an application
called FileCleanUp.
When the application is run on a user device,
it searches for all files-- including pictures, video,
and documents-- that have not been accessed in the past month
and stores them on the company's web server
and deletes them from the user device.
The application runs once each day.
And users have the ability to manually retrieve files
from the server if they are needed.
So, which of the following is most
likely to be a harmful effect of using FileCleanUp?
So the difference is in the question here
are frequently used files, or infrequently used files?
It's really kind of what we're looking at.
So it's these infrequently used files that have been stored.
And so you notice, we're talking about internet connectivity,
too.
So if there's no internet connectivity,
it's those infrequently used files
that are important to take a look at.
So that means I can eliminate those choices of those
frequently used ones, and look at the infrequently used ones.
And if there is no internet, that's a problem.
We could not access them.
So that's a harmful effect.
I still want to be able to access them.
So that's why the answer there is B. All right,
we've come to the end of our questions.
If there are anything that you need to review,
here are the topics that were covered in this session--
collaboration, program function and purpose,
program design and development, identifying and correcting
errors, beneficial and harmful effects, and computing bias.
Again, you can find more about these topics on the AP Daily
Videos on AP Classroom.
We also cover these topics from Big Idea 3,
so a lot to do with variables, data, mathematical expressions,
strings, Boolean expressions, conditionals, and iteration
and developing algorithms.
Again, check out the AP Daily videos
on these topics on AP Classroom.
Thank you for joining me.
I will see you next time.