Docsity

D278 SCRIPTING AND PROGRAMMING FOUNDATIONS LESSONS WITH EXPLAINED EXAMPLES, Exams of Programming Paradigms

Toggle sidebar
bg1
D278 SCRIPTING AND
PROGRAMMING FOUNDATIONS
LESSONS WITH EXPLAINED
EXAMPLES
โ—‰ A program uses the number of seconds in a minute in various
calculations.
How should the item that holds the number of seconds in a minute
be declared?
Answer: Constant integer secondsPerMinute
โ—‰ A program determines if a user's age is high enough to run for U.S.
president. The minimum age requirement is 35.
How should the item that holds the minimum age be declared?
Answer: Constant integer minAge
โ—‰ Given integer x = 3 and integer y = 5.
What is the value of the expression (x / 2.0) + y?
pf3
pf4
pf5

Partial preview of the text

Download D278 SCRIPTING AND PROGRAMMING FOUNDATIONS LESSONS WITH EXPLAINED EXAMPLES and more Exams Programming Paradigms in PDF only on Docsity!

D278 SCRIPTING AND

PROGRAMMING FOUNDATIONS

LESSONS WITH EXPLAINED

EXAMPLES

โ—‰ A program uses the number of seconds in a minute in various calculations. How should the item that holds the number of seconds in a minute be declared? Answer: Constant integer secondsPerMinute โ—‰ A program determines if a user's age is high enough to run for U.S. president. The minimum age requirement is 35. How should the item that holds the minimum age be declared? Answer: Constant integer minAge โ—‰ Given integer x = 3 and integer y = 5. What is the value of the expression (x / 2.0) + y?

Answer: 6. โ—‰ Given float x = 10.2 and float y = 1.0. What is the value of the expression x / y? Answer: 10. โ—‰ What kind of operator is the == in the expression i == 20? Answer: Equality โ—‰ What is the purpose of parentheses () in a programming expression? Answer: To group expressions โ—‰ Given float x = 3.0. Which expression evaluates to 2.0? Answer: x / 2 + 0.5 /2 +. โ—‰ Which expression represents all the values of x, when x is the age ranging from 18 to 24 years old? Answer: (x >= 18) and (x <= 24)

What should be the output from the function? Answer: Diff โ—‰ function P(integer x) returns integer yy = 2 * x What does P(5) evaluate to? Answer: 10 โ—‰ Function F()Put "Hey" to outputWhat entire output appears after three successive calls to F()? Answer: HeyHeyHey โ—‰ What is a valid user-defined function name? Answer: Any valid identifier โ—‰ A function MyFct has an input x and an output z. What does MyFct return? Answer: z only โ—‰ What is the return value of a function? Answer: Output of a function

โ—‰ A program should continue accepting input numbers, adding each to a sum, until a 0 is input. Which control structure should be used? Answer: While loop โ—‰ Joe is building an online game. He wants to provide a riddle and have the player guess the answer. The game needs to prompt the user to enter the answer, check to see if it the input provided does not match the correct answer, and continue prompting the user until the answer entered matches the correct answer. Which control structure supports Joe's needs? Answer: Do-while loop โ—‰ What is put to output by the following pseudocode? x = 3 do Put x to output Put " " to output x = x - 1 while x > 0