# CS31-3 - CS 31 Introduction to Computer Science I Topic 3...

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

CS 31: Introduction To CS I Topic 3: Functions 1/2010 John A. Rohr All Rights Reserved JAR 3-1 CS 31 : Introduction to Computer Science I Topic 3 Functions

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

View Full Document
CS 31: Introduction To CS I Topic 3: Functions 1/2010 John A. Rohr All Rights Reserved JAR 3-2 Functions Function Definition A function is a single unit of computation Other words for function Procedure Method Subprogram (that returns a value)
CS 31: Introduction To CS I Topic 3: Functions 1/2010 John A. Rohr All Rights Reserved JAR 3-3 Functions Function Characterization Accomplishes one thing May use other functions May produce a result Sequence of statements

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

View Full Document
CS 31: Introduction To CS I Topic 3: Functions 1/2010 John A. Rohr All Rights Reserved JAR 3-4 Functions Function Inputs Called “arguments” or “actual parameters” Provides values for calculation Not needed by all functions Display text Generate random number
CS 31: Introduction To CS I Topic 3: Functions 1/2010 John A. Rohr All Rights Reserved JAR 3-5 Functions Function Outputs Called the “return value” Reports the results of the processing Not produced by all functions Functions that perform an action only

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

View Full Document
CS 31: Introduction To CS I Topic 3: Functions 1/2010 John A. Rohr All Rights Reserved JAR 3-6 Functions Function Processing Apply defined algorithm Use inputs Generate outputs
CS 31: Introduction To CS I Topic 3: Functions 1/2010 John A. Rohr All Rights Reserved JAR 3-7 Functions Function Example Square Root Input: Value: 9 Processing: Calculate square root Output: Square root of value: 3

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

View Full Document
CS 31: Introduction To CS I Topic 3: Functions 1/2010 John A. Rohr All Rights Reserved JAR 3-8 Functions Two Function Dichotomies Function definition dichotomy Predefined functions Programmer-written functions Function return value dichotomy void Typed (int, float, double, char, bool, etc.)
CS 31: Introduction To CS I Topic 3: Functions 1/2010 John A. Rohr All Rights Reserved JAR 3-9 Functions Function Definition Types Predefined functions Function library Commercial product Other programmers Programmer defined functions Written by programmer

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

View Full Document
CS 31: Introduction To CS I Topic 3: Functions 1/2010 John A. Rohr All Rights Reserved JAR 3-10 Functions Function Return Value Types Functions that return a value (typed) Perform a calculation (e.g. Square root) Deliver (return) the result Functions that do not return a value (void) Perform an action (e.g. set an output format) Do not have a result to return
CS 31: Introduction To CS I Topic 3: Functions 1/2010 John A. Rohr All Rights Reserved JAR 3-11 Functions C++ Predefined Functions Provided by the compiler Organized in libraries Referenced by #include statements Included in program using #include

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

View Full Document