Unit 1 Computer Science Principals AP Review
Which of the following best describes how abstraction makes code written in higher-level programming languages easier for humans to parse? A) Abstractions used in higher-level languages mean what a command does is easier to understand without needing to parse all the individual operations performed by the CPU. B) Abstractions used in higher-level languages remove any potential ambiguity from the code. C) Abstractions used in higher-level languages make the code closer to the actual individual operations performed by the CPU D) Abstractions used in higher-level languages make them almost identical to a natural language which would be spoken by humans.
Abstractions used in higher-level languages mean what a command does is easier to understand without needing to parse all the individual operations performed by the CPU. - This is correct. Abstraction replaces a complex system with a simplified representation. In this case a complicated sequence of operations being performed by the CPU is replaced with a simplified representation which is more easily understandable to a human.
Which of the following statements are NOT true about high level programming languages? Select two answers: A) Code written using high level languages usually requires compiling before it can be run B) Code written using high level languages is guaranteed to be ambiguous C) Code written using high level languages is relatively easy for humans to read, write and parse D) Any particular algorithm will be written in the same way regardless of which high level programming language is used
B and D D) Any particular algorithm will be written in the same way regardless of which high level programming language is used - This is correct. This is both the syntax and semantics of different high level languages can be quite different. Therefore while it is usually possible to write an algorithm in many different languages, the way in which it is written may be quite different. B) Code written using high level languages is guaranteed to be ambiguous This is correct. This is a false statement as programming languages are unambiguous (when properly documented), meaning a program only has one possible way of being interpreted.
Which of the following best describe examples of abstraction Select two answers. A) Several developers are working on a program together. In order to complete the work efficiently, they split the program up into several parts, and each work on a section, testing as they proceed. When code is complete they add it to a master program. B) A sheet of music for guitar is written as a series of chords (e.g C, Am, G7). Each of these represents multiple notes which are played simultaneously on different strings of a guitar. C) A series of steps for creating a model aeroplane is laid out in a clear order, with specific instructions in great detail for completing each step. D) A developer writing a program for calculating properties of shapes uses a variable pi to store a decimal approximation of the number π (~3.14159). They use this variable whenever they need to use the number π to calculate an area or volume.
B and D D) A sheet of music for guitar is written as a series of chords (e.g C, Am, G7). Each of these represents multiple notes which are played simultaneously on different strings of a guitar. - This is correct. Each chord is actually made up of several different notes, but is represented by just one or two characters. This is therefore an example of abstraction, where a complex system is replaced with a simplified representation. B) A developer writing a program for calculating properties of shapes uses a variable pi to store a decimal approximation of the number π (~3.14159). They use this variable whenever they need to use the number π to calculate an area or volume. - This is correct. The constant π, which has an infinite decimal expansion, is represented by a simple variable name of pi. This is therefore an example of abstraction, where a complex system is replaced with a simplified representation.
Which of the following is a simplified but equivalent Boolean expression to the following: (X > 0 AND X ≤ 20) OR (X > -5 AND X < 15) A) (X > 0) AND (X < 15) B) (X > -5) AND (X ≤ 20) C) (X < 0) AND (X > 15) D) (X < -5) AND (X ≥ 20)
B) (X > -5) AND (X ≤ 20) - This is correct. The expression in the question is satisfied whenever (1) the value of x is between 0 and 20 (including 20), or (2) the value of X is between −5 and 15, or both conditions (1) and (2) are satisfied. For every value of X greater than −5 and not larger than 20, at least one of the conditions (1) or (2) is satisfied, and for every value of X not in this range, neither of the conditions (1) or (2) is satisfied. Therefore any value of x which satisfies (X > -5) AND (X ≤ 20) also satisfies the expression in the question, and any value of x which does not satisfy (X > -5) AND (X ≤ 20) does not satisfy the expression in the question. This must mean that the two expressions are equivalent.
Rick is in charge of a team developing a program which will be used by businesses to control stock. The team has already consulted with potential clients and developed an idea of what inputs will be required and the likely outputs that will be produced from these inputs. Which of the following should Rick and his team do next? A) Write segments of code in different languages to see which language will be most suitable for the job B) Plan the structure of the program and determine how the major algorithms will work C) Make a list of bugs which will occur during development and propose ways these could be fixed D) Decide on the schedule for updates and maintenance of the code
B) Plan the structure of the program and determine how the major algorithms will work - This is correct. When the initial planning and ideas phase of the development cycle is complete, the next step should be to consider the overall design of the program and how it will implement the desired functionality.
Jama is creating a program which calculates the square roots of whole numbers. The program will store the results of each square-root as a variable. Which of the following data-types would be best used for this variable? A) bool B) float C) int D) string
B) float This is correct. The square root of an integer may be another integer or a non-integer number (e.g. the square root of 2 is 1.4142...). Since the floating point number (float) data type stores decimal numbers, this makes it an ideal data-type for this variable.
Roxanne is writing a program which will be used to display information to passengers on a flight. Some of the variables she will use for her program are as follows. speed - the current speed of the airplane relative to the ground in meters per second passengers - the number of passengers on-board the plane destination - the name of the destination airport of the flight Which of the following correctly describes the types which would be best used for each of these variables? A) speed - float, passengers - string, destination - int B) speed - float, passengers - int, destination - string C) speed - int, passengers - float, destination - string D) speed - string, passengers - int, destination - float
B) speed - float, passengers - int, destination - string This is correct. The variable speed takes decimal number values, therefore a float, which represents decimal numbers is the best choice. The variable passengers will always be a whole number (integer), therefore an int is the best choice. The variable destination is a word (or multiple words) formed of letters, therefore a string, which is made up of multiple characters (letters, numbers, symbols) is the best choice.
Which of the following variable types is characterized by allowing only two possible values to be stored? String Boolean Float Array
Boolean - This is correct. A boolean can take a true or false value, so is useful for storing variables which can only take 2 possible values.
Which of the following statements comparing low-level programming languages (such as assembly language) and high-level programming languages (such as python or java) are correct? Select two answers. A) A low-level program can be easily understood and assembled on any hardware, while the use of a compiler means a high-level program is difficult to use on different systems. B) A program written in a high-level language will usually be easier for a person reading the code to understand than one written in a low-level programming language. C) A program written in a low-level language is closer in syntax to the binary code understood by computers than a program written in a high-level language. D) A low-level programming language is easier to learn, but some algorithms can only be written using high level programming languages.
C) A program written in a low-level language is closer in syntax to the binary code understood by computers than a program written in a high-level language. This is correct. In contrast to high-level languages, the commands and syntax of low level languages, such as assembly language, closely reflect a machine or binary code understood by computers. B) A program written in a high-level language will usually be easier for a person reading the code to understand than one written in a low-level programming language. This is correct. One implication of this is that it is harder for a human to read and understand a low-level language than a high-level language, which was designed for humans to use to program efficiently.
Rhys is creating a program which stores customer records. One variable used in the program stores the first initial of a customer's name. Which of the following data-types could be used to store this data? Select two answers. Character Integer Boolean String
Character - This is correct. A character stores a single letter, number or symbol, and therefore is ideally suited to storing a single letter variable. String - This is correct. A string variable stores a sequence of letters, numbers and symbols, and could therefore be used to store a single letter if required.
Erin has written a program which presents a user with multiple-choice quiz questions to answer and calculates a percent score based on the number the user got right or wrong. Each question has 5 possible answers, and scores presented are from 0 to 100 percent inclusive. Which of the following could be represented by a boolean variable? A) The correct answer choice for a particular question. B) The number of questions in the quiz. C) The percent score of the user D) Whether a user got a specific question right or not
D) Whether a user got a specific question right or not This is correct. A boolean variable can have two possible values - true or false. This makes ideal for determining if a user got an individual question right (true) or not (false).
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 could successfully cause the robot to trace out a "T"-shaped path as drawn above? A) Step 1: MOVE_FORWARD ( ) Step 2: MOVE_FORWARD ( ) Step 3: ROTATE_RIGHT ( ) Step 4: MOVE_FORWARD ( ) Step 5: ROTATE_RIGHT ( ) Step 6: ROTATE_RIGHT ( ) Step 7: MOVE_FORWARD ( ) B) Step 1: MOVE_FORWARD ( ) Step 2: ROTATE_LEFT ( ) Step 3: ROTATE_LEFT ( ) Step 4: MOVE_FORWARD ( ) Step 5: ROTATE_RIGHT ( ) Step 6: MOVE_FORWARD ( ) C) Step 1: MOVE_FORWARD ( ) Step 2: MOVE_FORWARD ( ) Step 3: ROTATE_LEFT ( ) Step 4: MOVE_FORWARD ( ) Step 5: MOVE_FORWARD ( ) Step 6: ROTATE_RIGHT ( ) Step 7: ROTATE_RIGHT ( ) Step 8: MOVE_FORWARD ( ) D) 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: MOVE_FORWARD ( )
D) 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: MOVE_FORWARD ( ) This is correct. If the robot begins at the top-right of the "T"-shape, facing towards the left, then it will trace out the "T"-shape as shown. Initially the robot moves forward twice to draw the horizontal top of the "T", then turns back on itself and moves forward once, taking it to the center of the top. The robot then turns right and moves forward twice to draw the vertical line of the "T"-shape.
The following algorithm is proposed for the task of baking a cake, and is presented along with a list of ingredients. Add some ingredients from the list to a bowl Stir Add other ingredients to a bowl Stir Put in a tin in the oven Take out tin from oven Which of the following correctly describes an issue with the way the instructions in this algorithm is presented? A) The instructions do not contain any selection or iteration statements B) The sequencing of the instructions is unclear C) The instructions lack imperative statements D) The instructions lack descriptive qualifiers
D) The instructions lack descriptive qualifiers This is correct. Descriptive qualifiers are needed to determine for example which ingredients are added first, which ingredients are added later, and how long the tin should be in the oven for.
Which of the following statements about variables in programming are true? I. Variables allow a value to be stored for future use II. Once the value of a variable is set it cannot be changed III. The name given to a variable is important for human comprehension, but not for the computer. I, II and III II only I and III only I only
I and III only This is correct. The use of a variable is primarily to store values which can be used later. It is important to name variables so that code is comprehensible to people reading it (including the original programmer) and its purpose and function can be quickly determined. Despite this, it makes no difference to the running of the program by the computer what variable names are used.
Which of the following describes algorithmic solutions to problems: I. A set of step by step instructions for assembling a piece of furniture. II. A flowchart used to make important decisions on which actions to take in an emergency situation III. A recipe for baking a cake with detailed numbered steps to follow II and III only I, II and III I and II only I and III only
I, II and III - This is correct. Each of the problems described (assembling a piece of furniture, dealing with an emergency situation and baking a cake) are solved through a set of logically ordered, precise instructions. These solutions can therefore be thought of as being algorithmic in nature.
The following algorithm is presented for assembling a piece of furniture from 12 individually numbered parts. Parts 1, 5, and 11 Parts 2 and 10 Part 12 Parts 6 to 9 inclusive Parts 3 and 4 Which of the following correctly describe issues with the way these instructions are presented? I. There instructions lack the required descriptive qualifiers II. The instructions lack the required imperative statements III. The order in which the instructions should be performed is unclear I, II and III I and II I only II only
II only - This is correct. The order of instructions is clear, as is which parts should be used for each instruction. Imperative statements (e.g. attach, place together, fasten to) however are required in order for someone following the algorithm to understand what actions they actually have to perform with the parts listed.
Microsoft Excel® is a spreadsheet program that can be used for computing the average of a list of values in cells A1 through A20 with a command such as =AVERAGE(A1:A20). After the user initiates this command, the command disappears and the average (or mean) of the list of numbers appears. Why is this an abstraction? A) There are steps that are followed in order to complete the calculations. B) There is math being used in order to calculate the average. C) The average can be viewed without knowing the process of how the average was computed. D) There is an equal sign present in the command.
The average can be viewed without knowing the process of how the average was computed. - This is correct. Abstraction is the process by which complicated procedures can be replaced by a simplified representation. In this case, excel is summing the values in cells A1 to A20 and dividing this by the number of cells (20). However this process is represented by a simple command, =AVERAGE(A1:A20), which describes what is actually calculated by this process. Therefore this is an example of abstraction.
Which of the following best describes why the development process by which computer programs are created is described as "iterative"? A) The steps in the process must be strictly followed one after another. B) The process is a cycle, with results from one run of the cycle feeding into the next. C) The process begins with planning and design phases before any of the implementation begins. D) Evaluation and testing may take place throughout the process and not just at the end.
The process is a cycle, with results from one run of the cycle feeding into the next. - This is correct. To iterate means to repeat a process, although not necessarily with the same data or results. This describes the development process since results from the evaluation and testing in one cycle are then used to create ideas for improvement and extension and start a new cycle of development.
Marta is writing a program for a home-automation system. Three of the variables in her program are as follows: light - A variable which determines whether the lights in a room are switched on or off temp - A variable which records the temperature of the room to the nearest whole degree Fahrenheit name - A variable which records the name the user has set for the room (e.g. "kitchen") Which of the following correctly describes the types which would be best used for each of these variables? light - boolean, temp - string, name - integer light - string, temp - integer, name - boolean light - boolean, temp - integer, name - string light - integer, temp - boolean, name - string
light - boolean, temp - integer, name - string - This is correct. A boolean should be used for light as it can only have two possible value (on/off or true/false). An integer should be used for temp, as it can take many different possible values which are whole numbers. A string should be used for name since it can contain a combination of letters (and/or numbers).
Which of the following is an example of code written in a high-level programming language? A) Add the number 2 to the number 5, then subtract this from the number 10 and display the answer. B) LD R0 8 LD R1 3 SUB R1 R0 LD R2 1 ADD R2 R0 ST R0 X C) num1 = 8 - 3 num2 = 2 * num1 + 1 print(num2) D) 00101100 01010000 11011000 10110111
num1 = 8 - 3 num2 = 2 * num1 + 1 print(num2) Choice C is correct. This code is written in a high-level programming language: it uses some Instructions in english (e.g. print) and mathematical operators, but uses a formal and logical structure which removes ambiguities present in natural language.