This preview shows pages 1–8. Sign up to view the full content.
C++ Programming:
Program Design Including
Data Structures,
Second Edition
Chapter 6: UserDefined Functions I
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document C++ Programming: Program Design Including Data Structures, Second Edition
2
Objectives
In this chapter you will:
•
Learn about standard (predefined) functions
•
Learn about userdefined functions
•
Examine valuereturning functions, including
actual and formal parameters
•
Explore how to construct and use a value
returning, userdefined function in a program
C++ Programming: Program Design Including Data Structures, Second Edition
3
Functions
•
Functions
−
Called modules
−
Like miniature programs
−
Can be put together to form a larger program
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document C++ Programming: Program Design Including Data Structures, Second Edition
4
Predefined Functions
•
Some of the predefined mathematical functions
are:
−
sqrt(x)
−
pow(x,y)
−
floor(x)
•
Predefined functions are organized into
separate libraries
•
I/O functions are in iostream header
•
Math functions are in cmath header
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document C++ Programming: Program Design Including Data Structures, Second Edition
6
UserDefined Functions
•
Void functions
: do not have a data type
•
Valuereturning functions
: have a data type
•
To use these functions you need to:
−
Include the correct header file
−
Know the name of the function
−
Know the number of parameters, if any
−
Know the data type of each parameter
−
Know the data type of the value computed by
the function, called the type of the function
C++ Programming: Program Design Including Data Structures, Second Edition
7
ValueReturning Functions
•
Because the value returned by a value
returning function is unique, we must:
−
Save the value for further calculation
−
Use the value in some calculation
−
Print the value
•
A valuereturning function is used in an
assignment or in an output statement
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.
This note was uploaded on 12/03/2010 for the course COP 1334 taught by Professor Cooper during the Fall '10 term at Miami Dade College, Miami.
 Fall '10
 cooper
 C++ Programming

Click to edit the document details