Correct Implementation of Greeting Procedure Answer Needed
Your question:
A program's expected function is to return a greeting message, including the user's name. Review the AP Exam pseudocode code segment below. x ← INPUT() y ← greeting(x) DISPLAY(y) Which of the following is the correct implementation of the greeting() procedure? PROCEDURE greeting(name) { DISPLAY(Concat("Good Morning ", name)) } PROCEDURE greeting(x) { DISPLAY(Concat("Good Morning ", name)) } PROCEDURE greeting(name) { RETURN(Concat("Good Morning ", name)) } PROCEDURE greeting(name) { RETURN(Concat("Good Morning ", "name")) }
Correct Implementation of Greeting Procedure Answer and Explanation
B. PROCEDURE greeting(x) { DISPLAY(Concat("Good Morning ", name)) }: This procedure uses x instead of name for the greeting, resulting in an incorrect message being displayed.
D. PROCEDURE greeting(name) { RETURN(Concat("Good Morning ", "name")) }: This procedure uses the literal string "name" instead of the actual user input variable, resulting in an incomplete greeting.


