AP CSP Computer Science final

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Which of the following is the MOST important reason computers use artificial languages over natural language?

The syntax of artificial languages is explicit and unambiguous

repeat (random 1,10) times DISPLAY [HI]

The word HI could be displayed 1, 2, 3, 4, 5, 6, 7, 8, 9, or 10 times

Which of the following best describes high-level computing languages?

They are not very ambiguous

The block of code below is supposed to display "Multiple of 5" if the positive number value is in fact a multiple of 5. If(missing condition) display [multiple of 5] else display [incorrect]

(value MOD 5) = 0

x ← 0 a ← 3 k ← 4 REPEAT a TIMES { REPEAT k TIMES { x ← x + a } x ← x * (-1) } DISPLAY x When the code above is run, what will be the final value of the variable x, displayed at the end of the program?

-12

Consider the following code: REPEAT UNTIL (x mod 2 = 1) { x ← x + 3 } Assume that x is initially 6. How many times will the loop iterate?

1

Which of the following should be true of any algorithm? I. The order in which the steps making up the algorithm are followed is logically determined II. Following the instructions in the algorithm will always result in the same outputs, regardless of any inputs III. The instructions in the algorithm contain all necessary information to be implemented

1,3

What is the binary equivalent to the decimal number of 78?

1001110

ASCII is a common format for the representation of characters in writing code. How many characters can be represented in the standard ASCII encoding?

2^7

Daija is creating a budget, and evaluating his purchases over the last month. Consider the following code segment which attempts to find the sum of all purchases made in the last month, stored in purchaseList. n ← 1 sum ← 0 REPEAT UNTIL (<missing code>) { sum ← sum + purchaseList[n] n ← n + 1 } What code can replace missing code to assign the total of all values in purchaseList to sum? 1. n = LENGTH (purchaseList) 2 .n ≥ LENGTH (purchaseList) 3. n > LENGTH (purchaseList)

3

Consider the following actions which might be performed by a developer when creating a new piece of software to solve a problem. 1. Thoroughly testing code with a variety of inputs 2. Designing an algorithm to tackle the central problem the program hopes to solve3. Considering what outputs a program solving the problem might produce and what inputs it may require to do this4. Writing code in a high-level programming language to implement an algorithm In which order in the development cycle would these actions first appear?

3, 2, 4, 1

The following steps can be used to encode a string of text using Base64 encoding: 1. Convert the ASCII characters to their corresponding decimal value2. Convert the decimal values to their 8-bit equivalents3. Join all of the bits together to form one continuous string4. Split the combined string into groups of 6 bits5. From left to right, convert each group of 6 bits to their corresponding decimal values6. Convert those decimal values back to the corresponding Base64 values If I started with the three ASCII characters "CSP", how many Base64 values will I be left with at the end?

4

Which of the following decimal values, when converted to binary (ignore leading zeros) have exactly 3 zeros in them?

50, 20

total. 0 count. 1 Repeat Until (count >10) next <--- Input total <--- total +next count <--- count + 1 [average <--- total/10] [display average]

6

Consider the given code using variables a, b, and c. What will be the output of this code? a ← 2 b ← 6 c ← 12 a ← b b ← c DISPLAY(a) DISPLAY(c)

6 12

Which of the following is a valid reason for giving variables meaningful names in a program?

A programmer will find it easier to read and understand the code since they will know what the variables represent.

Consider the given code fragment. Determine the output of the program fragment. m ← 2 REPEAT UNTIL(m > 500) { DISPLAY(m) m ← m + 2 }

All even numbers 2 4 6 8 ... 500

Which is NOT true about comments in programs?

All published programs have their comments available.

Which of the following statements about 32-bit binary values is NOT true?

All real numbers within a finite interval can be expressed by a 32-bit integer representation.

The code segment below uses the procedure IsPartOf (list, item), which returns true if item appears in list and returns false otherwise. The list newList is initially empty. FOR EACH item IN oldList { IF (NOT IsPartOf (newList, item)) { APPEND (newList, item) } } Which of the following best describes the contents of newList after the code segment is executed?

All unique elements in oldList NOT including any repeats of elements.

The procedure below is intended to return true if a particular city name (cityName) appears more than once in a list of cities (cityList), and false if it does not appear, or only appears once in the list. PROCEDURE CityRepeat (cityList, cityName) { counter ← 0 FOR EACH city IN cityList { IF (city = cityName) { counter ← counter + 1 } } IF (counter = 1) { RETURN false } ELSE { RETURN true } } Which of the following statements about the testing of this procedure is true?

Calling the procedure CityRepeat (["New York", "Los Angeles" "New York", "Chicago"], "Boston") shows that the procedure does not work as intended in this case.

Consider the code segment below. Line 1: IF (b ≠ 0) Line 2: { Line 3: a ← a/b Line 4: } Line 5: ELSE Line 6: { Line 7: a ← a*b Line 8: } Which of the following changes will NOT affect the results when the code segment is executed?

Changing line 7 to a ← 0

A team of students is collaborating on a program to obtain local weather data from a website, and predict weather-related school closings based on their own formulas. They must present their code to a group of faculty, some of whom have little to no experience with code. What strategies can the group use while writing their code, in order to make it more understandable for the faculty?

Choose meaningful names for all variables and procedures. Include comments detailing the purpose and behavior of variables and procedures

Which of the following best describes "compilation" in reference to computer science?

Code in a high-level language is converted to low-level instructions which can be interpreted and run by the CPU.

The county clerk's office is writing a program to search their database for citizen records based on information about that citizen such as first name, last name, age, etc. Given below is a segment of pseudocode that should find the record of every citizen over the age of 50 in the county. The code makes use of the functions GetAgeOf and GetNameOf, which are used to retrieve the age and name of a citizen from a record which is inputted. FOR EACH person IN citzlist { age = GetAgeOf(person) name = GetNameOf(person) IF(age < 50) { DISPLAY(name) } There is a mistake in this pseudocode. Which of the following is the correct pseudocode to find the records of all citizens over the age of 50?

FOR EACH person IN citzlist { age = GetAgeOf(person) name = GetNameOf(person) IF(age > 50) { DISPLAY(name) } }

Jeremiah is part of a group planning a summer fair at which local businesses can run stalls and events. He wants to use his programming skills to develop an app for the fair which businesses will be able to use to communicate information about their activities at the fair with visitors. Which of the following would be the best first step for Jeremiah to take?

Find out from the businesses and potential visitors what information and format they think should be used for the app

Which of the following would be the most appropriate name for the following procedure (currently named MYSTERY), where number is any number and the procedure CHECK (number) returns true if the number is an integer and false if not? PROCEDURE MYSTERY (number) { IF (number > 0 AND CHECK (number)) { RETURN (true) } RETURN (false) }

IS_POS_INT

Understanding of the life cycle of a program is an essential component to becoming an effective programmer. Which of the following is the best example of how the life cycle of a program should work?

Idea→algorithm→write code→execute code→debug→maintain

The algorithm below simulates rolling a regular 6-sided die twice. Consider the goal of determining if the sum of the values of the two rolls is odd or even. Step 1: Using a random number generator, get a value between 1 - 6 inclusively Step 2: Remember that number Step 3: Repeat steps 1 and 2 Step 4: Add the two remembered numbers together Step 5: Multiply that sum by 10 Step 6: Divide the result of that multiplication by 2 What conclusions can be made with regard to what we are trying to determine? Select two answers:

If the last digit of the value found in step 6 is 5, then the sum is odd If the value found in step 6 is 10, 20, 30, 40, 50 or 60 then the sum is even

In a flowchart, a typical decision symbol has what type of output?

boolean (true/false)

Consider the following two implementations of the same algorithm, each written in a different language. Language A:Calculate the average daily rainfall for the week (averageRainfall) by adding together the rainfall totals for each of the 7 days of the week (sun, mon, tue, wed, thu, fri, and sat) and dividing the sum by 7. Language B:Take the total amount of rain from each day of the week (sunday, monday, tuesday, wednesday, thursday, friday and saturday) and then average them together to get the average daily rainfall for the week (averageRainfall). Which of the following statements about these two implementations is true?

Language B is ambiguous because the process of "average" is not explained well

The software for an elevator uses a variable, called level, to track the floor number of the elevator's current position. When a person presses a button indicating that the elevator should rise to a higher floor, the following goUp procedure is invoked with the desired number of floors to climb provided as a parameter. Procedure goUP {floors} Repeat Floors times IF [level < 9] level <--- level +1 ELSE display [cannot go up] DISPLAY "level "+ Level

Level 8 Level 9 Cannot go up. Level 9

Elsa and her friend Olaf are co-owners of the world's largest ice cream truck, offering their customers the choice of 256 different flavors of ice cream. The truck, which has been built from an 18-wheeled tractor-trailer, houses the 256 tubs of ice cream in the refrigerated trailer. The side of the truck displays a large list of the 256 names of the different flavors, which the customers then name when they place their orders. Business is booming and the duo needs to serve their customers quickly. However, in order to quickly find the right tub of ice cream out of such a large collection, Elsa and Olaf both agree that they need to use an efficient solution. Elsa suggests that they organize the flavors alphabetically while Olaf suggests that they organize the flavors in order from his favorite to his least favorite. Which of the following solutions would allow these ice cream peddlers to find the customers' chosen flavors the most efficiently?

Organize the tubs alphabetically by flavor name and use a binary search algorithm to find the customer's requested flavor.

Which of the following best describes the type of language used in the below algorithm? Prompt user for number if number is greater than or equal to 0 Output "Positive" else Output "Negative" Repeat 4 times

Pseudocode

Which of the following describes the part of a computer which stores instructions and information which has been input to the computer?

RAM

A statistics teacher wishes to create a program on her calculator that generates a random even integer. The command built in the calculator to generate a random positive integer is RANDOM(a,b). This command generates a random integer between integers a and b (and including a and b). Which of the following lines of code will ensure that the random integer generated will be even?

RANDOM(a,b) * 2

Consider the following code: n ← 4 x ← -2.5 IF(n < 3) { DISPLAY("Team A") } ELSE { IF(n < 2) { DISPLAY("Team B") } ELSE { IF(x > -2) { DISPLAY("Team C") } ELSE { DISPLAY("Team D") } } } Which of the following is the output of the code?

Team D

A program is used to print name tags for guests at an event. Unfortunately for each guest it prints the last name before the first name when the opposite is desired. The procedure for printing the name tags uses the variables FN for the first name and LN for last name. Which of the following code segments, inserted in the correct place in the procedure will cause the program to print the name tags in the desired way?

Temp ← LN LN ← FN FN ← Temp

What must you consider when determining the efficiency of an algorithm? Select two choices.

The amount of resources, such as storage, required The length of time required to run the program

Consider the following algorithm which uses an integer variable n. Double the value of n Add 34 to the answer Round the answer to the nearest ten Sum the digits of the answer Display the final answer Which of the following statements best describes the predictability of the results when this algorithm is run on a computer?

The answer displayed by the algorithm for any known value of n can always be predicted

Which of the following best describes how a compiled program is run by a computer?

The binary instructions from the program are loaded into RAM. The CPU reads and executes instructions, storing and accessing data from RAM as needed.

Which of the following are benefits of well-named variables? Select two answers.

The program will be easier for others to debug, The program will be easier to read.

Which of the following will cause an algorithm to fall into an infinite loop?

The condition of the loop never becomes false

Which of the following can be represented by a single binary digit?

The direction of travel for an elevator

If our list called List is populated as [0, 1, 2, 3, 4], what happens if our code tries to access List [5] per the rules of the AP Computer Science Principles Reference Guide?

The output will be 4

The diagram below shows a circuit composed of three logic gates labeled OR and AND. Each gate takes two inputs and produces a single output. A B C D I. I. I. I OR AND I I AND I OUTPUT If inputs B and C are both true, which of the following best describes the final output produced by the circuit?

The output will be true if input D is true, and false otherwise.

Tamara is writing code as part of a large project. She has just compiled her code and run it, but the result is not exactly as expected. Which of the following strategies would be efficient ways to "debug" her code so that it works as intended?

Try changing some of the inputs to see under what circumstances the program is not working and what type of error may be occurring. Add statements to display the state of the program at various points to try and identify where the error might have occurred.

A student developed a program that outputs the name of a fruit that begins with a letter, dependent upon the variable keyPressed, which stores the letter (from A to Z only) a user types on the keyboard. Below is a section of code from her program: Which of the following descriptions below would be a way that this student might have written the rest of her code so that it executes as intended? Select two answers.

Use 25 nested IF/ELSE blocks where the IF portion is formatted like the code segment above (changing the letters of the alphabet and fruits) and the else simply holding the next IF portion until the last ELSE, which displays a fruit that begins with Z. Use 26 IF blocks formatted similarly to the one above (changing the letters of the alphabet and fruits).

Which of the following describes good practice when naming variables in code?

Use concise names to avoid typos and keep code tidier, Use names which describe what each variable represents to make code easier to understand

Which of the following is a reason for the importance of variables in programming?

Variables assist in making code more readable, Variables allow you to store values calculated by the program and access them at a later point in the program, Variables allow you to change a value used in multiple places in a program easily.

Under which of the following conditions is it most beneficial to use a heuristic approach to solve a problem?

When the problem cannot be accurately solved in a reasonable time and an approximate solution is acceptable.

Which of the following questions cannot be easily answered using a binary set of answers?

Which is the best song new song from last year?

IF [LENGTH (list) MOD 2=0 DISPLAY [MISSING OUTPUT] ELSE DISPLAY [MISSING OUTPUT2]

You have an even amount of items in your list!

What should replace <missing statement> in the following code be if we want this code to repeat until the variable a is greater than 10? a ← 0 REPEAT UNTIL (<missing statement>) { a ← a + 1 }

a > 10

A program that Thomas has written is complete. It has been tested thoroughly, and some outputs were not as expected. Thomas is now going through the code carefully attempting to establish the cause of these errors and change the code to remove them. What is this procedure called?

debugging

Which of the following illustrates an aspect of efficiency?

execution time memory usage size of program

This question references a robot in a grid of squares. The robot is represented by the triangle in the bottom left-hand corner and is facing toward the top. Based on the following program, what would the robot's final position be? MOVE_FORWARD MOVE_FORWARD IF (CAN_MOVE(right)) { ROTATE_RIGHT MOVE_FORWARD MOVE_FORWARD } IF (CAN_MOVE(left)) { ROTATE_LEFT MOVE_FORWARD ROTATE_LEFT }

facing left

A programmer has two lists of random words, list1 and list2. He has written a program that is intended to create a list, finalList, of all the words found in list1 and list2 in alphabetical order with no repeated words. His program makes use of the following procedures: Alphabetize(list) Returns a list that contains the elements of list in alphabetical order. Join (list 1, list2) Returns a list with the elements of list1 followed by the elements of list2 RemoveDuplicates (list) Returns a list with the same elements in the same order as list, but with any duplicate elements removed. The programmer's program is as follows: list1 ← RemoveDuplicates (list1) list2 ← RemoveDuplicates (list2) finalList ← Join (list1, list 2) finalList ← Alphabetize (finalList) What will be the contents of finalList after running this program?

finalList, will contain all the words found in list1 and list2 in alphabetical order, but it may contain repeated words.

A teacher uses the following program to adjust student grades on an assignment by adding 5 points to each student's original grade. However, if adding 5 points to a student's original grade causes the grade to exceed 100 points, the student will receive the maximum possible score of 100 points. The students' original grades are stored in the list gradeList, which is indexed from 1 to n. i ← 1 REPEAT n TIMES { i ← i + 1 } The teacher has the following procedures available. min (a, b): Returns the lesser of the two values a and b max (a, b): Returns the greater of the two values a and b Which of the following code segments can replace so that the program works as intended? Select two answers.

gradeList [i] ← gradeList[i] + 5 IF (gradeList [i] > 100) { gradeList [i] ← 100 } gradeList [i] ← min (gradeList[i] + 5, 100)

Below is a block of code intended to navigate a robot through a grid of squares. Repeat Until (can_move [right] move_forward [rotate_right] [move_forward] For which of the following grids will the code correctly navigate the robot to a final destination of the grey square and then terminate?

grey box in upper corner

Consider a robot that is initially facing north in a 5-by-5 grid, as shown in the diagram below. A program segment has been written to move the robot to the upper-right corner where it should face west. Starting Position of Robot (facing north) Ending Position of Robot (facing west) The following program segment is intended to move a robot from the starting position to the ending position as shown above. However, the program segment does not work correctly. Line 1: MOVE_FORWARD () Line 2: MOVE_FORWARD () Line 3: IF(CAN_MOVE (right)) Line 4: { Line 5: MOVE_FORWARD () Line 6: MOVE_FORWARD () Line 7: ROTATE_RIGHT () Line 8: } Line 9: ROTATE_LEFT () Line 10: ROTATE_LEFT () Which 2 lines of code in the segment above must be switched in order for the program to correctly move a robot from the starting position to the ending position? Select two answers.

line 5 and line 7

What is displayed as a result of running the following program? a ← 6 b ← 11 IF (a = b) { DISPLAY ("January") } ELSE { IF (a > b) { DISPLAY ("February") } ELSE { IF (a > 0) { DISPLAY ("March") } ELSE { DISPLAY ("April") } } }

march

GROCER <---MILK EGGS CHEESE answer<--- yes Repeat Until (awnser=/ yes) DISPLAY [ ADD AN ITEM] item <--- input insert [grocery,2,item] DISPLAY [add an item?' answer <---- input While running this code segment, the user enters the following values when prompted: pizza yes bread no. What is stored in the list called grocery after the block of code is executed?

milk, bread, pizza, eggs, cheese

This is a section of code taken from a larger program. What outputs would be the best choice to substitute in for "missing output 1" and "missing output 2", based on the condition?

missing output 1: value does not equal 4 missing output 2: value is equal to 4

The figure below uses a robot in a grid of squares. The robot is represented as a triangle, which is initially in the bottom white square and facing up. The goal is to move the triangle to the gray square. MoveTurn [moves,turns] Repeat Moves TIMES [move forward] Repeat turns TIMES [rotate right]

moveTurn 1,3 move turn 2,1 moveturn 2,0

Using the flowchart below, what value when entered for Y will generate a mathematical error and prevent our flowchart from being completely executed? (just know how to use a flow chart)

none of these

The algorithm below is used to simulate the results of rolling a standard 6-sided die 5 times. Consider the goal of determining whether the simulation resulted in more results which were odd than results which were even. Step 1:Initialize the variables odd_counter and roll_counter to 0.Step 2:A variable dice_roll is randomly assigned an integer value between 1 and 6 inclusive. If dice_roll has a value of 1, 3 or 5, then odd_counter is incremented by 1.Step 3:Increment the value of roll_counter by 1.Step 4:Repeat steps 2 and 3 until roll_counter equals 5. Following the execution of the algorithm, which of the following expressions indicates that the simulation resulted in more results which were odd than results which were even?

odd_counter>2

1 integer ← 22 2 lowtemp ← 0 3 4 IF(integer < 10) 5 { 6 lowtemp ← lowtemp - 5 7 } 8 ELSE 9 { 10 lowtemp ← lowtemp + 10 11 } 12 13 DISPLAY(lowtemp) What is the best description of the structure implied by line 4?

selection

Sometimes we care about the order of a list, and need to reorder the items according to a condition (alphabetical, numerical, etc). An algorithm finds the minimum value in the list and swaps it with the value in the first position, then repeats these steps for the remainder of the list, swapping with the second position, then the third position and so forth. What type of sorting is this?

selection

Sam and Emma are creating a multiplayer tic-tac-toe game. Below is a segment of their code that is used so that the Sprite on screen can tell the user whose turn it is. Before each user's turn, this set of code is run. What would condition 1 need to be so that this part of the program runs correctly? The variable turn is initialized as 0 at the start and player 1 always goes first.

turn MOD 2 = 1

Consider the following code segment that appears in the middle of a program. display [what is the password?] EnterPassword<-- input Repeat Until (missing statement) display[invalid, try again] userPassword <--- Input Which of the following can replace the missing statement in the REPEAT UNTIL block so that the user will be required to enter the correct password of "swordfish" before they can continue on with the rest of the program.

userPassword = "swordfish"


Set pelajaran terkait

Intro to Physical Fitness Wellness Online Exam

View Set

English 12B Unit 3: Goodbye to Romance (The Enlightenment/Neoclassic, 1660-1798, & Romantic Period, 1798-1837)

View Set

Chapter 3: policy riders, provisions, options, and exclusions ( quiz material)

View Set

Chapter 9: Leading People and Organizations

View Set