Quizlet Fall study exam
Which of the following could be represented by a boolean variable? (A) Whether a pair of headphones is plugged into a specific port (B) The name of an item on a menu (C) Whether a number is positive, negative or zero. (D) The number of appointments a dentist has in a given week.
(A) This can be represented as a boolean since there are only two possible values which it can take: these can be represented as true and false. Choice B is incorrect because this variable could take many different possible values, and a boolean can only store 2 different possible values (e.g. true/false). Choice A is incorrect because this variable could take 3 different possible values (positive, negative or zero), and a boolean can only store 2 different possible values (e.g. true/false). Choice D is incorrect because this variable could take many different possible values, and a boolean can only store 2 different possible values (e.g. true/false).
Which of the following would not be considered an example of abstraction? (A) A football coach uses a named "play" to refer to a complex set of actions performed by players on her team. (B) A programmer stores a long message using a String variable called message1. Whenever the long message needs to be accessed, it is referred to in the code by message1. (C) A programmer renames all the variables in their program to make it shorter. (D) A robot can be programmed with the command MOVE_FORWARD, which causes a motor and several sensors to perform a series of tasks to move the robot a fixed distance forward.
(A)Abstraction refers to the process of representing a complex system by a simplified, representative version, usually describing the purpose of that system. The scenarios in choices A, B and D can all be considered examples of this. Choice C is not an example of abstraction: in fact machine code (which is represented by binary numbers) would be considered less abstract than a high-level programming language as it is closer to the actual functioning of the computer which is performing the tasks.
A financial analyst wishes to predict the chances of a fall of 10% or more in a particular stock in the next week by analyzing the recent performance of the stock. Which of the following sources of data would be the most appropriate for helping him make the prediction? (A) A list of floating-point values representing the changes in the value of the stock over the past 10 weeks. (B) An integer representing the number of times the stock has previously fallen by 10% or more in a week. (C) A list of integers representing the days of the previous week on which the value of the stock fell. (D) A floating point value representing the change in the value of the stock in the same week of the previous year.
(A)Of the potential answers, the information on recent performance by the stock is likely to be the best indicator of its performance in the near future. Floating-point values would be appropriate for this purpose as they can record the data to a high level of accuracy.
Which of the following best describes the meaning of the term "source code" in the context of a programmer writing a program? (A) The code written by the programmer, usually in a high-level language, to be compiled by the compiler. (B) A low-level language which the compiled code can be written in and closely corresponds to the ones and zeroes understood by the computer. (C) The ones and zeroes which are actually understood and run by the computer. (D) A generic language which can be used to express the functioning of the program without needing to use the specific syntax of any particular programming language.
(A)Source code refers to the code actually typed by the programmer, which is then sent to the compiler. The answer in choice B best describes assembly language, while choice C best describes machine code, which is written using binary numbers. Choice D accurately describes pseudocode.
Which of the following College Board AP Computer Science Principles Pseudocode commands is used to record something typed by a user of the program so that it can be used in the program? (A) INPUT () (B) DISPLAY (expression) (C) a MOD b (D) RANDOM (a, b)
(A)The INPUT () command is used for the purpose described in the question. DISPLAY (expression) causes the string expression to be displayed on screen, the command a MOD b calculates the remainder when the integer a is divided by the integer b, and the RANDOM (a, b) command selects a random integer between a and b to be selected.
Jasper is attempting to create instructions for folding clothes which could be described as an algorithm. Which of the following would be a feature of Jasper's instructions if they could be considered to describe an algorithm?(A) The instructions would be completely random. (B) The instructions would involve logical decisions and specific ordered sets of actions. (C) The instructions would result in exactly the same actions being performed for every item of clothing. (D) The instructions would be written in a high-level programming language.
(A)The instructions must specify actions which will be followed in a set way, however algorithms do not require exactly the same set of actions to be performed in all cases: decisions made in the algorithms may mean actions are different (e.g. Jasper's algorithm may specify different instructions for folding a shirt compared to a pair of trousers). Algorithms therefore are not completely random, although they may contain elements of randomness in some cases. Algorithms are most usually enacted through programming in a high or low level computer programming language, but can be expressed in other ways too (e.g. using natural language or flowcharts).
Which of the following are advantages of using meaningful names for variables when writing a program? Select two answers. (A) It is easier for a person reading the code to identify the purpose of a variable and follow the logic of the program. (B) It is simpler for the compiler to compile the program, meaning wait times and errors are reduced. (C) The programmer is less likely to make a mistake and use a variable for the wrong purpose. (D) Less variables will be required as the existing ones can be renamed throughout the program.
(A,C)The advantages of meaningful names for variables all relate to the readability of the code by humans. Using meaningful names will not have any effect on the overall logic of the program, or in the way the computer compiles and interprets the code.
17. 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. (B) The procedure will make the program more efficient, spending less time running the same set of 10 blocks over and over again. (C) If there is an error in the procedure, she can fix the error in the procedure without having to search through her code for each place the procedure is used. (D) She will be able to hide the function of this code block easier meaning others cannot copy her work.
(A,C)The program will be no more efficient as the blocks of code making up the procedure will still run each time the procedure is called. The procedure will also be no more visible than before. However if appropriately named the procedure can provide a useful abstraction whereby Sally only need think about the result of that section of code each time she calls it without worrying about the method (e.g. if the procedure is named SwapVarAB, she may know that this procedure swaps the values of the variables A and B without needing to rethink why or how each time). Furthermore there is an error in the procedure, fixing the error in the procedure will cause the error to be fixed wherever the procedure is called.
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 cross path as drawn above? (A) Step 1: MOVE_FORWARD Step 2: ROTATE_LEFT Step 3: MOVE_FORWARD Step 4: ROTATE_RIGHT Step 5: MOVE_FORWARD Step 6: ROTATE_RIGHT Step 7: ROTATE_RIGHT Step 8: MOVE_FORWARD (B)Step 1: MOVE_FORWARD Step 2: MOVE_FORWARD Step 3: ROTATE_LEFT Step 4: ROTATE_LEFT Step 5: MOVE_FORWARD Step 6: ROTATE_RIGHT Step 7: MOVE_FORWARD Step 8: ROTATE_RIGHT Step 9: ROTATE_RIGHT Step 10: MOVE_FORWARD Step 11: MOVE_FORWARD (C)Step 1: MOVE_FORWARD Step 2: ROTATE_LEFT Step 3: MOVE_FORWARD Step 4: ROTATE_LEFT Step 5: ROTATE_LEFT Step 6: MOVE_FORWARD Step 7: MOVE_FORWARD Step 8: ROTATE_RIGHT Step 9: ROTATE_RIGHT Step 10: MOVE_FORWARD Step 11: ROTATE_LEFT Step 12: MOVE_FORWARD (D)Step 1: MOVE_FORWARD Step 2: ROTATE_RIGHT Step 3: MOVE_FORWARD Step 4: ROTATE_LEFT Step 5: ROTATE_LEFT Step 6: MOVE_FORWARD Step 7: ROTATE_RIGHT Step 8: MOVE_FORWARD Step 9: ROTATE_LEFT Step 10: ROTATE_LEFT Step 11: MOVE_FORWARD
(B)In the algorithm given in choice B, steps 1 and 2 will cause the robot to trace one complete line of the cross from end to end through the center. Steps 3 and 4 will cause the robot to turn to face the opposite direction and step 5 will cause it to move to the center of the cross. Step 6 causes it to rotate so it faces perpendicularly to the line it just traced, and step 7 causes it to trace a line in this direction from the center to the end of one of the "arms" of the cross. Steps 8 and 9 cause the robot to turn to face the opposite direction before steps 10 and 11 cause it to trace the other complete line of the cross from end to end through the center. None of the other answer choices will cause the complete cross to be traced although C and D will result in part of the cross being traced.
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? (A) Five years from now, computer programs will be able to solve complex problems faster than today's computer programs. (B) Five years from now, web pages will require less memory (RAM) than today's web pages. (C) Five years from now, top-of-the-line computers will have faster processors (CPUs) than today's top-of-the-line computers. (D) Five years from now, electronic components can be made smaller than today's equivalent electronic components.
(B)Moore's law relates to improvements in hardware, rather than software. The amount of RAM which is required by a web page is a software problem. In fact, in general as web pages become more content rich they will require more memory to run. Moore's law does mean that additional memory will likely be available for this in the future however.
Which of the following languages is easily understandable, but is likely to contain many ambiguities? (A) Machine Code (B) Natural Language (C) High-level programming language (D) Low-level programming language
(B)Natural language, as people usually use to communicate with other people, is not well suited to programming since there are many ambiguities present in the language. Machine or Binary Code understood by computers and low-level languages, which are close in structure to this are considered to be almost completely unambiguous. A high-level programming language may contain more ambiguities created by the abstractions used, but is still going to be very unambiguous when compared to natural language.
Which of the following features of a scratch program could not be changed by a block at a later stage of the program? (A) The background image (B) The name of a sprite (C) The value of a variable (D) The visibility of a sprite
(B)Once a sprite (or any type of variable) in Scratch has been created and given a name, the name can only be changed by directly editing it within Scratch. The name is used by the blocks within Scratch to refer to that sprite, therefore changing the name while the program is running would cause numerous problems. For this reason there is no block to do this in Scratch
Given the following code segment, what would be displayed if age were initialized with a value of 18? (A) group 1 (B) group 2 (C) group 1 group 2 (D) Nothing will be displayed
(B)The code within the IF block is only run when one of the two conditions is met: that is the value of age is bigger than or equal to 65, or the value of age is less than 18. The value 18 does not meet either of these conditions so the code in the IF block will not be run. The code within the ELSE block will run whenever the code in the IF block is run. Hence in this case group 2 will be displayed and nothing else.
15. A programmer is attempting to convince her boss to give her time to write a program which will improve efficiency in the office by determining when and where certain resources should be allocated. Which of the following would be most useful for her to show to her boss to help him understand how the program will work?(A) A printout of all of the code she has created for the program so far. (B) Examples of various inputs and the intended outputs of the code resulting from these. (C) A list of errors which were encountered when she attempted to compile the code. (D) A list of pros and cons of using different programming languages to create the program.
(B)The example inputs and outputs will help to summarize the overall logic used by the program and give her boss a sense of what to expect when the program is complete. This is likely to be more quickly understood than incomplete code which may be difficult to interpret and not fully reflective of what the program will do. The errors and pros/cons list will contribute very little to an overall sense of how the program will work although they may both be important to ensuring good execution of the project.
Consider the block of code below: What would be the most appropriate substitute for the missing Boolean Operator if the intention is to display "True" for only values of x between, but not equal to values of 0 and 10? (A) NOT (B) AND (C) OR (D) XOR
(B)Using the operator AND will ensure that the variable x must both be less than 10 and at the same time greater than 0 if the code within the IF block is to be run. Using OR or XOR would mean the code may be run when only one of these is true, while using NOT would most likely lead to an error, since this is an operator single boolean variable, not a binary operator.
20. Which of the following algorithms require both selection and iteration? Select two answers: (A) An algorithm that, given two integers, displays the greater of the two integers. (B) An algorithm that, given a list of integers, displays the number of even integers in the list. (C) An algorithm that, given a list of integers, displays only the negative integers in the list. (D) An algorithm that, given a list of integers, displays the sum of the integers in the list.
(B,C)An algorithm which deals with multiple elements on a list will most likely use iteration since it will almost certainly be performing the same function on multiple elements of the list. If a decision needs to be made based on the values of the variables used then the algorithm will require selection. The algorithm in choice A uses only selection, while the algorithm in choice D uses only iteration. In choices B and C both iteration and selection since both perform a function on elements of a list which match a certain condition.
Which of the following statements about low and high-level programming languages is not true? (A) High-level languages make more use of abstractions than low-level languages. (B) High-level languages are generally easier for humans to read and understand than low-level languages. (C) High-level languages are closer in structure to the binary code understood by computers than low-level languages (D) High-level languages are more likely to contain ambiguities than low-level languages.
(C)High-level languages make use of abstractions, replacing several difficult to understand commands in machine code with a statement describing the effect of these.This makes them easier to be read and understand than low-level languages, but can introduce some ambiguities. By contrast, the structure of low-level languages is based off the machine code which is actually used by computers to give and receive instructions.
Which of the following statements comparing block-based and text-based programming languages is true? (A) Block-based languages offer far greater control over low-level functionality than text-based languages. (B) Most programs written in a block-based language could not be replicated in a text-based language. (C) Errors from incorrect syntax are far more likely if writing using a text-based language than if using a block-based language. (D) Text-based languages are far more likely to be ambiguous than block-based languages.
(C)Since commands and variable names must be typed when writing using a text-based language, it is far easier to make typos and other small syntax mistakes which cause errors. These errors will not be made when placing a preset block in the correct place in a program. This is a disadvantage of using a text-based language, however text-based languages do as a result allow for far greater customizability and control. There is not much difference in either the capability or ambiguity of text-based and block-based languages
Hiro is writing a program which will record the number of cars passing a certain point in town every hour in a day, then record the range of this data by subtracting the smallest total from the largest. He will use a variable, rge, to store the range. Which variable type would be most suitable for rge? (A) Floating point (float) (B) Boolean (C) Integer (int) (D) String
(C)The number of cars passing each hour must be an integer value (i.e. a whole number). Since the range is calculated by subtracting the greatest number of cars from the least, this will also be an integer value, making an integer variable the most appropriate variable type to store this. Choice A is incorrect because a floating point variable stores any decimal number. As the range is calculated by subtracting one integer value (the highest number of cars passing) from another (the lowest number of cars), the answer will definitely be an integer, making a floating point variable unnecessary. Choice B is incorrect because a boolean can only store one of two values: "false" (0), or "true" (1). This does not make it suitable for a range which can take many different number values. Choice D is incorrect because a string variable holds a string of characters, which are letters, digits or symbols. Since the average will be a number not containing letters or symbols, a string is not a good choice of variable to store this
Three friends are programming a game together and have run into problems working on the code simultaneously. It is difficult for each programmer to test the code when needed as other parts of the code are often not ready, and it is not always clear whose code is causing errors. Which of the following solutions should the programmers implement to solve these problems. (A) Leave all testing of the code until everything is complete and then thoroughly test the completed program. (B) Only allow one person to program at a time. (C) Create individual copies of the code for each programmer to work on and test different sections, then add code to a master copy as it is completed. (D) Make each programmer write their own complete version of the game, then use the best solutions from each programmer to create a joint program.
(C)The solution described in option B is likely to be very inefficient as it will leave two programmers idle at all times. The solution in option D is also incredibly inefficient as code will be written multiple times by different programmers. The solution in option A will also not work well as it will be much harder to identify and fix errors if the code is only tested once everything is completed. The solution in option C could work as long as there is a sufficient plan to ensure all parts work together.
Nick wishes to create a variable in his scratch game which records the best score by a player so far. Which of the following would be the most appropriate name for this variable? (A) Variable1 (B) b (C) best_score (D) theBestScoreSoFarByAPlayer
(C)Using a name which describes the purpose and meaning of a variable will make code easier to write, understand and debug. However a good variable name should also be succinct: using a name such as the one in D may make the code less easy to read, and (in the case of written code) be more likely to cause typos which can cause a program error.
Which of the following would not be a sensible action to take before beginning to write a program? (A) Decide how to name the variables in the program so their purpose is clear and no conflicts or confusion arises between variables. (B) Consider the outputs which might be expected by the program given a variety of different inputs. (C) Draw or write a brief outline of the logical steps will need to be written in the program in order to ensure it behaves as intended.
(D) Choose a random segment of the program to write in full in order to get a feel for what will be required. Choices A, B and C all describe reasonable steps which help to create a plan for how the program will be written. Without these steps there is a greater likelihood of running into problems later and needing to rewrite earlier code or create inefficient patches. By contrast, going straight in and writing a random part of the program would not be sensible. Any part of the program may depend on other parts to function correctly and may have other parts which depend on it, necessitating it to be written as part of a bigger whole.
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. (A) I only (B) I and II only (C) I and III only (D) I, II, and III
(D)For some problems, a suitable algorithm may not have been developed, particularly if it is a new problem. There are also some problems (for example the traveling salesman problem) which have an exponential complexity, meaning for large examples it can take years to find an exact solution. It has also been determined that some problems can never be algorithmically solved (an example of such a problem is the "Halting Problem", which asks whether any given program will eventually halt or continue infinitely). Problems such as these are referred to as "undecidable problems".
What values, when inputted by the user, of A, B, and C will cause the code to display " Invalid Input "? (A)A=-10 B = 0 C=4 (B)A = 0 B = 0 C=0 (C)A = -1 B=-2 C=0 (D) A = -5 B = 0 C=0
(D)Since the condition for the IF block is given as (A < 0) AND (B ≥ 0) AND (C = 0), the code within the IF block will not run unless all three of the conditions A < 0, B ≥ 0, and C = 0 are met. This is not true for choice A because the condition C = 0 is not met. It is not true for choice B because the condition A < 0 is not met. It is also not true for choice C because the condition B ≥ 0 is not met. Only in choice D are all three of the conditions met, meaning the code within the IF block will run and cause the string "Invalid Input" to be displayed.
16. 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? (A) The linear search will now be faster on average than the binary search. (B) 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 approximately the same as for the shorter lists. (C) 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 approximately 10 times greater than for the shorter lists. (D) 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.
(D)The average number of comparisons which a linear search performs on average is linearly related to the length of a list (since the search iterates through items on the list one at a time). This means that using a list 10 times as long will result in an average tenfold increase in processor time. The number of comparisons a binary search performs is logarithmically related to the number of items on the list: if the size of the list doubles only 1 extra check needs to be made. This means that the processor time for the binary search will increase by far less than tenfold. Therefore the difference between the binary search and linear search times must increase by a bigger factor than 10.
What would be the final value of the variable third once the following program is complete? first ← 2 second ← 3 third ← first * second second ← third - first first ← first + second + third third ← second * first (A) 6 (B) 33 (C) 36 (D) 48
(D)The first line of the program sets the value of first to 2, and the second line sets the value of second to 3. The next line sets the value of third to the product of the current values of first (2) and second (3), this sets third to a value of 6. The following line sets the value of second the current value of third (6) less the current value of first (2), this sets second to a value of 4. The line after this sets the value of first to the sum of the current values of first (2), second (4) and third (6), this sets first to a value of 12. The final line sets the value of third to the product of the current values of second (4) and first (12), this sets third to a value of 48.
Which of the following are advantages of using meaningful names for variables when writing a program? Select two answers. (A) It is easier for a person reading the code to identify the purpose of a variable and follow the logic of the program. (B) It is simpler for the compiler to compile the program, meaning wait times and errors are reduced. (C) The programmer is less likely to make a mistake and use a variable for the wrong purpose. (D) Less variables will be required as the existing ones can be renamed throughout the program.
A,C)The advantages of meaningful names for variables all relate to the readability of the code by humans. Using meaningful names will not have any effect on the overall logic of the program, or in the way the computer compiles and interprets the code.