Students will gain experience writing code in the agnostic language of AP CSP.
AAP-2.H.2: The exam reference sheet provides
IF(condition)
{
<block of statements>
}
in which the code in block of statements is executed if the Boolean expression condition evaluates to true; no action is taken if condition evaluates to false.
AAP-2.H.3: The exam reference sheet provides
IF(condition)
{
<first block of statements>
}
ELSE
{
<second block of statements>
}
in which the code in first block of statements is executed if the Boolean expression condition evaluates to true; otherwise, the code in second block of statements is executed.
AAP-2.M: For algorithms:
a. Create algorithms.
AAP-3.A.5: The exam reference sheet provides procName (arg1, arg2, …) as a way to call PROCEDURE procName(parameter1, parameter2, …) which takes zero or more arguments; arg1 is assigned to parameter1, arg2 is assigned to parameter2, and so on.
AAP-3.A.6: The exam reference sheet provides the procedure DISPLAY(expression) to display the value of expression, followed by a space.
AAP-3.A.7: The exam reference sheet provides the RETURN(expression) statement, which is used to return the flow of control to the point where the procedure was called and to return the value of expression.
AAP-3.A.8: The exam reference sheet provides result ß procName(arg1, arg2, …) to assign to result the “value of the procedure” being returned by calling PROCEDURE procName(parameter1, parameter2, …){ <block of statements> RETURN(expression) }
AAP-3.A.9: The exam reference sheet provides procedure INPUT(), which accepts a value from the user and returns the input value.
AAP-3.C.1: The exam reference sheet provides
PROCEDURE procName(parameter1, parameter2, …)
{
<block of statements>
}
which is used to define a procedure that takes zero or more arguments. The procedure contains block of statements.
AAP-3.C.2: The exam reference sheet provides
PROCEDURE procName(parameter1, parameter2, …)
{
<block of statements>
RETURN(expression)
}
which is used to define a procedure that takes zero or more arguments. The procedure contains block of statements and returns the value of expression. The RETURN statement may appear at any point inside the procedure and causes an immediate return from the procedure back to the calling statement.
The objective of this lesson is to provide students with exposure to the agnostic coding language used in the AP CSP exam through a coding task.
Activity 5.10.1 (55 minutes)
Students should be provided with a copy of the AP CSP exam reference sheet. This assignment will be hand-written.
Students should write a script that follows the prompt below:
create an empty string assigned to a variable named songStructure
define a procedure named writeSong that takes the number of choruses (which will always be at least 2) as an argument
each section of the song added to songStructure should be separated by " -> "
add verses to songStructure until the correct number of choruses have been added
add a chorus after every 2 verses
if there is one chorus remaining, add a bridge instead of the 2 verses
after the correct number of choruses have been added, add an outro
print out the final song structure
For example, the final song structure for a song that has 3 choruses should be the following:
"verse -> verse -> chorus -> verse -> verse -> chorus -> bridge -> chorus -> outro"
The answer key for this prompt is provided for the teachers.