AP CSP Mathematical procedures and constants

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Brayden is writing code to calculate the surface area of a cylinder based on this formula: \text{Surface area} = 2 \pi r h + 2 \pi r^2Surface area=2πrh+2πr 2 start text, S, u, r, f, a, c, e, space, a, r, e, a, end text, equals, 2, pi, r, h, plus, 2, pi, r, squared He's testing the code on this cylinder: Cylinder with radius of 3 and height of 2 The code starts with these variables, where radius represents rrr and height represents hhh: radius ← 3 height ← 2 The built-in constant PI stores an approximation of \piπpi. Which expression correctly calculates the surface area? Choose 1 answer:

(2 * PI * radius * height) + (2 * PI * radius * radius)

Consider the following code segment: a ← 3 b ← 8 c ← 5 result ← min( max(a, b), c) The code relies on these built-in procedures: Name Description min(a, b) Returns the smaller of the two arguments. max(a, b) Returns the greater of the two arguments. After the code runs, what value is stored in result?

5

Consider the following code segment: a ← 2 b ← 4 c ← 6 d ← 8 result ← max( min(a, b), min(c, d) ) The code relies on these built-in procedures: Name Description min(a, b) Returns the smaller of the two arguments. max(a, b) Returns the greater of the two arguments. After the code runs, what value is stored in result? Choose 1 answer:

6

Joo-won is writing code to calculate the volume of a cone based on this formula: \text{Volume} = \pi r^2 \dfrac{h}3Volume=πr 2 3 h start text, V, o, l, u, m, e, end text, equals, pi, r, squared, start fraction, h, divided by, 3, end fraction He's testing his code on this cone: Cone with height of 5 and radius of 2 The code starts with these variables, where radius represents rrr and height represents hhh: radius ← 2 height ← 5 The built-in constant PI stores an approximation of \piπpi. Which expression correctly calculates the volume? Choose 1 answer:

PI * (radius * radius) * (height / 3)

A digital artist is programming a natural simulation of waves. They plan to calculate the y position of the wave using this wave equation: y = Acos(\dfrac{2\pi}{\lambda}x)y=Acos(λ2π​x)y, equals, A, c, o, s, left parenthesis, start fraction, 2, pi, divided by, lambda, end fraction, x, right parenthesis The environment provides the built-in procedure cos(angle) which returns the cosine of angle. The built-in constant PI stores an approximation of PI. In the artist's code, the variable x represents the x position (xxx), wL represents the wavelength (\lambdaλlambda), and amp represents the amplitude (AAA). Which of these code snippets properly implements the wave formula? Choose 1 answer:

amp * cos( ((2 * PI)/wL) * x)

An astronomer is writing a program demonstrating Kepler's three laws of planetary motion, including this ratio of orbital period compared to average orbital radius: \text{Constant} = T^2/R^3 Constant=T 2/R 3 start text, C, o, n, s, t, a, n, t, end text, equals, T, squared, slash, R, cubed This is their code for computing that ratio: keplerRatio ← (period * period) / (radius * radius * radius) They then discover that the coding environment offers a number of useful mathematical procedures: Name Description add(n, m) Returns the addition of n to m. sqrt(n) Returns the square root of nnn. square(n) Returns the value of n^2n 2 n, squared. cube(n) Returns the value of n^3n 3 n, cubed. pow(n, m) Returns the value of n^mn m n, start superscript, m, end superscript. How could the code be rewritten using the procedures? 👁️Note that there are 2 answers to this question.

keplerRatio ← pow(period, 2) / pow(radius, 3) keplerRatio ← square(period) / cube(radius)

A game programmer decides to use the Pythagorean distance formula for collision detection: d = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2}d= (x 2 −x 1) 2 +(y 2−y 1) 2 d, equals, square root of, left parenthesis, x, start subscript, 2, end subscript, minus, x, start subscript, 1, end subscript, right parenthesis, squared, plus, left parenthesis, y, start subscript, 2, end subscript, minus, y, start subscript, 1, end subscript, right parenthesis, squared, end square root The programming environment provides these built-in procedures: Name Description sqrt(n) Returns the square root of nnn. square(n) Returns the value of n^2n 2n, squared. In the programmer's code, the coordinates are represented by the variables x1, y1, x2, y2. Which of these code snippets properly implements the distance formula?

sqrt( square(x2 - x1) + square(y2 - y1) )

Harper is writing code to calculate the surface area of a sphere, based on this formula: \text{Surface area} = 4 \pi r^2Surface area=4πr 2 start text, S, u, r, f, a, c, e, space, a, r, e, a, end text, equals, 4, pi, r, squared This is their code so far: surfaceArea ← 4 * 3.14159 * (radius * radius) They then discover that the coding environment has a built-in constant for PI plus a number of useful mathematical procedures: Name Description add(n, m) Returns the addition of n to m. sqrt(n) Returns the square root of nnn. square(n) Returns the value of n^2n 2 n, squared. cube(n) Returns the value of n^3n 3 n, cubed. pow(n, m) Returns the value of n^mn m n, start superscript, m, end superscript. How could the code be rewritten using the constant and procedures? 👁️Note that there are 2 answers to this question.

surfaceArea ← 4 * PI * pow(radius, 2) surfaceArea ← 4 * PI * square(radius)

Malcolm is writing code to calculate the volume of a sphere, based on this formula: \text{Volume} = \dfrac43 \pi r^3Volume= 3 4 πr 3 start text, V, o, l, u, m, e, end text, equals, start fraction, 4, divided by, 3, end fraction, pi, r, cubed This is his code so far: volume ← (4/3) * 3.14159 * (radius * radius * radius) He then discovers that the coding environment has a built-in constant for PI plus a number of useful mathematical procedures: Name Description add(n, m) Returns the addition of n to m. sqrt(n) Returns the square root of nnn. square(n) Returns the value of n^2n 2 n, squared. cube(n) Returns the value of n^3n 3 n, cubed. pow(n, m) Returns the value of n^mn m n, start superscript, m, end superscript. How could the code be rewritten using the constant and procedures? 👁️Note that there are 2 answers to this question. Choose 2 answers:

volume ← (4/3) PI cube(radius) volume ← (4/3) PI pow(radius, 3)

A digital artist is creating an animation with code. Their code needs to convert polar coordinates to cartesian coordinates, using these formulas: x = r × cos( θ )\\y = r × sin( θ )x=r×cos(θ) y=r×sin(θ) The environment provides these built-in procedures: Name Description sin(angle) Returns the sine of the given angle. cos(angle) Returns the cosine of the given angle. In their code, theta represents the current angle and r represents the current radius. Which of these code snippets properly implements the conversion formulas? Choose 1 answer:

x ← r * cos(theta) y ← r * sin(theta)


Kaugnay na mga set ng pag-aaral

Vsim Health Assessment Case: Jared Griffin

View Set

OSHA Cert Study Guide Part 4: Avoiding Electrocution Hazards

View Set

Econ 380 final exam - labor economics - Mcgann - ch 1-11,14,16-18

View Set

chap 28 + 32 bio 2 part 1 final exam

View Set