Lecture5_6 - Lecture 5 - Functions ECE 3090 Software for...

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

View Full Document Right Arrow Icon
ECE 3090 Software for Engineering Systems Dr. Ayanna Howard School of Electrical and Computer Engineering Georgia Institute of Technology Lecture 5 - 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
2 Adapted from “Brief Version of Starting Out with C++” Modular Programming Modular programming : breaking a program up into smaller, manageable functions or modules Function : a collection of statements to perform a task Motivation for modular programming: Improves maintainability of programs Simplifies the process of writing programs
Background image of page 2
3 Adapted from “Brief Version of Starting Out with C++” Defining and Calling Functions Function call : statement causes a function to execute Function definition : statements that make up a function Function Definition includes: return type: data type of the value that function returns to the part of the program that called it name: name of the function. Function names follow same rules as variables parameter list: variables containing values passed to the function body: statements that perform the function’s task, enclosed in {}
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 Adapted from “Brief Version of Starting Out with C++” Function Definition Note: The line that reads int main() is the function header.
Background image of page 4
5 Adapted from “Brief Version of Starting Out with C++” Function Return Type If a function returns a value, the type of the value must be indicated: int main() If a function does not return a value, its return type is void : void printHeading() { cout << "Monthly Sales\n"; }
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 Adapted from “Brief Version of Starting Out with C++” Calling a Function To call a function, use the function name followed by () and ; printHeading(); When called, program executes the body of the called function After the function terminates, execution resumes in the calling function at point of call.
Background image of page 6
7 Adapted from “Brief Version of Starting Out with C++” Calling Functions main can call any number of functions Functions can call other functions Compiler must know the following about a function before it is called: name return type number of parameters data type of each parameter
Background image of page 7

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

View Full DocumentRight Arrow Icon
8 Adapted from “Brief Version of Starting Out with C++” Function Prototypes Ways to notify the compiler about a function before a call to the function: Place function definition before calling function’s definition Use a function prototype (function declaration ) – like the function definition without the body Header: void printHeading() Prototype: void printHeading();
Background image of page 8
9 Adapted from “Brief Version of Starting Out with C++”
Background image of page 9

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

View Full DocumentRight Arrow Icon
10 Adapted from “Brief Version of Starting Out with C++” Prototype Notes Place prototypes near top of program Program must include either prototype or full function definition before any call to the function – compiler error otherwise When using prototypes, can place function definitions in any order in source file
Background image of page 10
11 Adapted from “Brief Version of Starting Out with C++”
Background image of page 11

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

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

This note was uploaded on 06/09/2009 for the course ECE 3090 taught by Professor Staff during the Fall '08 term at Georgia Institute of Technology.

Page1 / 118

Lecture5_6 - Lecture 5 - Functions ECE 3090 Software for...

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

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