Documente Academic
Documente Profesional
Documente Cultură
Programmer
Specific Objectives
At the end of the session the students should be
able to:
Define function
Identify the function structure
Identify function prototype
Declaration of function
Distinguish and apply the 4 ways of function
Naming functions with different arguments
FUNCTION
USING FUNCTION
#include<iostream>
Using namespace std;
Func3(){
}
int main(){
}
Func1(){
}
Func2(){
}
Structure of a Function
Attributes of a function
The type of the value returned by the function
A name that identifies it
The functions parameters and their data types
Int Func1(parameter type) {
Processing statements
}
Calling a Function(1)
main()
{
Func1();
}
void Func1(){
cout<<hello world!;
}
no return type
int main(){
void back(int); defining function prototype
int num;
cin>>num;
back(num);
system("pause");
return 0;
}
void back(int wew){
wew = wew/2;
cout<<wew;
}
int main(){
void sum(int,int);
int num, num1;
cin>>num;
cin>>num1;
sum(num,num1);
system("pause");
return 0;
}
void sum(int wew,int wow){
int sum = wew + wow;
cout<<sum;
}
int main(){
int sum(int,int); defining function prototype
int num, num1;
cin>>num;
cin>>num1;
cout<<sum(num,num1);
system("pause");
return 0;
}
BENEFITS
large tasks can be broken up into manageable
units
repetitive tasks can be simplified
Specific Objectives
At the end of the session the students should be
able to:
Define function
Identify the function structure
Identify function prototype
Declaration of function
Distinguish and apply the 4 ways functions
Naming functions with different arguments
Activity #2
Using 1st and 2nd way of Function:
Menu System
1 converting ft to inch (1st way)
2 Area of a circle (2nd way)
3 Exit
Do You Want to Try again? (y/n)
Assignment#1
Give 2 example of 3rd and 4th way of function
program.
*code
*output
*printed