{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

C__DOCUME~1_MAXWID~1_LOCALS~1_Temp_plugtmp-27_lecture08_functions1

C__DOCUME~1_MAXWID~1_LOCALS~1_Temp_plugtmp-27_lecture08_functions1

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

View Full Document Right Arrow Icon
1 ee312 Spring 2008 Lecture 8 1 Announcements Lecture 8 Functions from Chapter 9 Review Exercises from the text Topics for today – functions ee312 Spring 2008 Lecture 8 2 Review for Exam 1 Review the following chapter questions for Exam 1: 1. Chapter 2 - 7, 11 2. Chapter 3 - 3, 7 3. Chapter 4 - 5, 7 4. Chapter 5 - 1, 9 5. Chapter 6 - 7, 15 6. Chapter 7 - 5, 13 7. Chapter 8 - 1, 3, 5, 9 8. Chapter 9 - 1, 7, 9 9. Chapter 10 - 1, 3, 5
Background image of page 1

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

View Full Document Right Arrow Icon
2 ee312 Spring 2008 Lecture 8 3 Functions in a Nutshell A named collection of statements Somewhat like mathematical functions: y = f(x) Arguments are not required Does not need to return a value (similar to a procedure in other languages) Functions are like “mini-programs” called by name – declarations – body Previously written standard functions are in the library for your use You can write your own functions too ee312 Spring 2008 Lecture 8 4 C Standard Library Functions See appendix D In various header files (.h) – stdlib – stdio – math – time – ctype – string – assert – a few others #include <math.h> . . . float x; . . . If (ceil (x) ! = ceil (x+.5)) x = (int) (x + .5); else x = (int) x; What does this do?
Background image of page 2
3 ee312 Spring 2008 Lecture 8 5 Top Down Functional Programming main sub1 sub2 sub3 sub4 subsub1 subsub2 subsub3 subsub4 sss1 sss4 calls calls calls calls ee312 Spring 2008 Lecture 8 6 How does this work? Chunking the problem Let’s us divide a big problem into small problems No one part is highly complex However a balance must be achieved between too many and too few functions Too few complexity of the size of each Too many complexity of number and interconnects Many ways to divide a problem this is one of the fundamentals of the craft of design Functions are key to Reducing complexity Increasing clarity
Background image of page 3

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

View Full Document Right Arrow Icon
4 ee312 Spring 2008 Lecture 8 7 Complexity Complexity – of detail, of logic, of interconnections When is something too complex? When it is difficult for your audience to comprehend When it’s too difficult for you to solve What increases complexity ? Too much or too little context functions – Unfamiliarity idioms / design patterns Complicated logic explanatory comments Excessive coupling and side effects functional encapsulation Elegance - a quality of ingenious simplicity and clarity in the solution of a problem Function Mechanics Functions allow us to modularize and encapsulate the processes of our programs. This is key to handling complexity.
Background image of page 4
5 Defining a Function (1) A function operates on data passed through the parameter list, and either returns a value computed or causes some action to occur It is called by name from some other function. The definition of the function consists of a header and a body inside of the { } Function Header Has a return value type (such as double or void) Has a function name (such as squareRoot) Has a list of formal parameters (such as double amount) • a parameter is a local variable declaration for an
Background image of page 5

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

View Full Document Right Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}