Abstractions Facilitate Programming and Program Development

Ace your homework & exams now with Quizwiz!

Can a program run faster simply based on what you name variables?

no

visualization

the formation of a mental image of something

Boolean

a single value of either true or false

privatization

a technique used in shared-memory programming to enable parallelism, by removing dependencies that occur across different threads in a parallel program

program development

happens when code is being planned

What do algorithms that help write programs help with?

helps in coding

What does debugging software that looks for errors help with?

helps in fixing code

What are ways that best help find errors when debugging code?

-having fewer long code blocks and more short ones and having -knowledge of what the program is supposed to do

What helps a programmer with debugging?

-well named variables and procedures -inserting statements like "loop completed" or "if statements starts here" that display the code is running

if else statement

A high-level programming language statement that compares two or more sets of data and tests the results. If the results are true, the THEN instructions are taken; if not, the ELSE instructions are taken

variable

A placeholder for a piece of information that can change

substring

any contiguous sequence of characters in a string

code fragment

are pieces of code that occur regularly in programs and for that reason have been collected for reuse

debugging

finding errors in code and fixing them

What do visuals showing how a certain user interface should appear help?

helps in the design of software

test case

is a set of conditions or variables under which a tester will determine whether a system under test satisfies requirements or works correctly

pseudocode

is a simplified programming language used to develop algorithms and plan for programming

string

is any finite sequence of characters (i.e., letters, numerals, symbols and punctuation marks)

if-statment

The common programming structure that implements "conditional statements"

Which of the following statements accurately describes the functionality of a program? I. When the user clicks "roll" the Yahtzee game displays five random dice. The user then selects any dice they want to keep and clicks "roll" again. This continues until the player has used all three turns. II. A car dealership wrote a program to help their customers find the perfect car. Each car in the lost is represented in the program with variables for the color, make, model, miles, etc. When the user inputs their choices, the program uses a selection sort to narrow down the possible choices for the customer. III. The Rock Paper Scissors program uses nested if statements to determine the winner of any game. A random number generator is used to determine the computer's play. A. I only B. I and II C. II and III D. I, II, and III

Correct Answer: A Explanation: The functionality of a program is best described at a high level; this ,means that the details of the algorithms or specific elements of code that the program uses can be left out. Choice I accurately describes what the program does at a high level. The description is not too technical and is easy to understand. Choices II and III are at a lower level, going into detail of specific algorithms and parts of the code.

Vang is programming some software for a client. Which of the following will best help him understand what the software is supposed to do? A. Visuals showing how the user interface should appear B. the intended outcome of several specific inputs C. Algorithms that might help him write the programs D. Debugging software that will help him find errors

Correct Answer: B Explanation: Answer choice B is the correct answer because testing cases and examples will help Vang understand what the program should actually do

Which of the following would be the best expiation of the functionality of a program? A. The Tic Tac Toe program looks for spots where it can win. If there are no such spots, it checks for spots where it can blocks the player's move. B. The program locates the highest card in the deck by using the binary search algorithm. C. The user calculates their bill by entering the price of each item they plan to purchase. The user then clicks "calculate" to determine the total cost. D. The program asks the user for a word, then translates the word into pig latin. The program does this using the substring procedure and concatenation.

Correct Answer: C Explanation: the functionality of a program is usually described by the war the user interacts with it. Choice C is the only option that explains how the user will interact with the program (by entering and the prices and clicking a button). The other choices explain how the program works, but not how the user interacts with it.

Which of the following variable names would be best for a textbook that the user will use to input his or her name? A. textBox B. name C. textBoxName D. x

Correct Answer: C Explanation: when making variable names it is important that they are descriptive enough that any programmer can tell what they are for. In this instance, Choice C is the more descriptive name. The other choices leave out information.

The following procedure takes four parameters: a full name, a number representing the length of the first name, a number representing the length of the middle name and a number representing the length of the last name. The procedure returns just the middle name. CODE BELOW: PROCEDURE middleNmae (fullName, fLength, mLength, lLength) { RETURN <-- //code needed to replace this comment// END OF CODE So the procedure would return "Marie" if fullName was set to "Jane Marie Smith". Recall how the SUBSTRING method works: CODE BELOW: x<-- "I have not the pleasure of understanding you." x SUBSTRING (1, 10) END OF CODE The above example sets x to "I have not". Which of the following should replace the comment in the middleName procedure so that it works as intended? A. fullName SUBSTRING (flength + 2, fLength + mLenght +2) B. fullName SUBSTRING (flength +2, fLength + mLength + 1) C. fullName SUBSTRING (flength + 1, fLength + mLength + 1) D. fullName SUBSTRING (fLength, fLength + mLength)

Correct Answer: C Explanation: Once again, let's assume that the fullName is set to "Jane Marie Smith". To get the middle name, we would want to start the substring at the index 6. This would be the length of Jane's first name plus 2. Next, we would want to end the substring at index 10. This would be the elgnth of Jane's middle name (5) plus the length of her first name (4) plus 1 (for the space in between the two names). So fullName SUBSTRING(fLength + 2, mlength +flength + 1) would be the correct middle name.

Molly asks Sean to debug her code. She tells him that the code is supposed to take a list of names and return the alphabetically sorted list with any duplicate names in bold. Why will this help Sean debug Molly's code? A. Knowing what the program is supposed to do will help Sean determine what stratifies Molly will have to use to get her code to work. B. Knowing what the program is supposed to do will help Sean determine what algorithms Molly will need to make the code work. C. Knowing what the program is supposed to do will help Sean determine what is wrong with the code. D. Knowing what the program is supposed to do will not help Sean; it's better for him to have "fresh eyes" when looking at the code.

Correct Answer: C Explanation: knowing what the program is supposed to do is necessary for Sean to find the error. There are most likely many different strategies and algorithms that Molly could use to make her code work, so choices A and B are both incorrect. Choice D is also incorrect; while it's important that Sean look at the code with "fresh eyes", he will need to know what the code is supposed to do in order to test it and find the errors

In the creation of programs, what you choose to name the variables is very important. What are the benefits of well-named variables in a program? Select TWO answers. A. the program will run faster B. the program will require less memory C. the program allows others to read it more easily D. the program will be easier to edit and debug

Correct Answer: C and D Explanation: Imagine that you are looking at a program that has three variables: var1, var2, and var3. Without any other information, we cannot guess what the variable stands for. However, if we name the three variables carType, ownerName, and color, we can assume that we are dealing with vehicles, the people who own them, and the color of the vehicle. Because of this, we can quickly find the variable that has an error and debug it.

Audrey is programming a Go Fish game and needs to create a procedure that compares two cards to see if they are a match. The procedure will return a boolean true if the cards match. Which of the following names would be best for this procedure? A. match B. matchCards C. compareTwoCardsForMatch D. checkForMatch

Correct Answer: D Explanation: choice D explains what the procedure does in a concise and clear manner. Choice C explains what the procedure does, but is too long to repeatedly type. Choices A and B are not very descriptive and its hard to tell if they are variables or procedures

Which of the following would be most helpful for someone trying to debug someone else's code? A. A brief description of what the program will be used for B. A list of things the creator of the code thinks might be the problem C. A list of things the creator of code has tried to get the code to work D. A list of example inputs along with the desired outputs

Correct Answer: D Explanation: Choice D will be most helpful because it gives the debugger an idea of what the program is supposed to do. Although Choice A would also help the debugger figure out what is wrong with the code, the test described by choice D would be more helpful for the testing and debugging process. Choice B and Choice C are not ideal because the benefit of having someone else check for errors is that they bring "fresh eyes" to the code. This means the debugger will probably spot the errors that the creator of the code has missed. Therefore the debugger does not need a list of the things the creator of the code thinks they are wrong.

Kylie has created some code designed to keep track of information about employees at a company. The code will be used by the company to create a database of personal information (like home address, phone humber, email address, etc.) and salary information. Since Kylie knows that the company will only need to do a few things with the program, she makes many procedures and variables private so as to "hide" the implementation. This doesn't affect the behavior of the code. What Kylie has done to her program is called... A. data abstraction B. procedural abstraction C. parameterization D. privatization

Correct Answer: data abstraction

Tia is writing a procedure that will find all the even numbers in a list and return the total number of even numbers. Which of the following names would be best for this procedure? A. totalEven B. totalNumberOfEvenNumbers C. even D. total

Correct Answer: totalEven Explanation: Choice A is both clear and concise. It explains that it will total all the even numbers without being too wordy. Choice B on the other hand is much too long to type multiple times. Choice C and D are not clear if they are variables or procedures

Mohamed notices that the same six lines of code appear in his program in multiple places. He writes a procedure that does these six lines of codes, then replaces them in the program with a call to the procedure. Why will this help Mohamed reason through his program later? Select TWO answers. A. The procedure makes those six lines more abstract, so he doesn't have to thing through them each time he comes to them in code. B. The separate procedure will make the program more efficient, spending less time doing the same six lines over and over again. C. If there's an error in the procedure, he can fix the error in the procedure without having to search through his code for each place the procedure is used. D. He will have less code to document, making his program less cluttered and easier to read.

Correct Answers: A and C Explanation: Repeated code makes it difficult to reason through a program. When Mohamed makes the procedure to replace the six lines of code, he has created an abstraction. Once he knows the procedure works as it's sipped to, he can reason through the code without having to get caught on those six lines every time he comes to them. Therefore A is correct. Choice C is also correct because if there is an error in the procedure, he can fix the error in one spot instead of in multiple places throughout the program. Choice B is incorrect because the procedure won't make the code more efficient. Code D is also incorrect because the decrease in documentation will not make a big difference in readability.

conditional statements

Statements that only run under certain conditions

parameter

a named value that is provided as an input to a function ex: CODE BELOW Procedure RobotMove (numMove, numTurn) END OF CODE the words "numMove and numTurn are parameters in which the robot will move and turn different ways based on how much the user wants to move and turn the robot)

procedure

a procedure is a set of coded instructions that tell a computer how to run a program or calculation

parameterization

allows us to pick different values at run in code at one time

loop

code that keeps repeating

pattern recognition

focuses on the recognition of patterns and regularities in code and if patterns are found a function can be made for the repeating code, therefore making the code more concise

program implementation

happens when code is being written

data abstraction

hiding some of the implementation while keeping the behavior of the program unchanged (Programmers might do this to make code easier to read or understand0

Boolean expression

in programming an expression that evaluates to true or false

procedural abstraction

is a mental model of what we want a subprogram to do (but not how to do it)

index (i)

is used to specify the elements of an array of numbers

Does a program require more or less memory simply based on what you name the variables?

no

abstraction

reducing information and detail to focus on essential characteristics. It is typically possible to look at a system at many levels of abstraction, depending on how much detail is necessary to approach the challenge at hand

input

the information put into a set of code

Why is it important for programmers to debug their code in small parts as they go?

whether or not the entire program works depends on whether or not each small part works

collaboration

working with one or more people to create and run code


Related study sets

Nutrition: Chapter 6 Practice Test

View Set

Career & College Exploration Vocabulary

View Set

PrepU test 2 Chapter 21: Nursing Care of the Child With an Alteration in Urinary Elimination/Genitourinary Disorder

View Set

Final final cultural anthropology final

View Set

PH Chapter 7 - Antibacterial Drugs that Disrupt the Bacterial Cell Wall

View Set

Chapter 1 - Introduction to Accounting and Business

View Set

Chapter 19 Study Guide | Exam #3

View Set

Chapter 9 Quiz: Business Cycles, Unemployment, and Inflation

View Set

Cognitive impairments, Delirium, Demenita, Alzheimers-NCLCEX

View Set

1. Chemistry Basics for Food Science

View Set