You are on page 1of 10

Unit 3.

Functions
Types of Functions:
1.Void Functions
There are functions which do not return a value but only
prints messages on the screen. These are called void
functions.
2. Overloading Functions
Function overloading is a feature of object-oriented
programming (OOP) where two or more functions can have the
same name but different parameters.
Unit 3. Functions
1.Void Functions
Void functions are created and used just like value-
returning functions except they do not return a value after
the function executes. In lieu of a data type, void functions
use the keyword "void.“
A void function performs a task, and then control
returns back to the caller--but, it does not return a value.
You may or may not use the return statement, as there is no
return value.
Unit 3. Functions
Example of Void Function:
Fuction
void message() { Definition
cout<<“Kim Sunoo”;
cout<<endl;
cout<<“18 years old”;
}

int main () {
Fuction Call
message();

return EXIT_SUCCESS;
}
Unit 3. Functions void message() {
cout<<“Kim Sunoo”;
cout<<endl;
cout<<“18 years old”;
Example of Overloading Function: }

SIMULATION: int main () {


message();

return EXIT_SUCCESS;
}

Kim Sunoo _
_18 years old

Computer Monitor
Unit 3. Functions
Create a void Structure That Will Print Your Teacher’s Name,age And What Age
Does She Looks Like
void print(string c) {

cout << "Teacher's name: " << c << endl;


}

void print(char f) {

cout << "Age: " << f << endl;


}

void print(int i) {
cout << "Looks like: " << i << endl;
}

Int main() {

print("Vee Arbee");
print(52);
print(18);

return EXIT_SUCCESS;
}
void print(string c) {

Unit 3. Functions
cout << "Teacher's name: " << c;
cout <<endl;
}
void print(char f) {

Example of Overloading Function:


cout << "Age: " << f << endl;
cout <<endl;
}
void print(char const i) {

SIMULATION: }
cout << "Looks like: " << i << endl;
cout <<endl;

int main() {
print("Vee Arbee");
Teacher’s name: Vee Arbee _ print(52);
print(18);
_
Age: 52 _
Looks
_ like: 18 _
_

52

Vee Arbee
f 18

Computer Monitor
c i
Unit 3. Functions
2. Overloading Functions
An overloaded declaration is a declaration that is declared with
the same name as a previously declared declaration in the same
scope, except that both declarations have different arguments and
obviously different definition (implementation).
When you call an overloaded function or operator, the compiler
determines the most appropriate definition to use, by comparing
the argument types you have used to call the function or operator
with the parameter types specified in the definitions. The process of
selecting the most appropriate overloaded function or operator is
called overload resolution.
Unit 3. Functions Fuction
Example of Overloading Function:
void display(int var1, double var2) Definition
{
cout << "Integer number = " << var1;
cout << " and double number = " << var2;
cout<<endl;
}

void display(double var)


{
cout << "Double number = " << var;
cout<<endl;
}

void display(int var)


{
cout << "Integer number = " << var;
cout<<endl;
}
Int main() Fuction Call
{
int a = 5;
double b = 5.5;
display(a);
display(b);
display(a, b);
Void display(int var 1, double var 2 c) {

Unit 3. Functions
cout << "Integer number = " << var1;
cout << " and double number = " << var2;
cout<<endl;
}

Example of Overloading Function:


void print(double var) {
cout << "Double number = " << var;
cout<<endl;
}
SIMULATION: void print(int var) {
cout << "Integer number = " << var;
cout<<endl;
}
int main() {
Integer number = 5 _ int a = 5;

_
Float number = 5.5 _ 5 5.5
double b = 5.5;
display(a);
Integer
_ number = 5 and double number = 5.5 _ display(b);

var var
display(a, b);
_

5 5.5
Computer Monitor
var 1 var 2
Group 1 We hope you
learn something
Thank you
everyone

Owen Duque Ladylyn Valdez Thank you,


Godbless
Bye
everyone
Jasmin Marigsa
Catherine Dekosantos Thank you for Marius Fajardo
Listening

You might also like