Unit 3

Ace your homework & exams now with Quizwiz!

Loop

A programming construct that repeats a group of commands.

Parameter

An extra piece of information that you pass to the function to customize it for a specific need.

What is a function parameter? Para-meter: a measure of the distance between a function's conception and implementation. A way to give input to a function that controls how the function runs. A collection of commands that can be used in a programming language. Another name for the purpose of a function. A named memory location.

A way to give input to a function that controls how the function runs.

Which of the following is NOT part of defining a function? Giving the function a name Identifying the parameters of the function Giving the parameters a value Adding code to the body of the function

Giving the parameters a value.

Which of the following statements about writing functions and Top-Down Design is NOT true? Writing functions helps manage complexity in a program. Top-Down Design leads to programs which feature multiple layers of abstraction. Two programmers solving the same problem using Top-Down Design should arrive at identical programs. Top-Down Design relies upon identifying sub-problems of a larger problem. Top-Down Design assists in identifying the layers of functions that will be used to solve a programming problem.

Two programmers solving the same problem using Top-Down Design should arrive at identical programs.

When breaking a problem down, you often encounter elements that you want to use repeatedly in your code. Sometimes it's appropriate to write a new function; at other times it's appropriate to write a loop. There is no hard-and-fast rule as to which is better, but what do you think? What kinds of circumstances would lead you to writing a function versus using a loop?

I think both are equally important. Functions allow for more variability but loops make things faster. You may want to use functions instead of loops when you have one small part of the function such as an angle that you want to alter each time.

Which two statements are true about functions? Meaningful function names help people better understand programs. Meaningful function names help computers better understand programs. Functions in programming are useful mathematical tools for doing complex computations. Functions in programming are named groupings of programming instructions.

Meaningful function names help people better understand programs. Functions in programming are named groupings of programming instructions.

Turtle programming

a classic method for learning programming with commands to control movement and drawing of an on-screen robot called a "turtle." The turtle hearkens back to early implementations in which children programmed a physical robot whose dome-like shape was reminiscent of a turtle.

Low Level Programming Languages

a programming language that captures only the most primitive operations available to a machine. Anything that a computer can do can be represented with combinations of low level commands.

In the Create Performance Task, you will be asked to identify an abstraction in your program and explain how it helps manage the complexity of the program. Functions are a form of abstraction. Pick a function you wrote in your solution to the 3x3 square problem and explain how it helps manage the complexity of your program.

I created a function that drew one of the rows of squares within the large square. This function condensed multiple steps into one single step and me the program less complex because it did not contain as many small details.

Which of the following blocks is least similar to the others? A. penUp () B. dot (radius) C. arcLeft (angle, radius) D. penWidth (width)

C. arcLeft (angle, radius)

A programmer wants to write a program in which the turtle draws 8 squares in a row while moving forward. The final result should look like this: https://images.code.org/59b3db519d6507b71fdf0670eeb98ab2-image-1443129607058.png But something is wrong! The incorrect code is shown below. The programmer has attempted to write a function to draw a single square. Then he wrote another function that attempts to call that function 8 times. Mentally trace through the code and determine which line of code should be removed to make the program do what it's supposed to. https://images.code.org/792ec4d5f8919808ea47ec657c969314-image-1443129807227.png Which line of code should be removed to make the program do what it's supposed to? 1 5 6 7 14

7

Hexadecimal

A base 16-number system that uses sixteen distinct symbols 0-9 and A-F to represent number from 0-15

Library

A collection of commands/functions, typically with a shared purpose.

Documentation

A description of behavior of a command, function, library, API, etc.

Selection

A generic term for a type of programming statement (usually an if statement) that uses a Boolean condition to determine, or select, whether or not to run a certain block of statements.

Consider these various uses of randomNumber. Each answer describes the use and shows a code example. Which one of the following is NOT a valid use of randomNumber Calling the parameters of a function Defining the parameters of a function Moving the turtle around the screen Orienting the direction of the turtle Setting pen properties None of the above

Calling the parameters of a function Defining the parameters of a function Moving the turtle around the screen Orienting the direction of the turtle Setting pen properties None of the above

Consider the figure below. Use top-down thinking to design a solution to the problem. In the space provided write a list of just the names of the functions that you would write in a program that draws this figure. (Assume that the long line segments are 6 turtle moves long). https://images.code.org/43895f8ceccb12f72e7f5ba03152a6e6-image-1441914144956.png

turnRight, drawLongline, drawShortline

Function

A named group of programming instructions. Functions are reusable abstractions that reduce the complexity of writing and maintaining programs.

Select the two true statements about functions with parameters Parameters can only be used once within the body of a function. Functions with parameters can be used to prevent the creation of duplicated code. Parameters help generalize the solution of a specific problem. Values do not need to be provided to a function with parameters in any particular order.

Parameters help generalize the solution of a specific problem.

In your own words, explain at least one reason why programming languages have functions. Include an example of something you did in this lesson that demonstrates the reason you describe.

Programming languages have functions in order to group together many commands. The functions save time and energy because there are less commands to remember that way and it takes less time to input one function compared to multiple commands. For example, it would take me a very long time and a lot of lines to have completed that diamond shape, but by using functions I was able to only input very few things and reach the same solution.

It is said that functions with parameters generalize the behavior of a more specific command and allow programmers to use functions instead of duplicated code. Explain what this means to you using the difference between turnLeft() and turnLeft(angle) as an example.

The turnLeft(angle) allows you to be more specific than the turnLeft() command. It allows you to have more control because you can input the number of degrees which the turtle rotates to the left while the command without the parameters automatically rotates the turtle to the left 90 degrees. Without the parameters, you would have to use multiple commands to get the turtle to function exactly the way you want it to. For example, if you wanted the turtle to turn around all you would have to do is input turnLeft(180) instead of having to input turnLeft() twice.

Iterate

To repeat in order to achieve, or get closer to, a desired goal.

What is an API? Read the definitions provided below and then choose the best answer. Abstract Programming Inheritance - The idea that abstractions in languages get "passed down" in newer versions. Artificial Parameter Intelligence - The idea that function parameters should be intelligent enough to "know" what you want as a programmer. Application Program Interface - A well-documented library of functions provided in a programming language that helps to simplify complex programming tasks. Applied Power Implementation - A process by which functions are given extra override power related to parameters. Abstract Parameter Interface - A programming construct in which parameters are passed down through levels of abstraction.

Abstract Programming Inheritance Artificial Parameter Intelligence Application Program Interface Applied Power Implementation Abstract Parameter Interface

Which of the following blocks is least similar to the others? A. moveTo (x,y) B. turnLeft (angle) C. arcRight (angle,radius) D. moveForward (pixels)

B. turnLeft (angle)

For loops

A particular kind of looping construct provided in many languages. Typically, a for loop defines a counting variable that is checked and incremented on each iteration in order to loop a specific number of times.

Algorithm

A precise sequence of instructions for processes that can be executed by a computer and are implemented using programming languages.

High Level Programming Language

A programming language with many commands and features designed to make common tasks easier to program. Any high level functionality is encapsulated as combinations of low level commands.

Abstraction

A simplified representation of something more complex. Abstractions allow you to hide details to help you manage complexity, focus on relevant concepts, and reason about problems at a higher level.

Which of the following is NOT a true statement about functions? Functions are reusable programming abstractions. Functions help reduce the complexity of writing and maintaining programs. Functions help break a problem into logical chunks. Once defined, a function can be called many times from different parts of a program. Functions cannot make calls to other functions written by the same programmer.

Functions cannot make calls to other functions written by the same programmer.

Understand the following points/concepts:

The number of defined words in a programming language is very small compared to the number of words in a natural language. Natural language is ambiguous compared to programming languages. Functions are reusable, reduce complexity, break problems into logical chunks, and can be called many times from different parts of a program. Function names should be descriptive and meaningful. Function names help people better understand programs, not computers. Multiple functions in a single program can have identical code as long as their names are different. Multiple programmers working on the same problem do not have to arrive at identical programs. In order to call a function, you must type the function name followed by parentheses and a semicolon. Parameters allow flexibility and generalized behaviors in functions. They also prevent the creation of duplicated code. Know how to read program code and trace its behavior. Programmers that are collaborating do not have to know the specific details of each other's functions. They just need to rely on the functionality. This promotes collaboration through abstraction. In order to define a function one must do the following: give the function a name, identify parameters, and add code to the body of the function.

Below is a segment of code from an "under the sea" program with a rectangle drawn around a portion of the code identifying an abstraction. Imagine that you wrote this and are composing an AP response about how this abstraction manages complexity. (Note: ignore the requirement that the abstraction integrate "mathematical and logical concepts" for this practice response. Just write about managing complexity). https://images.code.org/d98fa58fce78eff86fd734f32e2960e4-image-1507913593511.png Explain how the abstraction marked with the rectangle in the code above helps manage complexity of this program.

This abstraction combines multiple commands and parameters that could possibly be used to draw a fish and combines it into one function. The use of the parameters even allows you to use this function in many cases to draw fish that are multiple colors and sizes by still only using one function. This limits the lines of code you have to input.

API

A collection of commands made available to a programmer.

Top Down Design

A problem solving approach (also known as stepwise design) in which you break down a system to gain insight into the sub-systems that make it up.

"Abstraction" is often used to focus on a general case and ignore a specific instance of a problem. Given this meaning of the word, how are functions with parameters an example of abstraction?

Functions with parameters allow you to use a broad function even when cases of specificity are needed. For example, when you are creating the function you can put "size" or "width" in as parameters. These are very general. When you get to calling a function, you can then input the values that make the size and width you are talking about more specific. Even though you are being specific when doing this, you are still using a variation of a function which can be used in multiple instances and condenses many lines of code.

In this lesson we talked about how to build up solutions to larger programming problems with functions. Plan the code that you would use to draw this image (shown at right). Describe each of the functions that you would create. You should not write all the code, only the names of the functions that you would create with a brief description of what each function would do. Write your plan following the format: Name of function - description of what it does Name of function 2 - description of what it does ...

First I would create some very basic functions to make construction of the shape faster: turnRight - the turtle would turn right moveForward(n) spaces - the turtle would move forward multiple spaces at a time turnAround - the turtle would turn around 180 degrees Then I would use these functions as well as the other basic ones to create a broader function: drawSide - this function would draw one side of the shape. I would then combine this function with itself and some other small ones multiple times to create all of the sides: drawShape - this would draw the entire image.

Describe, using a top-down approach, how you would create a program to draw a white snowflake on a blue background that uses random numbers, so the snowflake will be unique every time you run the code. You don't need to write the exact code or blocks that you would use, but you should describe what functions you would need to create, where you would or would not use loops, and where you would or would not use random numbers.

First I would write the code to make the background blue. Then I would write the code to make the body of the snowflake using a function that contained commands to turn left and right and move a certain number of pixels. This function would also contain commands for the pen width, color, and size of the body of the snowflake. I would not use a random number here because I would want the body to be one size so that i would know that the snowflake would always fit on the page and look proportional. I could use a loop to repeat the drawing of the sides of the body of the snowflake. After the function for the body was made, I would create one to draw the branches of the snowflake. It would include commands to move forward and turn to a certain angle. I could loop this drawBranch function so many branches would be all around the body of the snowflake. In the loop, I could include a random number for the amount of times the loop would be iterated that way there would always be different numbers of branches on the snowflake.

Sequencing

Putting commands in correct order so computers can read the commands.

Here's the scoring guide for this question https://images.code.org/341764b27f16965cf27680e20c893a23-image-1508190677805.50.59%20PM.png The program code below is from a program a student developed. https://images.code.org/86d48cfc2c9c81551aa059281e9c62f3-image-1508189804595.34.48%20PM.png Write which of the rectangles (A, B, C, or D) is placed around a student-developed abstraction. Then explain your answer using the criteria in the scoring guide.

Rectangle D is placed around the abstraction because it is around a function that condenses multiple lines of code into one. Rectangle A is a command. Rectangle B is a call to the function in rectangle D, and rectangle C is a for-loop.


Related study sets

Week 10 BSN 346 Substance Misuse in Pregnancy

View Set

Computer Science Essentials: QUIZ 3/1/18 Price Per Slice

View Set

Parts of Speech: Gerunds, Participles, and Infinitives

View Set