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

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

View Full Document Right Arrow Icon
9. User-Defined Functions Input parameters Local Variables Output Values
Background image of page 1

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

View Full DocumentRight Arrow Icon
Why? 1. Elevates reasoning by hiding details. 2. Facilitates top-down design. 3. Software management.
Background image of page 2
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
Background image of page 3

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

View Full DocumentRight Arrow Icon
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); :
Background image of page 4
Facilitates Top-Down Design
Background image of page 5

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

View Full DocumentRight Arrow Icon
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.
Background image of page 6
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'.
Background image of page 7

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

View Full DocumentRight Arrow Icon
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.
Background image of page 8
Software Management Today: I write a function EPerimeter(a,b) that computes the perimeter of the ellipse 1 2 2 = + b y a x
Background image of page 9

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

View Full DocumentRight Arrow Icon
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
Background image of page 10
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.
Background image of page 11

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

View Full DocumentRight Arrow Icon
Example 1. MySqrt(A)
Background image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/28/2008 for the course CS 100 taught by Professor Fan/vanloan during the Fall '07 term at Cornell University (Engineering School).

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 Right Arrow Icon
Ask a homework question - tutors are online