ap csp midterm

¡Supera tus tareas y exámenes ahora con Quizwiz!

The code segments for making a Scratch program which simulates a conversation between the user and a sprite on-screen are given below.Which of the following orders is most suitable if the program is to run without errors and produce the most realistic appearing conversation?

5-3-1-4-2

what is the binary number 1001110001 expressed as a decimal number?

625

How many distinct values can be represented with 6 bits of data?

64

what is the value of z at the end of this procedure if x was 20 and y was 2 when the procedure was called?

84

in the program below, x is an integer between 5 and 10 inclusive answer <- 0 repeat x times repeat 4 times answer <- answer + 1 answer <- answer/2 what is the maximum possible value of answer after running the program?

20

What would be the final value of the variable third once the following program is complete?first ← 2second ← 3third ← first * secondsecond ← third - firstfirst ← first + second + thirdthird ← second * first

48

if x<10 missing boolean operator x>0 display true What would be the most appropriate substitute for the missing Boolean Operator if the intentionis to display "True" for only values of x between, but not equal to values of 0 and 10?

AND

Moore's Law describes the rate at which the number of transistors on a single chip doubles over time. Which of the following assumptions CANNOT be inferred as a direct consequence of this rate of doubling?

Five years from now, web pages will require less memory (RAM) than today's webpages.

Which of the following types of languages is optimized for machine processing and may be written and expressed as a series of binary digits (e.g., ones and zeros), making it difficult for humans to read and write?

low-level programming language

the following question uses a robot and a grid of squares. the robot is represented as a triangle, which is initially in the bottom left square of the grid and facing right. n <- 3 repeat 3 times repeat n times move forward rotate left n <- n-1 which of the following shows the location of the robot after running the code segment?

middle facing down

at the end of the code segment below, what will be said for 2 seconds? mississippi one

mixxixxixxi

in order to program a robot to move around within a two-dimensional space, a programmer considers four different designs for defining the robot's behavior. which of the following sets of procedures would be the best design in terms of the readability, efficiency, and flexibility of the resulting program?

move (dir, dist): moves the robot dist spaces in the dir direction, where dist is a number and dir is north, south, east, or west

The list mine is initialized with the values -- green, red, blue, purple, yellow, black -- and the list yours is initialized with the values -- green, red, black, blue. What will be displayed after the following code segment runs?

none of the messages, partway thru an error message is produced and the program terminates

i <- 0 sum <- 0 repeat until i = 4 i <- 1 sum <- sum + 1 i <- i +1 display sum Which of the following best describes the result of running the code segment?

nothing is displayed; the program results in an infinite loop

unit 2

now

which of the following is an important step to take before beginning to write the code for a program?

plan the logic and anticipated input/output of the code

Peter wrote the following code in scratch to make a sprite perform a series of coordinated moves, forming a "dance routine." The code will be used for a competition, and Peter does not want to reveal the moves performed by the sprite in his program. Currently the path taken by the sprite is traced on the screen. Which of the following changes to the code will change this and allow Peter to keep the path taken by his sprite hidden?

removing the pen down block

Tom created the following code segments in Scratch, which are intended to create a short piece of music between them. When the green flag is clicked, each of the three scripts is intended to run in turn, however, due to a mistake in the code, this does not happen. Which of the following changes could Tom make to ensure that all four of the scripts run as intended?

replace the block broadcast sound3 w the block broadcast sound2

The incomplete code displayed below is for a simple "Guess the Number" game in which the user inputs values and is displayed statements about the relationship of their input to a randomly chosen secret number until they correctly input that number. The condition for the first IF block in the code is missing. Based on the intended purpose of the code, which of the following blocks would be most appropriate as the missing condition?

secret number < guess

ounces <- input beverage <- input [if beverage = soda if ounces > 12 display bottle of + beverage else display can of + beverage] [if beverage = coffee if ounces > 16 display grande + beverage else display short + beverage What is displayed if the user enters "16" and then "coffee" when the program runs?

short coffee

as part of the lifecycle of a program, after a computer programmer writes the code, it is then compiled and usually used to create an executable file to be run on the cpu. the code that is run through the compiler is known as what?

source code

Consider constructing an algorithm for a robot that can only perform the following three predefined operations. MOVE_FORWARD ( ): The robot moves one square forward in the direction it is facing ROTATE_LEFT ( ): The robot rotates in place 90 degrees counterclockwise (i.e., makes an in-place left turn) ROTATE_RIGHT ( ): The robot rotates in place 90 degrees clockwise (i.e., makes an in-place right turn) Which of the following algorithms will successfully cause the robot to trace out a square-shaped path, with the robot ending up in its original position and facing in its original direction?

step 1: move forward step 2: rotate left step 3: move forward step 4: rotate left step 5: move forward step 6: rotate left step 7: move forward step 8: rotate left

Which of the following is not true about digitizing physical media?

The digital version is always equally as good as the physical one in terms of quality.

Refer to the following code segment:The procedure check is supposed to display a statement correctly comparing the size of the two provided numbers, value1 and value2. Which of the following changes to the code would be the best choice to make the procedure work as intended?

add another if/else block, nested in the else section

Consider the goal of finding the sum of all odd integers in a list, myInts, of integers. What should replace <block of statements> to successfully find the sum of all odd integers? sum <- 0 for each num in myints block of statements

if (not (num mod 2 =. 0)) sum <- sum + num

Which of the following CollegeBoard AP Computer Science Principles Pseudocodecommands is used to record something typed by a user of the program so that it can be used inthe program?

input ()

The volume of a rectangular prism is calculated by multiplying its length (l), width (w) andheight (h). What could be substituted into the section of the code below marked < missing code> that would accurately calculate the volume based on the user input of l, w and h? l <- input w <- input h <-input volume <- <missing code> display volume

l * w * h

A large office building has an elevator that carries occupants between any of the building's 10 floors. The basement is referred to as "Level 0" while the topmost floor is "Level 9." The software for the elevator uses a variable, called level, to track the floor number of the elevator's current position. When a person presses a button requesting the elevator to rise to a higher floor, the above code is executed. repeat floors times if level < 9 level <- level + 1 else display cannot go up display level + level What is displayed if the elevator is currently on the 7​th ​floor (level = 7) and the person on the elevator presses a button labeled "up 3 floors" which causes the variable floors to be set to 3.What will be displayed when the code above runs?

level 8 level 9 cannot go up. level 9

The procedure Max(list) is used to find the maximum number in list and display that number. See the procedure below: procedure max(list) maximum <- 0 for each number in list if (number > maximum) maximum <- number display maximum which of the following list assignments will demonstrate that the procedure does not work as intended. select two answers

list ← [ ] , list ← [-5, -3, -10, -8, -1]

{display[random(random 0, 10), random 15, 25]} which two of the following values are more likely to be displayed than the other two values listed when the this block code is run? select two answers

12 14

Sally notices that she has the same set of 10 blocks in her code in multiple places. She decides to create a new block (procedure) in Scratch so that she can simply replace those 10 blocks with one procedure. Which of the following gives the best ways in which this could be beneficial to Sally when she debugs and reasons through her program? Select two answers.

(A) The procedure can make the code section more abstract, so she doesn't have to think through all 10 blocks each time she comes across them in her code. (C) If there is an error in the procedure, she can fix the error in the procedure

Inspired by a tip-calculating mobile application that she made in the classroom, a student decides to create a program that uses percentages. She notices on a social media website that there is much debate over a proposed local sales tax increase. She decided to create a calculator into which users will be able to input the amounts they spend on various items, and which will output the current tax, and the proposed future tax on those items in dollars. The app will tell the user how much more the goods will cost with the new tax than the old tax. One of the procedures in her program, which finds the difference between the old and new tax, is listed below. what is returned by a call to taxman (food, 1.00)

.06

assuming that the list favorite songs is initially empty, and the user responds to each request for input, how many items will the list favorite songs contain after the program is run?

10

Sam's password is known to be formed of 3 decimal digits (0-9) in a given order. Karren and Larry are attempting to determine Sam's password by testing all possible combinations. If they are only able to try 10 combinations every day, how many days would it take to try all the possible combinations?

100

A large company uses 10-bit binary numbers to identify its employee records. It plans to change this system to use 12-bit binary numbers instead. Which of the following statements best describes the effects of this change?

4 times the number of individual records can potentially be stored

Which of the following decimal (base-10) values is equivalent to the binary (base-2) value 101001?

41

which of the following base-10 values is equivalent to the binary base-2 value 101001?

41

A <- input B <- input C <- input if A < 0 and B>= 0 and c= 0 display invalid input What values, when inputted by the user, of A, B, and C will cause the code to display"​Invalid Input​"?

A = -5 B= 0 C = 0

Which of the following scenarios will likely result in an overflow error?

A program which stores positive integers using 4 bits attempts to add the (decimal) integers 7 and 9.

Which of the following best represent examples of abstraction?Select two answers.

A set of crochet instructions describes in full how to complete a certain type of named stitch at the start. Throughout the rest of the instructions, the stitch is referred to by its name without the full instructions being repeated. A single command in a high-level programming language actually requires the CPU to perform multiple different operations, each of which would be represented by a different command in machine code.

The following two algorithms are designed to find the number of integers on a list which have a value greater than 5.Algorithm I:Create a variable count and set this to zero. For each value on the list, check whether it is greater than 5. If it is, then add 1 to the value of count. When the end of the list is reached display the value of count.Algorithm II:Create a variable count and set this to the number of items on the list. For each value on the list, check whether it is smaller than 5. If it is, then subtract 1 from the value of count. When the end of the list is reached display the value of count.Which of the following statements correctly demonstrates that the two algorithms are NOT equivalent?

Algorithm I will correctly display the number of integers greater than 5 on the list [4, 10, 5, 1], but Algorithm II will not.

Using the table given below convert the binary number 01000011 01010011 00100000 01010010 01101111 01100011 01101011 01110011 00100001 to ASCII characters.

CS Rocks!

Remember that "state space" refers to the space of all potential possibilities. Which dichotomous questions below will successfully narrow down the entire state space of "flipping a coin and rolling a normal six-sided die" to 1 or fewer possible outcomes regardless of the answers given?

Did the coin land on heads?Is the value on the die odd?Is the value on the die more than 3?Does the value on the die equal 1, 2, 5 or 6?

Consider the following procedure. procedure find (target, list) i <- 1 for each item in lift if (item = target) display i i <- i + 1

Displays the positions of all occurrences of target in list

A particular problem is currently not able to be practically solved by using an algorithm.Which of the following statements about the problem could possibly be true? I. no algorithm has yet been developed which would solve this problem, but it is possible one may be developed in the future II. an algorithm has been developed which would solve this problem but technology is not yet available which would compute this algorithm fast enough to be practicable. III. it is impossible to develop an algorithm which would solve this problem.

I, II, III

students were asked to order a list of the seven days of a week, without a specification as to the rules of the ordering. which of the dollowing ordered lists may be considered correctly ordered? I. m,tu,w,th,f,sa,su II. th,f,sa,su,m,tu,w III. f,m,sa,su,th,tu,w

I,II,III (no rules)

From the following blocks, a code segment can be formed which will swap the values of the variables a and b.Which of the following gives a correct, ordered set of instructions which will create a code segment swapping the initial values of a and b?

IV, I, II

The following code segment is intended to display the difference in the sums of two non-empty lists of integers, list1 and list2.Which of the following changes will reduce the number of operations performed by the program without making it incorrect?

Interchanging line 11 and line 12

The program below is intended to find and display the total when all the unique numbers on the list of integers numbers are summed (e.g. if a list contains a number twice it will only be added to the total once).The program makes use of a procedure named IsFirstOccurence. Which of the following definitions of this procedure would cause the program to function as intended?

PROCEDURE IsFirstOccurence(list,pos) {index ← 1 REPEAT UNTIL (index = pos) {IF (list [index] = list [pos]) {RETURN (false) }index ← index + 1} RETURN (true)}

ASCII is a character-encoding scheme that uses a numeric value to represent each character. For example, the uppercase letter "G" is represented by the decimal (base 10) value 71. A partial list of characters and their corresponding ASCII values are shown in the table below.ASCII characters can also be represented by binary numbers. According to ASCII character encoding, which of the following letters is represented by the binary (base 2) number 1010100?

T

if the ascII chart were continued, what letter would be represented by 84?

T

Frankie is considering whether to use a binary or linear search in her program to find a value in a sorted list. When she tests the algorithms on selection of short lists of fixed-length lists she finds that the binary search is faster on average than the linear search. Another programmer suggests she tests both algorithms on a selection of lists which are 10 times as long as her original test lists. Which of the following best describes the likely results of this test?

The binary search will still be faster on average than the linear search, and the difference in run times between the two searches will be significantly more than 10 times greater than for the shorter lists.

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

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.

Consider the following code segment which makes use of the list deck and the positive integer i:Which of the following could be displayed when this segment of code is executed, assuming that the block will sort the parameter list in alphabetical order from A to Z, and the user responds to each input?

Tim Tim Tim

Lists are widely used in programming, however, lists are not necessary for all programming tasks. In which of the following situations would you be least likely to need to use a list in a program?

Tracking the last song that played in a game, so that people playing the game don't hear the same song twice in a row

The program below was designed to find the smallest positive item in a list of integers but contains a crucial error. min <- list 1 for each num in list if num < min and num >0 min <- num display min which of the following lists will cause the program to give an incorrect output?

[-1,1,4,0]

For her 4th of July weather report, a local meteorologist wishes to predict the likelihood of the scheduled fireworks show being rained out by analyzing the most recent weather trends in the local vicinity. Which of the following sources of data would be the most appropriate for helping her make the prediction?

a list of floating point values representing the daily rainfall totals for the previous 10 days (june 24 through july 3)

Cardel is using Java to write a SaaS program for an educational technology company. He chooses to keep his code private and to protect his work from imitation but may wish to modify or update the code in the future. Which of the following will be most likely to make it easier for him to edit his code in the future?Select two answers.

adequate and appropriate comments naming conventions

Many tasks, large and small, can be solved by performing a specific set of actions and making a particular set of decisions in very precise ways. These sets of actions and decisions are known as what?

algorithms

which of the following could be considered part of the beginning "state" of a scratch program?

all of the options (value of variable, visibility of sprites, background image)

which of the following algorithms require both selection and iteration? select two answers

an algorithm that, given a list of integers, displays only the negative integers in the list an algorithm that, given a list of integers, displays the number of even integers in the list

What list will be displayed when the following code segment is run?

banana, banana, apple, banana, grape, kiwi, orange

if ontime display hello else if absent display is anyone there? else display better late than never If the variables onTime and absent both have the value false, what is displayed as a result ofrunning the code segment

better late than never

Which of the following is an advantage that block-based programming languages (e.g. Scratch) have over text-based programming languages (e.g. Processing)?

block-based programming languages do not require the programmer to worry about syntax, capitalization, or punctuation

Imagine you are programming a simple calculator using Scratch and you want to create a feature which adds a fixed number to an existing variable named "balance". Which of the blocks below will be the most appropriate to use for this feature?

change balance by

Two students are trying to combine their decks of Pokémon cards so that they make one large deck of cards that contains exactly one of each unique type of Pokémon card that they own - in alphabetical order. In order to do this, the students start with two lists, deck1 and deck2, which are lists of all Pokémon cards each student owns (duplicates included) and the following available procedures.

combinedDeck ← Add(deck1, deck2) combinedDeck ← RemoveDups(combinedDeck) combinedDeck ← Alphabetize(combinedDeck)

the procedure prime returns a value of prime if number (a positive integer) is prime and returns not prime if otherwise assuming number must be larger than 1, what must go in the missing code section to make this procedure work as expected?

count = 2

Subana is writing a program which will calculate the mean average of a set of numbers by adding the numbers and dividing the result by the amount of numbers. She will use a variable, avg, to store this average. Which variable type would be most suitable for avg?

floating point (float)

An entrepreneur has hired a programmer to design software to take user input and convert it to appear a certain way. The programmer is not clear on the assignment, so he asks the entrepreneur to elaborate. Which of the following would be most helpful for the programmer to ask the entrepreneur to do to make the assignment clearer?

give some examples of user input and what the result should look like

Given the following code segment, what would be displayed if age were initialized with avalue of 18? if age <18 or age >= 65 display group 1 else display group 2

group 2

which of the following statements about high-level programming languages when compared to low-level programming languages is true?

high-level programming languages provide programmers w more abstractions and are easier for ppl to read

A group of high school students is participating in a mobile application development contest. They have a limited time frame and would like to add many features. Which of the following strategies will allow them to create the best app they can in the time allotted?Strategy I:The students outline all goals. They make a program with all procedure names. They use software to simultaneously work on different parts of the code, frequently compiling and testing all code together. As each individual student completes one procedure, that student moves onto the next procedure.Strategy II:The students outline all goals. They work together on some shared code, and students work with their own copies of the code on specific parts. They check in regularly and completed, correct code is added to a master program. Strategy II only

strategy II only

a gaming software company gave their new customers a survey, asking them to rate various aspects of a new product on a scale of 1 to 5. the integer values of their answers were stored in a list feedback. which code segments would assign the mean average value of the items on the list to the variable average? select 2

sum <- 0 for each item in feedback sum <-sum + item average <- sum/length feedback sum <-0 item <-1 repeat length feedback times sum <- sum + feedback item item <- item + 1 average <-sum / length feedback

subtract 1 from the current value of y and store the answer as the new value of y set the value of x to the current value of y + 1 set the value of x to the current value of y repeat steps 1 to 3 until x = 10 which of the following best describes the behavior of this algorithm based on the starting values of the variables x and y?

there are many possible starting values for x and y which will cause the algorithm to eventually terminate, and many possible starting values for x and y which will cause the algorithm to run indefinitely

Joanna wishes to create a variable in her Scratch game which records the number of seconds until the game ends. Which of the following would be the most appropriate name for this variable?

time left

The elements of the list "months" are given below:What is the output of the following block? (Hint: think about case sensitivity.)

true

Below is the International Morse Code, where each letter is made up of a unique combination of dots and dashes.This code is an example of what type of encoding?

variable width

which of the following could be represented by a boolean variable?

whether a guest at a wedding is allergic to peanuts (t/f)

which of the following cannot be represented by a single binary digit?

which color is currently being shown by a traffic light

x <- input y <- input [if x = 0 or y <= 0 display right else display wrong] [if y > 0 and x = 0 display right else display wrong] which of the following best describes the conditions which must be satisfied by the user-inputted values of x and y if the program is to display right right when run?

x must be 0 and y must be a positive number


Conjuntos de estudio relacionados

Chapter 10: Mainstream Rock, Punk, and New Wave

View Set

Chapter 32 pre, post and Chapter test

View Set

Infant and Child Development EXAM 1

View Set

P.E. B Test 4- Conflict Management 2

View Set

Chapter 7: Written Communications

View Set

Chapter 40 Hematology and Blood Transfusions

View Set