CSC105 Intro to Programming Flashcards

1
Q

The following statement will evaluate to True:

5 > 6) OR (12 < 14

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

The following statement will evaluate to True:

5 > 6) AND (12 < 14

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Which of the following operators is used in most languages to test if two operands do not have the exact same value?

A

!=

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

In a Python program, if the variable value1 is set to 2.0 and and variable value2 is set to 12, what is the output of the following command?

           print(value1 * value2)
A

24.0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Which of the choices is equivalent to the following decision?
if x > 10 then

    if y > 10 then
            output "X"

   endif endif
A

if x > 10 AND y > 10 then output “X” endif

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Which of the following must always be false?

A

e > 10 AND e < 7

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

In the following pseudocode, what percentage raise will an employee in department 8 receive?

if department < 5 then

               raise = SMALL_RAISE
else if department < 14 then
               raise = MEDIUM_RAISE
else if department < 9 then
               raise = BIG_RAISE
A

MEDIUM_RAISE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

If sales = 100, rate = 0.10, and expenses = 50, which of the following expressions is true?

A

sales >50 AND expenses <=100

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Which of the following is the correct “if” clause to determine whether y is in the range 10 through 50?

A

if y >= 10 and y <= 50

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Given the following function definition, what would the statements display?

def magic(num):
          return num + 2 * 10

result = magic(5)

print(result)

A

25

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the result of the following Boolean expression, if x equals 5, y equals 3, and z equals 8?

    x < y or z > x
A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the result of the following Boolean expression, if x equals 5, y equals 3, and z equals 8?

not (x < y or z > x) and y < z
A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Design pseudocode for a module named timesTen. The module should accept an integer argument. When the module is called, it should display the product of its argument multiplied by 10.

After you write the module, call the module passing a 20 to it.

A
Your Answer:
Module timesTen(integerValue)

Declare integerResult

Set integerResult = integerValue * 10

Display result

End Module

result = 200

COMMENT: Need to call your module with an argument of 20

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Design pseudocode for a module named getNumber, which uses a reference parameter variable to accept an Integer argument. The module should prompt the user to enter a number and then store the input in the reference parameter variable.

After you write the module, call the module.

A
Your Answer:
Module getNumber(Real Ref integerValue)

Display “Enter a number: “

Input number

End Module

Module main

Call getNumber

End Module

COMMENT: Need to include argument in your getNumber call

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What will the following pseudocode program display?

Module main()
  Declare Integer x = 1
  Declare Real y = 3.4
  Display x, " ", y
  Call doSomething(x, y)
  Display x, " ", y
End Module
Module doSomething(Integer a, Real b)
  Set a = 0
  Set b = 0
  Display a, " ", b
End Module
A

Your Answer:
Nothing; there is nothing within the quotation marks of the Displays

COMMENT: Actually, we are concatenating three things. The value in x, “ “ (which is a blank space), and the value in y. This will result in 1 3.4 for the two displays in the Main module, and 0 0 in the doSomething module.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Design pseudocode for an If-Then-Else statement that assigns 0 to the variable b if the variable a is less than 10.

Otherwise, it should assign 99 to the variable b.

A

Your Answer:
If a < 10 Then:

b = 0

else b = 99

End If

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Write Python code that asks the user for a product name, the cost of the product and the quantity of the product purchased. Display the product name and the total cost of the purchase.

You do not have to create a function or call a function for this problem.

A
Your Answer:
def productName():

productName = float(input(‘Enter the name of the product: ‘))

return productName

def productCost():

productCost = float(input(‘Enter the cost of the product: ‘))

return productCost

def productQuantity():

productQuantity = float(input(‘Enter the quantity of the product: ‘))

return productQuantity

def totalCost(productName, productQuantity, productCost):

totalCost = productQuantity * productCost

print(‘The name of the product is: )productName

print(‘The total cost of the product is ‘)totalCost

COMMENT: These functions will work, but you also need a main module that will call them in the order you need.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Write Python code that has a function called “doubleMe”. The function requires that an integer value is passed to it when called. The function should double the integer value and return the result.

Write an additional Python statement that calls function “doubleMe” and passes it a 10. The result returned from the function should be stored in a variable called “answer”.

A
Your Answer:
def main():

integerAnswer = integerValue

def doubleMe():

doubleMe = integerValue * 2

integerValue = float(input(‘Enter the number: ‘))

input number

print(“The answer is: “)integerAnswer

end main()

COMMENT: main() never calls doubleMe therefore this script does nothing since we haven’t set values for integerValue or called any other modules.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Write Python code that tests the integer variable called “month”. Based on the value, display the month name. Valid values are: 1 (display January), 2 (display February), and 3 (display March) . Use if/elif statements, not all if statements.

You do not have to create a function or call a function for this problem.

A
Your Answer:
def month():

if month = 1:

print(“The month is January”)

elif month = 2:

print(“The month is February”)

elif month = 3

print(“The month is March”)

end if

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Write Python code that displays “Speed is OK” if the variable “speed” is within the range 24 to 56.

If “speed” holds a value outside the range, display “Speed is abnormal”.

You do not have to create a function or call a function for this problem.

A
Your Answer:
def speed():

if speed >= 24 AND speed <= 56

print(“Speed is OK”)

elif speed < 24 OR speed > 56

print(“Speed is abnormal”)

end if

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Which of the following is the structure that causes a statement or set of statements to execute repeatedly?

A

Repetition

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Which type of loop uses a Boolean expression to control the number of times a loop repeats?

A

condition-controlled

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Statements that appear between the While and End While statements are known as the __________.

A

loop body

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

A __________ represents a special value that marks the end of a list of values.

A

sentinel

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

If an expression is False, the __________ operator will return True.

A

NOT

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

How many times would the following loop iterate?

For j = 1 To 5 Step 2

 Display j

End For

A

3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

How many times would the following loop iterate?

Set k = 1

While k <= 5

 Display k

End While

A

Infinite

28
Q

How many times would the following loop iterate?

Set k = 1

While k > 5

 Display k

End While

A

0

29
Q

How many times would the following loop iterate?

For m = 1 To 8 Step 3

 Display m

End For

A

3

30
Q

The amount by which the counter variable is incremented or decremented in a For loop is known as the __________.

A

step amount

31
Q

In the following pseudocode counter is the accumulator.

For counter = 1 to 6

 Set numberWidgets = numberWidgets + counter

End For

A

False

32
Q

While and For loops are considered pretest loops because they test the condition before processing the statement or statements in the loop body.

A

True

33
Q

The test condition in a While loop must always be an integer value.

A

False

34
Q

The following pseudocode is for a loop that will perform three iterations.

For start = 5 To 10 Step 2

 Do something

End For

A

True

35
Q

A While loop repeats infinitely when there is no statement inside the loop body that will make the test condition false.

A

True

36
Q

A function __________ specifies the return data type, name of the function, and the parameter variable(s).

A

header

37
Q

A __________ is a module that returns a value back to the part of the program that called it.

A

function

38
Q

What is the data type of the value returned by the random function?

A

Integer

39
Q

What would display if the following pseudocode was coded and executed?

Declare String user = “Martha and George”

Declare Integer number

Set number = length(user)

Display number

A

17

40
Q

A function is a special type of __________.

A

module

41
Q

Select all that apply. Which of the following is(are) required when writing a function definition?

A

the function body
the return statement
the function header
the data type

42
Q

Select all that apply. Which of the statement(s) would be true if the following pseudocode was coded and executed?

Declare Integer needNumber

Set needNumber = random(5, 10)

A

A random number is generated between 5 and 10.

The numbers 5 and 10 are the arguments of the random number function.

43
Q

Library functions are built into a programming language and can be called whenever they are needed.

A

True

44
Q

Random numbers are useful in simulation programs where the computer must randomly decide how an object will behave.

A

True

45
Q

When a function finishes executing, it returns a value back to the part of the program that called it.

A

True

46
Q

What would display if the following pseudocode is coded and executed?

Declare String str1 = “car”

Declare String str2 = “green”

Set message = append(str1, str2)

Display “You have a “ , message

A

You have a cargreen

47
Q

What would display if the following pseudocode was coded and executed?

Declare String user = “Joey”

If isInteger(user) Then

 Set intUser = stringToInteger(user)

 Display intUser

Else

 Display "Not a valid number"
A

Not a valid number

48
Q

What would display if the following pseudocode was coded and executed?

Declare String user = “Martha and George”

Display substring(user, 1, 3)

A

art

49
Q

The __________ function does the same thing as using the mathematical ^ operator.

A

pow

50
Q

What is the value of r after the following statement is coded and executed?

Declare Integer i = 12

Declare Real r

Set r = toReal(i)

A

12.0

51
Q

An individual element in an array is identified by its __________.

A

subscript

52
Q

A type of loop that exists in some programming languages specifically for stepping through an array and retrieving the value of each element is known as a __________ loop.

A

For Each

53
Q

__________ arrays are two or more arrays that hold related data where each element of one array has the same subscript as a corresponding element in the other arrays.

A

Parallel

54
Q

Every element in an array is assigned a unique number known as a(n) __________.

A

subscript

55
Q

What is the term used for the number inside the brackets of an array that specifies how many values the array can hold?

A

Size declarator

56
Q

When working with arrays most programming languages perform __________ to ensure that programs don’t use invalid subscripts.

A

array bounds checking

57
Q

What type of error occurs when a loop through an array iterates one time too few or one time too many?

A

off-by-one error

58
Q

In the following declaration, what is the data type of the elements in the array?

Declare Integer numbers[SIZE]

A

Integer

59
Q

Which of the following statements is true about this array declaration?

Declare Integer numbers[5] = 123,456,789,321,654

A

This is an array declaration and initialization

60
Q

Given the following statement, what is the subscript for the data value 92?

Declare Integer numbers[5] = 83,92,78,94,61

A

1

61
Q

Which of the following array declarations would be best suited for storing prices of items sold in a store?

A

Declare Real itemPrice[SIZE]

62
Q

What would display if following statements are coded and executed?

Declare Integer scores[3]= 76, 94, 83

Declare String names[3] = “Joe”, “Amy”, “Pat”

Display names[1], scores[2]

A

Amy 83

63
Q

Which is the correct way to pass an array named studentScores that holds 25 values to a function named getAverage and save the result to a variable named average?

A

Set average = getAverage(studentScores, 25)

64
Q

The number of elements in an array is the value of the subscript of the last element in that array.

A

False

65
Q

To calculate the total of the values in an array, a loop is used with an accumulator variable.

A

True