ap comp sci test 3

Ace your homework & exams now with Quizwiz!

example of string concatenation

"Hello, my name is" + userName + "!"

Assume that both lists and strings are indexed starting with index 1. The list wordList has the following contents. ["abc", "def", "ghi", "jkl"] Let myWord be the element at index 3 of wordList. Let myChar be the character at index 2 of myWord. What is the value of myChar ?

"h"

Logical Operators:

&&, ||, ! (AND, OR, NOT)

Let n be an integer value. Which of the following expressions evaluates to true if and only if n is a two-digit integer (i.e., in the range from 10 to 99, inclusive)?

(n ≥ 10) AND (n < 100)

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

(num MOD 2) = 1

To qualify for a particular scholarship, a student must have an overall grade point average of 3.0 or above and must have a science grade point average of over 3.2. Let overallGPA represent a student's overall grade point average and let scienceGPA represent the student's science grade point average. Which of the following expressions evaluates to true if the student is eligible for the scholarship and evaluates to false otherwise?

(overallGPA ≥ 3.0) AND (scienceGPA > 3.2)

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

What is displayed as a result of executing the code segment?

21 40 30 50

Which of the following initial values of the variable y would result in the variable z being set to 2 after the code segment is executed?

3

Comparison Operators:

<, >, <=, >=, ==, !=

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

A company delivers packages by truck and would like to minimize the length of the route that each driver must travel in order to reach nn delivery locations. The company is considering two different algorithms for determining delivery routes. Algorithm IGenerate all possible routes, compute their lengths, and then select the shortest possible route. This algorithm does not run in reasonable time.Algorithm IIStarting from an arbitrary delivery location, find the nearest unvisited delivery location. Continue creating the route by selecting the nearest unvisited location until all locations have been visited. This algorithm does not guarantee the shortest possible route and runs in time proportional to n2n2. Which of the following best categorizes algorithm II?

Algorithm II uses a heuristic approach to provide an approximate solution in reasonable time.

Which of the following describes the possible values of ans as a result of executing the code segment?

Any integer value from 7 to 16, inclusive

Assume that the variables alpha and beta each are initialized with a numeric value. Which of the following code segments can be used to interchange the values of alpha and beta using the temporary variable temp ?

I and III only

In the following procedure, assume that the parameter x is an integer. Which of the following best describes the behavior of the procedure?

It displays true if x is negative and displays nothing otherwise.

n the following procedure, the parameter max is a positive integer. PROCEDURE printNums(max) { count ←← 1 REPEAT UNTIL(count > max) { DISPLAY(count) count ←← count + 2 } } Which of the following is the most appropriate documentation to appear with the printNums procedure?

Prints all positive odd integers that are less than or equal to max.

Which of the following is a true statement about program documentation?

Program documentation is useful during initial program development and also when modifications are made to existing programs.

In the following procedure, the parameter numList is a list of numbers and the parameters j and k are integers. PROCEDURE swapListElements(numList, j, k) { newList ←← numList newList[j] ←← numList[k] newList[k] ←← numList[j] RETURN(newList) } Which of the following is the most appropriate documentation to appear with the swapListElements procedure?

Returns a copy of numList with the elements at indices j and k interchanged.The values of j and k must both be between 1 and LENGTH(numList), inclusive.

Consider the following code segment. Which of the following best describes the behavior of the code segment?

The code segment displays the value of 2(53)2(53) by initializing result to 2 and then multiplying result by 5 a total of three times.

A student wrote the following code segment, which displays true if the list myList contains any duplicate values and displays false otherwise. The code segment compares pairs of list elements, setting containsDuplicates to true if any two elements are found to be equal in value. Which of the following best describes the behavior of how pairs of elements are compared?

The code segment iterates through myList, comparing each element to all subsequent elements in the list.

The position of a runner in a race is a type of analog data. The runner's position is tracked using sensors. Which of the following best describes how the position of the runner is represented digitally?

The position of the runner is sampled at regular intervals to approximate the real-word position, and a sequence of bits is used to represent each sample.

Which of the following are benefits of using well-named variables in a computer program?

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

A student is recording a song on her computer. When the recording is finished, she saves a copy on her computer. The student notices that the saved copy is of lower sound quality than the original recording. Which of the following could be a possible explanation for the difference in sound quality?

The song was saved using fewer bits per second than the original song.

The operand for a logical operator is either

a Boolean expression or a single Boolean value.

a/b means

a is divided by b

what is a code statement

a part of program code that express an action to be carried out.

what are comments a form of

a program documentation written into the program to be ready by people and do not affect how a program runs.

the assignment operator allows

a program to change the value represented by a variable.

RANDOM(a,b) generates and returns

a random integer from a to b, inclusive (included). Each result is equally likely to occur. RANDOM(1,3) could return 1, 2, or 3

The evaluation of expressions follows

a set order of operations defined by the programming language.

what is a program often referred to

a software

a expression can consist of

a value, a variable, an operator, or a procedure call that returns a value

what is a program documentation

a written description of the function of code segment, event, procedure, or program and how it was developed.

example of recent variable

a ← 1 b ← a a ← 2 display(b) The output is 1.

a variable is

an abstraction inside a program that can hold a value. Each variable has associated data storage that represents one value at a time, but that value can be list or other collection that in turn contains multiple values.

Other programming languages provide

an abstraction through which the size of representable integers is limited only by the size of the computer's memory. This is the case for the language defined in the AP exam.

what is an event associated with

an action and supplies input data to a program.

A string is

an ordered sequence of characters.

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

how can a program be described

broadly by what it does, or in more detail by both what the program does and how the program statements accomplish this function

Online tools support

collaboration by allowing users are important aspects of the development of computing innovations.

Nested conditional statements consist of

conditional statements within conditional statements.

Some programming languages provide types to represent

data, which are referenced using variables. These types include numbers, Booleans, lists, and strings. numbers: -1, 5, 100, ... Booleans: True or False lists: [-1, 0, 1, 2, ... ] or [apple, pears, bananas, ....] strings: sentences, words or characters

what does programming documentation help with

developing and maintaining correct programs when working individually or collaborative programming environments.

example of assignment operator

dollar = 3 + 1; dollar = 7; Output: dollar is 7

what does using random number generation in a program mean

each execution may produce a different result randomly.

what are sequential statements

execute in the order they appear in the code segment.

What are the values of first and second as a result of executing the code segment?

first = 100, second = 100

what is the behavior of a program

how a program functions during execution and is often described by how a user interacts with it.

Program requirements are needed to

identify appropriate defined inputs for testing

Data values can be stored

in variables, lists of items, or standalone constants and can be passed as input to (or output from) procedures.

what is a program

is a collection of program statements that performs a specific task when run by a computer.

A Boolean value

is either true or false.

a*b means

multiplication

do all programming environments support comments

no

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

Consultation and communication with users are important aspects

of the development of computing innovations.

what is an example of a common model

pair programming

The value stored in a variable will be the most

recent value assigned.

A development process that is iterative requires

refinement and revision based on feedback, testing, or reflection throughout the process.

MOD b, which evaluates to the

remainder when a is divided by b. Assume that a is an integer greater than or equal to 0 and b is an integer greater than 0. 17 MOD 5 evaluates to 2.

The code segment below is intended to swap the values of the variables and using a temporary variable, . Which of the following can be used to replace so that the code segment works as intended?

second <--- temp

A spinner contains 12 regions of equal size. The regions are numbered 1 to 12. Which of the following code segments can be used to simulate the results of spinning the spinner three times and assigns the sum of the values obtained by the three spins to the variable sum ?

sum ←← RANDOM(1, 12) + RANDOM(1, 12) + RANDOM(1, 12)

In the development process

testing uses defined inputs to ensure that an algorithm or program is producing the expected outcomes. Programmers use the results from testing to revise their algorithms or programs.

a ← expression evaluates

the expression and then assigns the result to the variable a.

Using meaningful variable names helps with

the readability of program code and understanding of what values are represented by the variables.

Conditional statements, or "if-statements," affect

the sequential flow of control by executing different statements based on the value of a Boolean expression.

"if": Means

there is a conditional statement that decides what pieces of code to run. The app does something "if" a boolean expression evaluates to true.

"when": Means

there is an onEvent to respond to user input. The app does something "when" the user clicks.

why do common modlels exist

to facilitate collaboration.

Expression are evaluated

to produce a single value.

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

booleans are

true or false

String concatenation joins together

two or more strings end-to-end to make a new string.

an example of a variable is

var petName = Ellie;

how can events be generated

when a key is pressed, a mouse is clicked, a program is started, or by any other defined action that affects the flow of execution.

when is clarity and readability an important consideration

when expressing an algorithm in a programming language.

In event-driven programming how are program statements are executed

when triggered rather than through the sequential flow of control.


Related study sets

- Hist H114 Exam 2.02 Enlightenment, Scientific Revolution, Adam Smith, John Wesley

View Set

Ch. 13 -Key Pediatric Nursing Interventions

View Set

Quiz 6: Iteration and Switch statements

View Set

MSN 377: Ch 26 Workbook Questions

View Set

earth science - earthquakes and earths interior CH 8

View Set

Lecture 16: Nuclear Energy and Radioactive Waste.

View Set

Life Insurance Basics Chapter Quiz

View Set