208 Day 13 Functions3

208 Day 13 Functions3 - 4002-208 Intro. to Prog. [in C+]...

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

View Full Document Right Arrow Icon
4002-208 Intro. to Prog. [in C++] Day 13 Yet More on Functions
Background image of page 1

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

View Full DocumentRight Arrow Icon
Objectives Review of Functions Storage classes Scope Rules Separate Compilation using projects 4002-208 2
Background image of page 2
Writing a function Function header Return type or void if no return type Name of function ( 0 or more parameters separated by commas ) Examples double doIt(int x, double y) void doSomething(double a, int n) 4002-208 3
Background image of page 3

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

View Full DocumentRight Arrow Icon
Writing a function (cont.) Function body { Block of code } If a function has a return type, there must be a return statement return expression_to_be_returned ; If a function has void return type, the } acts as the end of the function or a return; 4002-208 4
Background image of page 4
Function Prototype Functions normally placed at top of file before all functions. Declares a function to the compiler so that it knows how to use it correctly. Examples double doIt(int , double ); void doSomething(double , int ); 4002-208 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
Calling a Function Name of function ( Actual arguments separated by commas ) Examples: double x, y, z; int n, m; doIt( x, 7.5) doSomething(x+y, n+m-2) 4002-208 6
Background image of page 6
Calling a Function Returning a Value If the function returns a value, call in an assignment statement, condition, output Examples double x, y, z; int n, m; z = doIt(x, 7.5) - doIt(y, z); if ( doIt(x, 7.5) > 0.0 ) cout << "results is " << doIt(x, 7.5) << endl; doIt(x, y); 4002-208 7
Background image of page 7

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

View Full DocumentRight Arrow Icon
Calling a Function No Return Value If the function returns no value, call the function as a separate statement.
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/31/2009 for the course NSSA 4002 208 taught by Professor Niemi during the Spring '09 term at RIT.

Page1 / 29

208 Day 13 Functions3 - 4002-208 Intro. to Prog. [in C+]...

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

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