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

  1. 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

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

Idea’algorith- m’write code’execute code’debug’main- tain

  1. 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

  1. 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, wednes- day, 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 am- biguous because the process of "av- erage" is not ex- plained well

  1. 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.

If the last digit of the value found in step 6 is 5, then the sum is odd

Step 1: Using a random number generator, get a value between 1 - 6 inclusively Step 2: Remember that num- ber 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 multiplica- tion by 2

What conclusions can be made with regard to what we are trying to determine? Select two answers:

If the value found in step 6 is 10, 20, 30, 40, 50 or 60 then the sum is even

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

1,

  1. Which of the following is the MOST important reason computers use artificial languages over natural lan- guage?

The syntax of arti- ficial languages is explicit and unam- biguous

  1. Which of the following best describes high-level com- puting languages?

They are not very ambiguous

  1. 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 gen- erates 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

  1. Which of the following describes the part of a comput- er which stores instructions and information which has been input to the computer?

RAM

of error may be oc- curring.

Add statements to display the state of the program at var- ious points to try and identify where the error might have occurred.

  1. 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 ac- cess them at a lat- er point in the pro- gram, Variables al- low you to change a value used in multiple places in a program easily.

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

The program will be easier for oth- ers to debug, The program will be easier to read.

  1. Consider the following algorithm which uses an inte- ger 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

The answer dis- played by the al- gorithm for any known value of n can always be pre- dicted

Which of the following statements best describes the predictability of the results when this algorithm is run on a computer?

  1. 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 under- stand the code since they will know what the variables repre- sent.

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

Use concise names to avoid ty- pos and keep code tidier, Use names which describe what each vari- able represents to make code easier to understand

  1. 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

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

boolean (true/false)

  1. Which is NOT true about comments in programs? All published pro- grams have their comments avail- able.

  2. 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

Pseudocode

displays a fruit that begins with Z.

Use 26 IF blocks formatted similarly to the one above (changing the let- ters of the alpha- bet and fruits).

  1. 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 posi- tion? Select two answers.

line 5 and line 7

  1. 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: }

Changing line 7 to a • 0

Which of the following changes will NOT affect the results when the code segment is executed?

  1. The block of code below is supposed to display "Mul- tiple 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

  1. 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

  1. 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 ro- bot's final position be? MOVE_FORWARD MOVE_FORWARD IF (CAN_MOVE(right)) { ROTATE_RIGHT MOVE_FOR- WARD MOVE_FORWARD } IF (CAN_MOVE(left)) { RO- TATE_LEFT MOVE_FORWARD ROTATE_LEFT }

facing left

  1. 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

  1. 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 2:A variable dice_roll is ran-

odd_counter>

[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?

  1. 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

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

6

  1. 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

  1. What should replace <missing statement> in the fol- lowing 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

  1. 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?

  1. The software for an elevator uses a variable, called lev- el, 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 + ELSE display [cannot go up] DISPLAY "level "+ Level

Level 8 Level 9 Cannot go up. Lev- el 9

  1. 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 meaning- ful names for all variables and pro- cedures.

Include comments detailing the pur- pose and behav- ior of variables and procedures

  1. Which of the following would be the most appropriate name for the following procedure (currently named MYSTERY), where number is any number and the pro- cedure CHECK (number) returns true if the number is an integer and false if not?

PROCEDURE MYSTERY (number)

IS_POS_INT

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?

  1. Under which of the following conditions is it most ben- eficial to use a heuristic approach to solve a problem?

When the prob- lem cannot be ac- curately solved in a reasonable time and an approxi- mate solution is acceptable.

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

The condition of the loop never be- comes false

  1. Which of the following illustrates an aspect of efficien- cy?

execution time memory usage size of program

  1. 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 cir- cuit?

The output will be true if input D is true, and false oth- erwise.

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

The direction of travel for an eleva- tor

  1. 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?

  1. 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 rep- resentation.

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

1001110

  1. Which of the following decimal values, when convert- ed to binary (ignore leading zeros) have exactly 3 zeros in them?

50, 20

  1. 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^

  1. The following steps can be used to encode a string of text using Base64 encoding:
    1. Convert the ASCII characters to their correspond- ing 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

  1. 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 Refer- ence Guide?

The output will be 4

  1. A teacher uses the following program to adjust stu- dent 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)

  1. 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 posi- tion, then the third position and so forth. What type of sorting is this?

selection

  1. 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

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

You have an even amount of items in your list!

68. 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

  1. 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 ele- ments in oldList NOT including any repeats of ele- ments.

  1. A programmer has two lists of random words, list and list2. He has written a program that is intended to create a list, finalList, of all the words found in list 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

finalList, will con- tain all the words found in list1 and list2 in alphabet- ical order, but it may contain re- peated words.

What are two advantages of using well named variables?

Which of the following are benefits of well-named variables? -The program will be easier to read. -The program will be easier for others to debug.

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

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.

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

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 statements best describes the predictability of the results when this algorithm is run on a computer group of answer choices?

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.