CS31-3

# CS31-3 - CS 31 Introduction To CS I 9/2009 John A Rohr All...

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

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

View Full Document

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

View Full Document

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

View Full Document

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

View Full Document

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

View Full Document

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

View Full Document

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS 31: Introduction To CS I 9/2009 John A. Rohr All Rights JAR 3-1 CS 31 : Introduction to Computer Science I Topic 3 Functions CS 31: Introduction To CS I 9/2009 John A. Rohr All Rights 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 9/2009 John A. Rohr All Rights JAR 3-3 Functions Function Characterization • Accomplishes one thing • May use other functions • May produce a result • Sequence of statements CS 31: Introduction To CS I 9/2009 John A. Rohr All Rights 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 9/2009 John A. Rohr All Rights 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 CS 31: Introduction To CS I 9/2009 John A. Rohr All Rights JAR 3-6 Functions Function Processing • Apply defined algorithm • Use inputs • Generate outputs CS 31: Introduction To CS I 9/2009 John A. Rohr All Rights JAR 3-7 Functions Function Example • Square Root • Input: Value: 9 • Processing: Calculate square root • Output: Square root of value: 3 CS 31: Introduction To CS I 9/2009 John A. Rohr All Rights 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 9/2009 John A. Rohr All Rights JAR 3-9 Functions Function Definition Types • Predefined functions – Function library – Commercial product – Other programmers • Programmer defined functions – Written by programmer CS 31: Introduction To CS I 9/2009 John A. Rohr All Rights 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 9/2009 John A. Rohr All Rights JAR 3-11 Functions C++ Predefined Functions • Provided by the compiler • Organized in libraries • Referenced by #include statements • Included in program using #include CS 31: Introduction To CS I 9/2009 John A. Rohr All Rights JAR 3-12 Functions Some Predefined Libraries • iostream Stream input and output • cmath Mathematical functions • cstdlib Some standard functions • cctype Character operations • string String capabilities CS 31: Introduction To CS I 9/2009 John A....
View Full Document

{[ snackBarMessage ]}

### Page1 / 97

CS31-3 - CS 31 Introduction To CS I 9/2009 John A Rohr All...

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

View Full Document
Ask a homework question - tutors are online