unit 3 lesson 4-9

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

abstraction

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

Select the two true statements about functions with parameters:

- functions with parameters can be used to prevent the creation of duplicated code - parameters help generalize the solution of a specific problem

choose the two (2) statements that are true about functions

- meaningful function names help people better understand programs - functions in programming are named groupings of programming instructions

pick a function you wrote in your solution to the 3x3 square problem and explain how it helps manage the complexity of your program.

three drawSquare would make drawStack and a couple moveForward

which of the following blocks is least similar to the others?

turnLeft (angle)

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.

turnLeft (angle) is an example of a parameter that allows for one to create a more efficient picture by using specific angle measurements the turtle should turn. turnLeft() is redundant and is non-efficient. It just allows for the programmer to repeat themselves over and over again.

which of the following statements about writing functions and Top-Down Design is NOT true?

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

Which line of code should be removed to make the program do what it's supposed to?

7

briefly describe how the code for drawing a rectangle would be different than drawing a square.

A square has the same side lengths and so the code would be redundant. For a rectangle, side lengths are different and so different amounts of "move forwards" would be used.

in 1-2 sentences, explain what you think the following code does.

The code creates a dot with an opacity of 0.5. The loop will run 100 times, and each time the size, location, and color is random

in what ways is the meaning of "efficiency" the same? In what ways is it different?

Efficiency in programming is how fast and small something is coded and the amount of time it takes for the code to run. In the real world, "efficiency" is used when explaining how fast you can manage your time correctly. Furthermore, it can be used to manage time or programming used to help manage how fast the computer can encode things.

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.

First, I would make the background with a large blue dot. Then, I would change the pen color and write code to draw one "branch" of the snowflake. The numbers determining the length of the different pieces would be a parameter. In a loop, I would repeat the previous code enough times to create a snowflake (5 or 6 times). When I call the function in the loop, I would set the length parameter to a random number. That way, each side would be the same length, but each snowflake would be different.

how are functions with parameters an example of abstraction?

Functions with parameters allows you to use a function even when cases of specifics are needed. When creating functions, one can put "size" and "width" in as parameters. They are very general. When you get to call the function, you can input values that are making the size and width more specific.

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 prefer to use the same bits of code I previously wrote as many times as I can, so I am able to get the most use out of what I am coding. I find myself considering writing a new version of that code if I find myself getting stuck with the problem of no being able to tell what is what in the code any longer.

2d. Capture and paste a program code segment that contains an abstraction you developed individually on your own (marked with a rectangle). The abstraction must integrate mathematical and logical concepts. Explain how your abstraction helped manage the complexity of your program. (Must not exceed 200 words)

I would give this student 1 point. Although they thought explain how the abstraction affects the code, the abstraction they refer to was not developed by them. The arcRight command is already established by code.org, which is the fist bullet point in row seven. That being said, row 8 was carried out well and does not go against the guidelines.

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 demonstrates a student-developed abstraction, because it is comprised of a function that the student defined themself and then called in the program. This section is not an existing piece of code and it is explicitly identified.

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). Explain how the abstraction marked with the rectangle in the code above helps manage complexity of this program

The abstraction helps mange complexity of this program by using multiple commands and parameters that could be used to draw the fish and combine it into one function. The function of the parameter allows you to use the function to draw fishes that are multiple colors and sizes by still only using one function. This will help condense the lines of code you input.

give at least one reason why it's useful to learn how to solve and program solutions with a limited set of commands.

There are only a limited amount of commands that can be used with certain coding language. By learning how to use limited commands in unique ways can help understand different coding language.

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.

Turn left - turn the turtle left Turn right - turns the turtle to the right turn around - turns the turtle fully around move forward - moves the turtle forward draw side - draws one complete side, made of the above functions draw figure - calls the above function 4 times, turning the turtle each time

Try to write a response to this AP Prompt thinking about either how you developed the idea for the snowflake drawing program, or how you resolved to make the 3x3 grid program. You might have to use a little bit of imagination to assume that it's part of a larger program you created yourself. The point is to practice writing about your development process.

When writing programming for a three-by-three grid, I used top-down design. I figured out how to make one square, and then connected them into a row. I then combined three of the row commands to form the grid. While doing this, I realized that I couldn't just repeat the row command three times, because it would form a nine-by-one rectangle. So, I added some moveForward and turn functions in between the repeated code. Then, using the moveForward and turn functions, I moved the turtle back to where it was at the beginning of the programming. Since the turtle started in a new position every time, it was hard to repeat code and have it act the same way. My partner suggested returning it to similar position each time, which helped fix this problem.

library

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

API

a collection of commands made available to a programmer

documentation

a description of the behavior of a command, function, library, API

function

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

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

what is a function parameter?

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

application program interface

a well-documented library of functions provided in a programming language that helps to simplify complex programming tasks

parameter

an extra piece of information passed to a function to customize it for a specific need

which of the following blocks is least similar to the others?

arcLeft (angle, radius)

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

defining the parameters of a function

which of the following is NOT a true statement about functions?

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

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.

longLine(); shortLine(); right();

for loop

loops that have a predetermined beginning, end, and increment (step interval).

loop

the action of doing something over and over again


Kaugnay na mga set ng pag-aaral

Sports Communication and Public relations

View Set

Pharmacology of gastric acid secretion

View Set

Mis 301 Section K midterm exam study guide

View Set

Chapitre 1 : Entraînement sur les Termes et Concepts

View Set