C++ Functions
C++ Functions
Function is known as the block of code that runs when it is called. It can
also be use to pass data into the function using the parameter.
Objectives
Students are able to implement the C++ function into the program
Know how to pass data among the function
Understand the importance of implementing the function into the particular
programming problem.
Identify and describe the two types of functions
Two types of Function
The standard library function is a function that is already defined in the program.
A user-define function is a function that is being defined by the programmer to perform a specific
task in the program. When the function is invoked from any part of the program, it all executes the
codes defined in the body of the function.
Syntax:
In the previews slide, we have declared a function named result(). In order to use the result()
function, we are going to call it.
This will demonstrate how we can call the above result() function.
int main() {
//calling a function
result();
}
Calling a Function
ACTIVITY 1
Create at-least one program demonstrating the concept of calling a
function.
Function parameters
A function can also be declared with parameters (arguments). A parameter is a value declaring a
function.
The int and float data type, and variable a & b inside the function is what we called parameter
} Parameter
The parameter is used to be a storage for all the data that is being pass into the function.
Function parameters
Sample program:
#include <iostream>
using namespace std;
int main() {
int num1 = 5;
displayValue(num1, num2);
return 0;
}
Individual Activity
ACTIVITY 2
1. Demonstrate on how to create a function with a parameter.
2.Provide a sample program that demonstrate the process of passing the
data into the function using parameter.
Document your demonstration
Note: Do not copy the given sample in the presentation. Create your own program that will ask a
value from the user.
Thank you for listening
Next topic: