Programmer Defined Functions
Programmer Defined Functions
org/modularity/
FUNCTIONS
Programmer-defined Functions
(SLGs 7.1, 7.2.1-7.2.3)
1 / 12
Functions: Classification
●
Predefined Function / Built-in Function
– C++ comes with libraries of predefined
functions that you can use in your
program.
Arithmetic, character, string,
●
trigonometric, etc.
●
Programmer-defined Function / User-
defined Function
2 / 12
Predefined / Built-in Function
●
What library to include
– #include <header_file>
●
Name of the function
●
Number of arguments and data type of each
argument
●
Data type of the return value
3 / 12
Predefined / Built-in Function
●
Some predefined math function in the library
<cmath>
4 / 12
Predefined / Built-in Function
5 / 12
Functions: Classification
●
Predefined Function / Built-in Function
●
Programmer-defined Function / User-
defined Function
6 / 12
Programmer-defined Function
●
void Function
argument(s)
●
Value-returning Function
7 / 12
Programmer-defined Function
●
Method 1
//function declaration
int main()
{
//statements
return 0;
}
//function definition
8 / 12
Programmer-defined Function
●
Method 2
//function definition
int main()
{
//statements
return 0;
}
9 / 12
void Function
●
Sample source code
– Program to reverse display an N-digit
positive integer (where N >= 2)
10 / 12
Value-returning Function
●
Sample source code
– Program to compute the cube of a number
11 / 12
Hierarchy Chart: Coding Task 3
12 / 12