P.Lecture - 2.7.08 - Announcements Assignment 2 due today!...

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

View Full Document Right Arrow Icon
Announcements • Assignment 2 due today! •Exam 1 next Thursday –50 minute exam (9:30 – 10:20) • Topics for today nctions Functions –Scope of variables 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
Functions in a Nutshell •A named collection of statements •S o m e w h a t like mathematical functions: y = f(x) –A r g um e n t s are not required –D o e s not need to return a value (similar to a procedure in other languages) but can • Functions are like “mini programs” called by name –d e c l a r a t i o n s body • Previously written standard functions are in the library for your use • You can write your own functions too 2
Background image of page 2
A Function as a Module in Subprocess/ out lues sent in Resultant values returned, subprogram values sent in from function calling statement or function actions have me other function via arguments (optional) some other effect As in, for example: double y = sqrt (x); double y = square_it (x); tchar ( ); 3 getchar ( );
Background image of page 3

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

View Full DocumentRight Arrow Icon
C Standard Library Functions •See appendix D • In various header files (.h) – stdlib – stdio –math – time – ctype ring – string –assert few others 4 a few others
Background image of page 4
Top Down Functional Programming ain main calls sub1 sub2 sub3 sub4 lls lls subsub1 subsub2 subsub3 subsub4 calls calls sss1 sss4 calls 5
Background image of page 5

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

View Full DocumentRight Arrow Icon
How does this work? • Partitioning the problem –Le t s us divide a big problem into small problems –No one part is highly complex –Mu s t balance having too many and too few functions •Too few leads to complexity of the size of each •Too many leads to complexity of the number of interconnects any ways to partition a problem Many ways to partition a problem –one of the fundamentals of the craft of design nctions are key to Functions are key to – Reducing complexity – Increasing clarity 6 – Increasing reusability
Background image of page 6
Function Mechanics Functions allow us to modularize and encapsulate the processes of our programs. This is key to handling complexity.
Background image of page 7

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

View Full DocumentRight Arrow Icon
Defining a Function • Function operates on data passed through the parameter list • Function either returns a value computed or causes some action to occur • Called by name from some other function (e.g., main) • Function definition consists of a header and a body inside { } nction Header Function Header –H a s a return data type (such as int, double, char or void) a s a function name (such as squareIt) as a list of formal parameters (such as: double amount) Has a list of formal parameters (such as: double amount) •a parameter is a local variable declaration for an argument value to be sent into the function from the calling statement nction body Function body { // the set of declarations and statements that defines the implementation } nction prototype Function prototype –I s a function header that must appear before its use (compiler requirement)
Background image of page 8
Function Definition (cont) ntax of a function definition: Syntax of a function definition: return type function name ( parameter list ) { declarations statements } Parameter list ch
Background image of page 9

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

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/22/2008 for the course EE 312 taught by Professor Shafer during the Spring '08 term at University of Texas at Austin.

Page1 / 36

P.Lecture - 2.7.08 - Announcements Assignment 2 due today!...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online