Big Idea 2: Abstraction

Ace your homework & exams now with Quizwiz!

Which of the following are desired properties of procedural abstraction? Select TWO answers

Minimally specified.Simple. Explanation: Desirable properties of procedural abstraction include code that is more readable and reusable. Minimally specified means that the code is only restricted only to the extent required by the users, making it more reusable. Simple means code that is well-defined and has an easily explained purpose.; in other words, it is not overly complex.

Donna is writing a program for her book store that will help her monitor inventory. She has many different kinds of books (fiction, non-fiction, textbooks, cookbooks, etc.) that all require different types of data. She has noticed, however, that several pieces of data are the same no matter which type of book she is selling: title and price. She creates some procedures that report the title and price of a book that she can use with any kind of book she sells. This is an example of what computing principle?

Abstraction. Explanation: This is an abstraction because Donna generalized a concept — reporting the title or price of a book — to apply to all types of books. Noticing repeated details or common features and removing them is a key element of abstraction.

There are multiple levels of abstraction in computer hardware. Which of the following is NOT a level of abstraction in computer hardware?

Operating systems. Explanation: An operating system is the most important piece of software that runs on any computer system. Remember, a program is simply a bunch of instructions waiting to be put into action. The operating system takes the program's bits and bytes and creates the solution the program is waiting to execute. It is a core abstraction for computer science, but of software, not hardware: the process of running a program.

A beginning programmer has written a program to have a robot move up a flight of stairs that has 3 steps. The robot is initially facing east. PROCEDURE climbStairs () { ROTATE_LEFT () MOVE_FORWARD () ROTATE_RIGHT () MOVE_FORWARD () ROTATE_LEFT () MOVE_FORWARD () ROTATE_RIGHT () MOVE_FORWARD () ROTATE_LEFT () MOVE_FORWARD () ROTATE_RIGHT () MOVE_FORWARD () } However, the programmer just learned about abstraction and would like to modify the code to take advantage of this concept. Which of the following blocks of code would be the best use of abstraction that also performs the same function as the original code?

PROCEDURE climbStairs () { REPEAT 3 TIMES { oneStep () } } PROCEDURE oneStep () { ROTATE_LEFT () MOVE_FORWARD () ROTATE_RIGHT () MOVE_FORWARD () } Explanation: All of the given choices will have the robot navigate to the top of three steps like the original code. However, the code segment in this choice has taken the common code to climb one stair and created a new procedure named oneStep. The climbStair procedure repeats the call of oneStep three times within a loop to make the robot climb a total of three steps

Which of the following does NOT describe the process of procedural abstraction?

The reduction of a particular body of data to a more simplified model of the whole. Explanation: Reducing a particular body of data to a more simplified model is the definition of data abstraction, not procedural abstraction.

A spreadsheet can be used to perform mathematical operations on data. For example, in Google Sheets, the following command can be used to find the sum of the numbers in cell A1 through E1: =SUM(A1:E1) After the user hits enter, the text above disappears and is replaced with the actual sum. The text of the SUM command shows up at the top of the screen, but the SUM cell continues to display the sum, not the command. Why is this an example of abstraction?

The user can view the sum of those cells without knowing how the sum is calculated. Explanation: So a user in Google Sheets can see the sum of A1 through E1 without knowing how the sum was calculated. An abstraction removes detail from a process, making it easier to understand.

A constant is a special type of variable sometimes used to represent a piece of information in a computer program. Which of the following choices is the best situation for using a constant in a program?

To represent the maximum number of lives a player can have in a game. Explanation: A constant is a variable that is initially assigned a value, and the value of that variable cannot be changed in the program. "The maximum number of lives a player can have in a game" is typically a value that would not be changed while the game is being played, and therefore is a good candidate to be a constant.

High-level computer programming languages, such as Python, C++, and Java, provide which of the following features? Select TWO answers.

constants, expressions, and libraries. Statements and procedures. Explanation: High-level languages provide the programmer with a wide variety of abstractions, including constants, expressions, statements, procedures, and libraries.

MacKenzie is planning to write a program to play tic-tac-toe. She also knows that she has an assignment coming up at the end of the month that will require her to draw a checkers board on the screen. She plans to write the following procedures: square(size) row(tiles, size) grid(tiles, size) In her planning, she intends to start with code to draw a square, then use square(size) in her row(tiles, size) definition, and finally to use row in her grid(tiles, size) definition. Which is the highest level of abstraction?

grid(tiles, size) Explanation: The grid(tiles, size) procedure uses the grid(tiles, size) procedure, which in turn employs the square(size) procedure. grid(tiles, size) is the highest level abstraction, as it employs the other procedures.

Consider the following short program: 1. pi ← 3.14159 2. r ← INPUT() 3. a ← pi * r * r 4. DISPLAY (a) In the program above, line 3

is a statement. Explanation: A statement is a line or more of code. A statement does something, but it does not have a value. That is, a variable cannot be assigned a statement. Line 3 is a full line of code, that is, a statement.

Consider the following short program: 1. pi ← 3.14159 2. r ← INPUT() 3. a ← pi * r * r 4. DISPLAY (a) In the short program above, which is best thought of as a constant?

pi Explanation: The value of pi (π) in line 1 is the constant. The program is calculating the area of a circle using the equation A=π∗r2.

Donna makes a website feature that will recommend books to users by asking questions about their likes and dislikes. There's a bug in the program, so she decides to ask her friend Martha to look over her code. Before Martha looks at the code, she asks Donna to describe it. Which of the following parts of Donna's description is an abstraction? Select TWO answers.

"The ask method prints out a multiple choice question to the user and then records the user's answer in a list." "After all the questions have been asked, the match method retrieves three book recommendations for each answer selected and puts them in a new list." Explanation: Both of these descriptions give Martha an idea of what the code does without giving too much detail about how the code does it.

Using the algorithm below, the decimal number 13 has been converted to its binary equivalent. REPEAT UNTIL (quotient = 0) { remainder = quotient MOD baseNum; quotient = quotient / baseNum; DISPLAY (remainder) } The first two iterations of this algorithm are as follows: Which of the following is the binary number that is displayed for 13 using this algorithm?

1101 Explanation: By continuing the algorithm, 3/2 = 1, remainder 1, and 1/2 = 0, remainder 1. Remember, that the remainder from step 1 is the right most digit. All other remainders will be placed in order to the left of this digit. As such, the answer is 1101.

The figure below shows a circuit composed of two logic gates. The output of the circuit is true. A or B--> and--> true C--^ Which of the following values for inputs A, B, and C would cause the output to be true?

A <-- false B <-- true C <-- true Explanation: Let's consider the first logic gate. Since input A is false and input B is true, (A OR B) evaluates to (false OR true). In an OR condition, if either of the inputs are true then the result is true. Therefore, the first logic gate yields true. So, the second logic gate has two inputs: input C and true. Input C is given the value true in this case, so the second logic gate evaluates to (true AND true). An AND condition only evaluates to true if both of its inputs are true. This is the case, so the final output is true, which matches the diagram

Donna writes a procedure called Discount that will help her calculate the sale prices of books. The procedure includes a parameter called p that represents the percent being taken off the price of the book. Which of the following statements is true?

Adding the p parameter is an example of abstraction because it generalizes functionality of the procedure Explanation: Without the p parameter, Donna would need a different Discount method for every possible discount. The p parameter allows her to generalize the Discount method to any possible percent.

In many programming environments today, one language translates the programmers' code into a different language before the computer actually executes the code. For instance, the visual programming language Alice translates your instructions into Python, then Python translates the code into machine-readable code. Python, in this situation, also relies on some C/C++ libraries for certain items, including collision detection. In this situation, which is the highest-level language being used?

Alice Explanation: Alice is the highest-level language being used in this situation. The instructions given in Alice are translated into Python and C/C++, then down to lower-level machine code.

Consider the two procedures below: PROCEDURE shape1 () { REPEAT 4 TIMES { MOVE_FORWARD() MOVE_FORWARD() ROTATE_RIGHT() } } PROCEDURE shape2 (size) { REPEAT 4 TIMES { REPEAT size TIMES { MOVE_FORWARD() } ROTATE_RIGHT() } } Which of the following best describes the results of both procedures?

Both will draw a square when properly called. Explanation: Both will draw a square

An abstraction extracts common features from specific examples in order to generalize concepts. The following illustrates abstraction in the example code from top to bottom, starting with the procedure makeDinner(). PROCEDURE makeDinner () { IncludeGetIngredients() IncludeGetCookingImplements() } PROCEDURE getIngredients() { IF(this.missingIngredients() ) { IncludeShoppingList() } IncludeSetOutIngredients() } PROCEDURE missing code () { IncludeGetCoupons() IncludeGetMoney() } The level of abstraction in the program increases as you go deeper into the program. Based on the above, what is the BEST choice to replace the missing code in the following program?

IncludeShoppingList. Explanation: Remember, abstraction allows us to remove some details and replacing these details by some generalizations. It also extracts common features from specific examples in order to generalize concepts. The key to finding the correct answer in this problem is to find the common pattern of how the program goes deeper into levels of abstraction. You first start with making dinner, but in order to make dinner, you first have to get both the ingredients and the cooking implements (such as pots or pan). However, before you can get the ingredients, you need to make sure that you have them. If you don't have them, you need to go get them. If you are missing ingredients, you have to create something that requires you to get both money and coupons.

Which of the following is an example of abstraction?

Jimmy is teaching his daughter how to drive a car. Instead of explaining how the engine works, he tells her that turning the key will start the car. Explanation: Developing an abstraction involves removing details of a process. Since Jimmy removed the mechanics of how a car actually runs, he developed an abstraction

MacKenzie is planning to write a program to play tic-tac-toe. She also knows that she has an assignment coming up at the end of the month that will require her to draw a checkers board on the screen. She plans to write the following procedures: square(size) row(tiles, size) grid(tiles, size) In her planning, she intends to start with code to draw a square, then use square(size) in her row(tiles, size) definition, and finally to use row in her grid(tiles, size) definition. Assuming that square(size) works properly, drawing a square and ending with the robot in the position in which it started, which of the following is the correct code for row(tiles,size)?

PROCEDURE row (tiles, size) { REPEAT tiles TIMES { square(size) REPEAT size TIMES { MOVE_FORWARD() } } Explanation: After drawing each square, the robot moves forward the size of a square before drawing the next square.

Which of the following statements is NOT true about high-level and low-level programming languages

Programs written in a high-level language are generally more difficult for programmers to understand than programs written in a low-level language. Explanation: High-level language was created so that programmers could write code in a language that was easier to understand. However, computers cannot understand high-level language, so it must be translated with a compiler and/or interpreter.

A process named "Stepwise Refinement" is useful when programming. What is Stepwise Refinement?

Stepwise Refinement is a top-down design process in which the programmer starts with the overall goal of the program and continually breaks down the design into sub-functions. Explanation: Stepwise Refinement is a top-down design process which starts with the big picture and continually breaks down the design into sub-functions until the base code is reached. It is a common technique for determining the different procedures needed in the program. This design approach tends to lead itself to abstraction, since it promotes the continual break down of functions until it reaches the base level


Related study sets

English File Intermediate. Unit 5A. Vocabulary & Speaking pg. 157 (Sports)

View Set

Marketing 301 Exam 2 Review Part 1

View Set

Chapter 5: separate and together: life in groups

View Set

Word Meaning in the Preface to A Dictionary of the English Language

View Set