Computer Science > QUESTIONS & ANSWERS > Computer Science Final. Most Commonly Tested 71 Questions and Answers. (All)
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? 2. 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? 3. 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? 4. 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? 5. 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 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: 6. 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 7. Which of the following is the MOST important reason computers use artificial languages over natural lan- guage? 8. Which of the following best describes high-level com- puting languages? 9. 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? 10. Which of the following describes the part of a comput- er which stores instructions and information which has been input to the computer? 11. Which of the following best describes "compilation" in reference to computer science? 12. Which of the following best describes how a compiled program is run by a computer? 13. Consider the following actions which might be per- formed 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 out- puts 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 imple- ment an algorithm In which order in the development cycle would these actions first appear? 14. 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 strate- gies would be efficient ways to "debug" her code so that it works as intended? 15. Which of the following is a reason for the importance of variables in programming? 16. Which of the following are benefits of well-named variables? Select two answers. 17. 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 Which of the following statements best describes the predictability of the results when this algorithm is run on a computer? 18. Which of the following is a valid reason for giving variables meaningful names in a program? 19. Which of the following describes good practice when naming variables in code? 20. 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) 21. In a flowchart, a typical decision symbol has what type of output? 22. Which is NOT true about comments in programs? 23. 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 24. 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) 25. 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? 26. 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. 27. 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. 28. 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. 29. 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? 30. 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] 31. 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? 32. 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 } 33. 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") } } } 34. 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 ran- domly 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? 35. 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? 36. Consider the given code fragment. Determine the out- put of the program fragment. m • 2 REPEAT UNTIL(m > 500) { DISPLAY(m) m • m + 2 } 37. 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 state- ment in the REPEAT UNTIL block so that the user will be required to enter the correct password of "sword- fish" before they can continue on with the rest of the program. 38. 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? 39. 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? 40. total. 0 count. 1 Repeat Until (count >10) next <--- Input total <--- total +next count <--- count + 1 [average <--- total/10] [display average] 41. repeat (random 1,10) times DISPLAY [HI] 42. 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 } 43. 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? 44. 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 +1 ELSE display [cannot go up] DISPLAY "level "+ Level 45. 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? 46. 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) { IF (number > 0 AND CHECK (number)) { RETURN (true) } RETURN (false) } 47. 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] 48. What must you consider when determining the effi- ciency of an algorithm? Select two choices. 49. 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-trail- er, houses the 256 tubs of ice cream in the refriger- ated 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 collec- tion, 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? 50. Under which of the following conditions is it most ben- eficial to use a heuristic approach to solve a problem? 51. Which of the following will cause an algorithm to fall into an infinite loop? 52. Which of the following illustrates an aspect of efficien- cy? 53. 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? 54. Which of the following can be represented by a single binary digit? 55. Which of the following questions cannot be easily answered using a binary set of answers? 56. Which of the following statements about 32-bit binary values is NOT true? 57. What is the binary equivalent to the decimal number of 78? 58. Which of the following decimal values, when convert- ed to binary (ignore leading zeros) have exactly 3 zeros in them? 59. ASCII is a common format for the representation of characters in writing code. How many characters can be represented in the standard ASCII encoding? 60. 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? 61. 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? 62. 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 citi- zen 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? 63. Daija is creating a budget, and evaluating his pur- chases 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 pur- chaseList. 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 e LENGTH (purchaseList) 3. n > LENGTH (purchaseList) 64. 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. 65. 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? 66. 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? 67. IF [LENGTH (list) MOD 2=0 DISPLAY [MISSING OUTPUT] ELSE DISPLAY [MISSING OUTPUT2] 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? 69. 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? 70. 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 • RemoveDupli- cates (list2) finalList • Join (list1, list 2) finalList • Alpha- betize (finalList) What will be the contents of finalList after running this program? 71. 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 = city- Name) { counter • counter + 1 } } IF (counter = 1) { RETURN false } ELSE { RETURN true } } Which of the following statements about the testing of this procedure is true? [Show More]
Last updated: 2 years ago
Preview 1 out of 18 pages
Buy this document to get the full access instantly
Instant Download Access after purchase
Buy NowInstant download
We Accept:
Can't find what you want? Try our AI powered Search
Connected school, study & course
About the document
Uploaded On
May 10, 2022
Number of pages
18
Written in
This document has been written for:
Uploaded
May 10, 2022
Downloads
0
Views
207
In Scholarfriends, a student can earn by offering help to other student. Students can help other students with materials by upploading their notes and earn money.
We're available through e-mail, Twitter, Facebook, and live chat.
FAQ
Questions? Leave a message!
Copyright © Scholarfriends · High quality services·