{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# Lec9 - 9 User-Defined Functions Input parameters Local...

This preview shows pages 1–13. Sign up to view the full content.

9. User-Defined Functions Input parameters Local Variables Output Values

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Why? 1. Elevates reasoning by hiding details. 2. Facilitates top-down design. 3. Software management.
Elevates Reasoning Nice to have sqrt function when designing a quadratic equation solver. You get to think at the level of ax 2 + bx + c = 0

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Elevates Reasoning Easier to understand the finished quadratic equation solving code: : r1 = (-b+sqrt(b^2-4*a*c))/(2*a); r2 = (-b-sqrt(b^2-4*a*c))/(2*a); :
Facilitates Top-Down Design

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Facilitates Top-Down Design 1. Focus on how to draw the flag given just a specification of what the functions DrawRect and DrawStar do. 2. Figure out how to implement DrawRect and DrawStar.
To Specify a Function… You describe how to use it, e.g., function DrawRect(a,b,L,W,c) % Adds rectangle to current window. % Assumes hold is on. Vertices are % The color c is one of 'r‘,'g', %'y','b','w','k','c',or 'm'.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
To Implement a Function… You write the code so that the function works. I.e., code that “lives up to” the specification. E.g., x = [a a+L a+L a a]; y = [b b b+W b+W b]; fill(x,y,c); Not to worry. You will understand this soon.
Software Management Today: I write a function EPerimeter(a,b) that computes the perimeter of the ellipse 1 2 2 = + b y a x

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Software Management During the Next 10 years : You write software that makes extensive use of EPerimeter(a,b) Imagine 100’s of programs each with several lines that reference EPerimeter
Software Management After 10 years : I discover a more efficient way to approximate ellipse perimeters. I change the implementation of EPerimeter(a,b) You do not have to change your software at all.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Example 1. MySqrt(A)
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 50

Lec9 - 9 User-Defined Functions Input parameters Local...

This preview shows document pages 1 - 13. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online