apcsp midterm exam questions

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

The definition of an expression...

A combination of operators and values that evaluates to a single value

Consider the following code segment: What values, when inputted by the user, of A, B and C will cause the code to display "The number is 10"? A. A = 5 B = 7 C = 12 B. A = 4 B = 5 C = 11 C. A = 3 B = 3 C = 10 D. A = 2 B = 6 C = 6

B

What is the process of debugging?

Describe, Hunt, Try, Document

Which of the following best describes the purpose of a design specification?

Describing the requirements for how a program will work or users will interact with it

How does a Local variable work?

Temporary. Can be used only in the part of the code where it was created, like inside an onEvent(). Deleted once the onEvent() is done running.

The following program is run. Then the user clicks the "bottomButton" TWO TIMES. What will be displayed in the console?

bbb ddd ccc ccc

var x = 5; x = x+1; x = x+4; x = x+9; if(x<10){ console.log("Less than 10"); } else if ((x<20)){ console.log("Less than 20"); } else if ((x<30)){ console.log("Less than 30"); } else { console.log("More than 30"); }

"Less than 20"

Choose the lines of code that will evaluate to a concatenated string. Multiple answers-Choose all of the correct answers.

"starry " + "nights" "99" + "100"

Consider the following code segment. p <-- 10 q <-- 20 r<-- 30 s <-- 40 p <-- q q <-- r s<-- q r <-- p What is the value of r as a result of executing the code segment?

20

The diagram below shows a circuit composed of three logic gates. Each gate takes two inputs and produces a single output. For which of the following input values will the circuit have an output of true ?

A = false, B = true, C = true, D= true

Directions: The question or incomplete statement below is followed by four suggested answers or completions. Select the one that is best in each case. A student is writing a program to model different real-world events using simulations. Which of the following simulations will generate a result that would best be stored using a Boolean variable?

A simulation of flipping a fair coin

Consider the code below. Which of the following best describes the conditions which must be satisfied by the threeboolean variables Bool1, Bool2 and Bool3, if the program is to display Pass Pass when run?

Bool1 and Bool2 must both be true, while Bool3 must be false.

A programmer has a need to round many numeric values to the nearest integer. Which of the following best explains the benefit of using a list as a data abstraction in this situation?

Keeping the numeric values in a list makes it easier to apply the same computation to every data element.

Given a list of integers, sequence, and an integer, value, which of the following best describes what the code segment does?

The number of items in sequence that are less than value is displayed.

This question is based on the Truth Tables for && and || The diagram below shows a circuit composed of two logic gates labeled OR and AND. Each gate takes two inputs and produces a single output.

The output will be true no matter what the value of input B is.

Consider the following program, which is intended to display the number of items on a list which are not equal to an item called stopValue Which of the following best describes the behavior of the program?

The program displays the number of words not equal to stopValue subtracted from the number of words equal to stopValue.

Directions: For the question or incomplete statement below, two of the suggested answers are correct. For this question, you must select both correct choices to earn credit. No partial credit will be earned if only one correct choice is selected. Select the two that are best in each case. Which of the following are benefits of using well-named variables in a computer program? Select two answers.

The program will be easier for people to read. The program will be easier to modify in the future.

What are the following symbols called <- and =

assignment operators

A flowchart is a way to visually represent an algorithm. The flowchart below is used by an application to set the Boolean variable available to true under certain conditions. The flowchart uses the Boolean variable weekday and the integer variable miles. Block Explanation Oval The start or end of the algorithm Diamond A conditional or decision step, where execution proceeds to the side labeled true if the condition is true and to the side labeled false otherwise Rectangle One or more processing steps, such as a statement that assigns a value to a variable

available <--- weekday AND miles < 20

What will the "background-color" of the "topButton" be when the program is finished running?

blue

Directions: The question or incomplete statement below is followed by four suggested answers or completions. Select the one that is best in each case. Computers are often used to search through large sets of data to find useful patterns in the data. Which of the following tasks is NOT an example where searching for patterns is needed to produce useful information? A A credit card company analyzing credit card purchases to identify potential fraudulent charges B A grocery store analyzing customers' past purchases to suggest new products the customer may be interested in C A high school analyzing student grades to identify the students with the top ten highest grade point averages D An online retailer analyzing customers' viewing habits to suggest other products based on the purchasing history of other customers

c

Type of selection statement that only executes when a certain criteria is met.

if statement

The variable age is to be used to represent a person's age, in years. Which of the following is the most appropriate data type for age ?

number

The following are examples of _______________: + - * /

operators

day_of_week = "Saturday" day_of_week = "Monday' IF day_of_week= "Saturday" OR day_of_week= "Sunday" weekend ELSE weekday PROCEDURE weekday DISPLAY "School day" PROCEDURE weekend DISPLAY "Day off"

school day

Program instructions that are executed one at a time, in order.

sequential

Which of the following COULD NOT possibly be the output?a <- RANDOM(1,10)b <- RANDOM(10,20)DISPLAY(a)DISPLAY(a)DISPLAY(b)DISPLAY(b)

10 5 10 5

Consider the following segment of code. IF (num > 10) { num ← num * 2 } IF (num < 40) { num ← num / 2 } DISPLAY (num) Which of the following numbers, if originally assigned to num, would display the same value for num after executing the above block of code?

15

var x = 5; x = x+1; x = x+4; x = x+9; console.log(x);

19

Consider the following code segment, which uses the variables r, s, and t. r ← 1 s ← 2 t ← 3 r ← s s ← t DISPLAY (r) DISPLAY (s) What is displayed as a result of running the code segment?

2 3

The question below uses a robot in a grid of squares. The robot is represented as atriangle, which is initially in the bottom-left square of the grid and facing toward the right of thegrid. Which of the following code segments can be used to move the robot to the gray square?

A REPEAT 2 TIMES ROTATE LEFT () MOVE FORWARD () ROTATE RIGHT () MOVE FORWARD ()

Which of the following is NOT a reason to include comments in programs?

Comments help the computer decide whether certain components of a program are important.

The cost of a customer's electricity bill is based on the number of units of electricity the customer uses. For the first 25 units of electricity, the cost is $5 per unit. For units of electricity after the first 25, the cost is $7 per unit. Which of the following code segments correctly sets the value of the variable cost to the cost, in dollars, of using numUnits units of electricity?

IF numUnits≤25 cost<---- numUnits * 5 ELSE cost <---- 25 * 5 + (numUnits-25) * 7

In a certain country, a person must be at least 16 years old to drive a car and must be at least 18 years old to vote. The variable age represents the age of a person as an integer. Which of the following expressions evaluates to true if the person is old enough to drive but not old enough to vote, and evaluates to false otherwise? I. (age ≥ 16) AND (age ≤ 18) II. (age ≥ 16) AND (NOT(age ≥ 18)) III. (age < 18) AND (NOT(age < 16))

II and III only

In which of the following stages of the development process is a team MOST likely to interview a potential user of an app?

Investigating and Reflecting

Directions: For the question or incomplete statement below, two of the suggested answers are correct. For this question, you must select both correct choices to earn credit. No partial credit will be earned if only one correct choice is selected. Select the two that are best in each case. Which of the following Boolean expressions are equivalent to the expression NUM≥ 15 Select two answers

NOT (num < 15) (num . 15) OR (num = 15)

How does a Global variable work?

Permanent. Can be used anywhere in your code.

score <- 4 lives <- 3 If lives=0 Display "You Lose!" else if score >= 5 AND lives = 3 Display "Perfect Game!" Else Display "You Win!"

You Win!

Which of the following is a benefit of using a list as a data abstraction in a program? A Lists often allow their size to be easily updated to hold as many data values as needed. B Lists convert all elements to strings so that they can be inspected character-by-character. C Lists prevent duplicate data values from appearing in the list. D Lists are used to store all input data so that there is a running record of all user input.

a

If the user does NOT click the button what color will "topButton" be when this program finishes running?

blue

The variable isOpen is to be used to indicate whether or not a store is currently open. Which of the following is the most appropriate data type for isOpen ?

boolean

The following program is run. Then the user clicks the "bottomButton" ONCE and then clicks the "topButton" ONCE. What will be displayed in the console?

ccc bbb aaa

Match the definition to the correct word: Only executes if a certain designated condition is true.

conditional

The algorithm below is used to simulate the results of flipping a coin 4 times. Consider the goal of determining whether the simulation resulted in an equal number of heads and tails. Step 1: Initialize the variables heads_counter and flip_counter to 0. Step 2: A variable coin_flip is randomly assigned a value of either 0 or 1. If coin_flip has the value 0, the coin flip result is heads, so heads_counter is incremented by 1. Step 3: Increment the value of flip_counter by 1. Step 4: Repeat steps 2 and 3 until flip_counter equals 4. Following execution of the algorithm, which of the following expressions indicates that the simulation resulted in an equal number of heads and tails?

heads_counter = 2

he variable age is to be used to represent a person's age, in years. Which of the following is the most appropriate data type for age ? A Boolean B number C string D list

number

In the following expression, the variable truckWeight has the value 70000 and the variable weightLimit has the value 80000. truckWeight < weightLimit What value does the expression evaluate to?

true

Which of the following statements could replace condition to make the following codefragment an infinite loop?

y ≥ 8

Which of the following programming scenarios would benefit most from the use of lists?

Writing a program to calculate statistics about a large set of exam scores (e.g. highest/lowest score, median average score).

What are booleans?

a value that is TRUE or FALSE

The following program is run. Then the user clicks the "topButton" button ONCE. What will be displayed in the console?

cat dog bird

Which of the following can be used to replace <MISSING CONDITION> so that the code fragment will work as intended?

(num MOD 2) = 1

A programmer wants to determine whether a score is within 10 points of a given target. For example, if the target is 50, then the scores 40, 44, 50, 58, and 60 are all within 10 points of the target, while 38 and 61 are not. Which of the following Boolean expressions will evaluate to true if and only if score is within 10 points of target ?

(target - 10 ≤ score) AND (score ≤ target + 10)

If the value of x is 3 and the value of y is 5, what is displayed as a result of executing the code segment?

-2

What are specific debugging skills?

1)Slow down code (2) Use console.log to output (3) Use Watchers to see your variables change values

var x = 2; var y = 3; x = y; y = 5; x = 10; y = 4; console.log(x);

10

Directions: The question or incomplete statement below is followed by four suggested answers or completions. Select the one that is best in each case. Consider the following program, which uses the variables start, end, and current start <--- 1 end <--- 20 current <--- 3 start <--- current current <--- current +1 DISPLAY (start) DISPLAY (current)

3 4

number <- INPUT() IF (number >= 10) { IF (number <= 20) { DISPLAY("MEDIUM") } ELSE { DISPLAY("HOT") } } ELSE { DISPLAY("COLD") }

5

A teacher is writing a code segment that will use variables to represent a student's name and whether or not the student is currently absent. Which of the following variables are most appropriate for the code segment?

A string variable named studentName and a Boolean variable named isAbsent

Which of the following BEST describes the differences between sequential and event-driven programming?

In sequential programming commands run in the order they are written. In event-driven programming some commands run in response to user interactions or other events.

Which line of code in this program is MOST likely to result in an error?

Line 2


Ensembles d'études connexes

Mastering Biology Chapter 6 quiz

View Set

Patho Unit 3 PrepU with Explanations Chapter 27

View Set

Lesson 6 Passive Optical Networks

View Set

Microeconomics True/false Final Exam

View Set

Statistical Terms/Databases and Data Sets- 1

View Set

Ethics ch.7, 8, and 9 Homework Questions

View Set

ECON 2002.01 Macroeconomics Final

View Set