PROGRAMMING FOUNDATIONS
QUESTIONS & ANSWERS(RATED A+)
Which operator should be used to determine if a number is evenly divisible by 5? -
ANSWER%
A car drove 200 miles using 10 gallons of fuel.
Which operation should be used to compute the miles per gallon, which is 20? -
ANSWERDivision
A variable should hold a person's height in meters.
Which data type should the variable be? - ANSWERFloat
A variable should hold the names of all past U.S. presidents.
Which data type should the variable be? - ANSWERString array
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? -
ANSWERConstant 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? - ANSWERConstant
integer minAge
Given integer x = 3 and integer y = 5.
What is the value of the expression ( x / 2.0) + y? - ANSWER6.5
Given float x = 10.2 and float y = 1.0.
What is the value of the expression x / y ? - ANSWER10.2
What kind of operator is the == in the expression i == 20? - ANSWEREquality
What is the purpose of parentheses () in a programming expression? - ANSWERTo
group expressions
Given float x = 3.0.
Which expression evaluates to 2.0? - ANSWERx / 2 + 0.5 /2 + .25
Which expression evaluates to true only when the user is within 3 years of 21 years,
given a variable x containing a user's age? - ANSWER( x >= 18) and ( x <= 24)
, Which data type is used for items that are measured in length? - ANSWERFloat
Which data type should be used to keep track of how many planes are in a hangar? -
ANSWERInteger
A function should convert hours and minutes to seconds, such as converting 1 hour and
10 minutes to 4,200 seconds.
What should be the input to the function? - ANSWERHours and minutes
A function returns a number x cubed. For example, if x is 3, the function returns 3 * 3 *
3, or 27.
What should be the input to the function? - ANSWERx
A function calculates the weight difference (Diff) given two sample weights (S1 and S2).
What should be the output from the function? - ANSWERDiff
function P(integer x) returns integer y
y=2*x
What does P(5) evaluate to? - ANSWER10
Function F()
Put "Hey" to output
What entire output appears after three successive calls to F()? - ANSWERHeyHeyHey
What is a valid user-defined function name? - ANSWERAny valid identifier
A function MyFct has an input x and an output z.
What does MyFct return? - ANSWERz only
What is the return value of a function? - ANSWEROutput 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? - ANSWERWhile 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? - ANSWERDo-while loop
What is put to output by the following pseudocode:
x=3
do
Put x to output
Put " " to output