Overview
This lesson will introduce you to nonmember (free) functions in C++. You will
learn about function prototypes, function headings, and how to
use a function.
Objectives
By the end of this lesson, you will be able to:
- use existing & user-defined functions in your programs
- declare a function by writing a function prototype
- define and identify
- function prototype
- function signature
- function header
- function body
- parameter-list
- argument
- return value
- call a function using pass-by-value arguments
- assign default values to function parameters
Readings
- Mercer Chapter 3
- Sections 3.1 and 3.2 show you how to use existing C++ functions,
primarily from the cmath library. Section 3.3 introduces the use of
function headings What the book calls a function heading, most other
authors (and I) call a function prototype. You turn a function
heading into a function prototype by adding a ; to the end of the function
heading. This is the method we will be using in this class,
complete with pre- and post- conditions.
Functions
Functions
Tutorial (an alpha site)
Functions Handout
Class Prep
Complete Exercises 4 and 6 on page 100 of the Mercer text. Write
the function heading, including pre- and post conditions, for Exercise 6.
Examples
Functions
Martian Conversion
|