Instructions: The first three problems ask you to read a Pseudocode function definition. Trace through each of them by hand, keeping track of the variables, to determine the answer to the question.
Problem Solution # Comment: A function definition that takes 1 parameter To functionA(a): Return: a + 100 Trace: functionA(5) returns 5 + 100 = 105
Problem Solution # Comment: Convert inches to centimeters # There are 2.54 centimeters per inch To inchesToCm(in): Return in * 2.54 Trace: inchesToCm(10) returns 2.54 * 10 = 25.4
Problem Solution # Comment: A mystery function with 2 arguments To mystery(x, y): Set M to x If y < x then do: Set M to y Return M x y M Return -------------------------------- 3 2 3 2 2 mystery(3,2) returns 2 2 3 2 2 mystery(2,3) returns 2 This function computes the minimum of its arguments, a and b.
Instructions: The next three problems ask you to define a
function in Pseudocode. Model your answers after the Pseudocode
algorithms in the first 3 questions.
# A function to compute the average of 3 arguments To avg3(a, b, c): Return (a + b + c) / 3
# A function to convert kilometers to miles. To kmToMiles(km): Return km * 0.62
# A function to calculate the circumference of a circle with radius r To circumference(r) Return r * 3.14 * 2