Lesson 8 - Functions
Lesson 8 - Functions
Functions
OBJECTIVE
8.1 Library Function
8.1.1 Standard Library Header Files
8.1.2 Mathematical Functions
8.1.3 Character Functions
8.2 User Defined Functions
8.2.1 Declaring the function.
8.2.2 Defining the function.
8.2.3 Inserting Argument To A Function
8.2.4 Declaring Return Type Of A Function
8.1 Library Functions
• C++ Standard Library Function
• The C++ Standard Library provides a rich
collection of functions for performing common
mathematical calculations, string
manipulations, character manipulations,
input/output, error checking and many other
useful operations.
• This makes the programmer's job easier,
because these functions provide many of the
capabilities programmers need.
8.1 Library Functions
• C++ Standard Library Function
• The C++ Standard Library functions are
provided as part of the C++ programming
environment.
• Header file names ending in .h are "old-style"
header files that have been superseded by the
C++ Standard Library header files
8.1.1 Standard Library Header Files
C++ Standard
Explanation
Library header file
Function Meaning
isalpha(c) It returns True if C is an uppercase letter and False if c is lowercase.
isdigit(c) It returns True if c is a digit (0 through 9) otherwise False.
}
8.2 User Defined Function
• Example
• What is the output of the following program when you enter 40 and 30?
8.2 User Defined Function
• Example
• What is the output of the following program when you enter 40 and 30?
8.2 User Defined Function
• Creating User-Defined Functions involves the
following
• 1. Declaring the function.
• 2. Defining the function.
• 3. Inserting Argument To A Function
• 4. Declaring Return Type Of A Function
8.2.1 Declaring the Function
• Creating User-Defined Functions involves the
following
• 1. Declaring the function.
• The declaration, called the FUNCTION
PROTOTYPE, informs the compiler about the
functions to be used in a program, the argument
they take and the type of value they return.
8.2.2 Defining the Function
• 2. Defining the function.
• The function definition tells the compiler what
task the function will be performing.
• The function prototype and the function
definition must be same on the return type, the
name, and the parameters.
• The only difference between the function
prototype and the function header is a
semicolon.
8.2.2 Defining the Function
• 2. Defining the function.
• The function definition consists of the function
header and its body.
• The header is EXACTLY like the function
prototype, EXCEPT that it contains NO
terminating semicolon.
8.2.2 Defining the Function
8.2.3 Inserting Argument To A Function
• 3. Argument To A Function
• Sometimes the calling function supplies some
values to the called function.
• These are known as parameters.
• The variables which supply the values to a calling
function called actual parameters.
• The variable which receive the value from called
statement are termed formal parameters
8.2.3 Inserting Argument To A Function
• Consider the following example that evaluates the area of a
circle.
Output
Please enter a number: 45
Your number times two = 90
NEXT LESSON
9.1 OOP Concepts
9.2 Classes and Objects
9.2.1 Object declaration
9.2.2 Accessing Class Members
9.2.3 Defining Member Function of Class
9.3 Constructors and Destructors
9.3.1 Default Constructors
9.3.2 Parameterized Constructors
9.3.3 Copy Constructors
9.3.4 Destructors