0% found this document useful (0 votes)
7 views

Programmer Defined Functions

The document discusses the classification of functions in C++, distinguishing between predefined (built-in) functions and programmer-defined (user-defined) functions. It outlines the requirements for using predefined functions, including necessary libraries and function signatures, and provides examples of both void and value-returning functions. Additionally, sample source code is included for demonstrating the implementation of these functions.

Uploaded by

ajbelependio
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Programmer Defined Functions

The document discusses the classification of functions in C++, distinguishing between predefined (built-in) functions and programmer-defined (user-defined) functions. It outlines the requirements for using predefined functions, including necessary libraries and function signatures, and provides examples of both void and value-returning functions. Additionally, sample source code is included for demonstrating the implementation of these functions.

Uploaded by

ajbelependio
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Credit: defit.

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

argument(s) value returned

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

You might also like