SlideShare a Scribd company logo
Kinan keshkeh 
IT Engineering-Damascus University 
3rd year 
Summer course- 2014 
2 bytes team
• 
Welcome again ! 
• 
Who has any Ques? 
• 
So Let’s Go ! 
• 
What we will take : 
• 
Functions. 
• 
parameters& overloading
Function Basics!
Functions 
•Two ways to write functions in your program: 
•Declaration / calling / definition
Functions 
•Two ways to write functions in your program: 
•Declaration / calling / definition 
Before main 
Inside main 
After main
Functions 
•Two ways to write functions in your program: 
•Declaration / calling / definition 
•Declaration + definition / calling
Functions 
•Declaration / calling / definition 
#include<iostream> 
using namespace std ; 
Float avg(float x, float y ) ; 
int main () 
{ 
float x,y; 
cout<<" Enter the first number: n"; 
cin>>x; 
cout<<" Enter the second number: n"; 
cin>>y; 
float c=avg(x,y); 
cout<<"the avg : "<<c<<endl; 
system("pause"); 
return 0; 
} 
float avg(float x, float y ) 
{ 
return (x+y)/2; 
}
#include<iostream> 
using namespace std ; 
Float avg(float x, float y ) ; 
int main () 
{ 
float x,y; 
cout<<" Enter the first number: n"; 
cin>>x; 
cout<<" Enter the second number: n"; 
cin>>y; 
float c=avg(x,y); 
cout<<"the avg : "<<c<<endl; 
system("pause"); 
return 0; 
} 
float avg(float x, float y ) 
{ 
return (x+y)/2; 
} 
Functions 
•Declaration / calling / definition 
Declaration
#include<iostream> using namespace std ; Float avg(float x, float y ) ; int main () { float x,y; cout<<" Enter the first number: n"; cin>>x; cout<<" Enter the second number: n"; cin>>y; float c=avg(x,y); cout<<"the avg : "<<c<<endl; system("pause"); return 0; } float avg(float x, float y ) { return (x+y)/2; } 
Functions 
•Declaration / calling / definition 
Declaration 
calling
#include<iostream> 
using namespace std ; 
Float avg(float x, float y ) ; 
int main () 
{ 
float x,y; 
cout<<" Enter the first number: n"; 
cin>>x; 
cout<<" Enter the second number: n"; 
cin>>y; 
float c=avg(x,y); 
cout<<"the avg : "<<c<<endl; 
system("pause"); 
return 0; 
} 
float avg(float x, float y ) 
{ 
return (x+y)/2; 
} 
Functions 
•Declaration / calling / definition 
Declaration 
calling 
Definition
Functions 
•Declaration + definition / calling 
#include<iostream> using namespace std ; float avg(float x, float y ) { return (x+y)/2; } int main () { float x,y; cout<<" Enter the first number: n"; cin>>x; cout<<" Enter the second number: n"; cin>>y; float c=avg(x,y); cout<<"the avssg : "<<c<<endl; system("pause"); return 0; }
Functions 
•Declaration + definition / calling 
#include<iostream> using namespace std ; float avg(float x, float y ) { return (x+y)/2; } int main () { float x,y; cout<<" Enter the first number: n"; cin>>x; cout<<" Enter the second number: n"; cin>>y; float c=avg(x,y); cout<<"the avssg : "<<c<<endl; system("pause"); return 0; } 
Declaration+ definition
Functions 
•Declaration + definition / calling 
#include<iostream> using namespace std ; float avg(float x, float y ) { return (x+y)/2; } int main () { float x,y; cout<<" Enter the first number: n"; cin>>x; cout<<" Enter the second number: n"; cin>>y; float c=avg(x,y); cout<<"the avssg : "<<c<<endl; system("pause"); return 0; } 
Declaration+ definition 
calling
Functions 
#include<iostream> using namespace std ; float avg(float x , float y ) { return (x+y)/2; } int main () { float x,y; cout<<" Enter the first number: n"; cin>>x; cout<<" Enter the second number: n"; cin>>y; float c=avg(x,y); cout<<"the avssg : "<<c<<endl; system("pause"); return 0; } 
Returned value
Functions 
#include<iostream> 
using namespace std ; 
float avg(float x , float y ) 
{ 
return (x+y)/2; 
} 
int main () 
{ 
float x,y; 
cout<<" Enter the first number: n"; 
cin>>x; 
cout<<" Enter the second number: n"; 
cin>>y; 
float c=avg(x,y); 
cout<<"the avssg : "<<c<<endl; 
system("pause"); 
return 0; 
} 
It could be Void , then no return and no “ = ”
Functions 
#include<iostream> 
using namespace std ; 
float avg(float x , float y ) 
{ 
return (x+y)/2; 
} 
int main () 
{ 
float x,y; 
cout<<" Enter the first number: n"; 
cin>>x; 
cout<<" Enter the second number: n"; 
cin>>y; 
float c=avg(x,y); 
cout<<"the avssg : "<<c<<endl; 
system("pause"); 
return 0; 
} 
Attention !! 
“ , ” Not “ ; ”
Functions 
#include<iostream> 
using namespace std ; 
float avg(float x , float y ) 
{ 
return (x+y)/2; 
} 
int main () 
{ 
float x,y; 
cout<<" Enter the first number: n"; 
cin>>x; 
cout<<" Enter the second number: n"; 
cin>>y; 
float c=avg(x,y); 
cout<<"the avssg : "<<c<<endl; 
system("pause"); 
return 0; 
} 
Variables like in procedures & functions in Pascal !
Functions 
#include<iostream> 
using namespace std ; 
float avg(float x , float y ) 
{ 
return (x+y)/2; 
} 
int main () 
{ 
float x,y; 
cout<<" Enter the first number: n"; 
cin>>x; 
cout<<" Enter the second number: n"; 
cin>>y; 
float c=avg(x,y); 
cout<<"the avssg : "<<c<<endl; 
system("pause"); 
return 0; 
} 
Also , it could be null 
Float avg()
Predefined Functions !
Predefined Functions 
•It’s existing in libraries in C++ 
•You can call it without writing any definition or declaration !! 
•You have to put using namespace std with all functions !
Predefined Functions 
Name 
Description 
Type of 
Arguments 
Type of 
Value 
Example 
Value 
Library 
Header 
sqrt 
Square root 
double 
double 
sqrt(4.0) 
2.0 
cmath 
pow 
Powers 
double 
double 
pow(2.0,3.0) 
8.0 
cmath 
abs 
Absolute value for int 
int 
int 
abs(-7) 
abs(7) 
7 
7 
cstdlib 
labs 
Absolute value for long 
long 
long 
labs(-70000) labs(70000) 
70000 70000 
cstdlib 
fabs 
Absolute value for double 
double 
double 
fabs(-7.5) fabs(7.5) 
7.5 
7.5 
cmath 
ceil 
Ceiling (round up) 
double 
double 
ceil(3.2) ceil(3.9) 
4.0 
4.0 
cmath 
floor 
Floor (round down) 
double 
double 
floor(3.2) floor(3.9) 
3.0 
3.0 
cmath 
exit 
End program 
int 
void 
exit(1); 
None 
cstdlib 
rand 
Random number 
None 
int 
rand( ) 
Varies 
cstdlib 
srand 
Set seed for rand 
unsigned int 
void 
srand(42); 
None 
cstdlib
Predefined Functions 
Name 
Description 
Type of 
Arguments 
Type of 
Value 
Example 
Value 
Library 
Header 
sqrt 
Square root 
double 
double 
sqrt(4.0) 
2.0 
cmath 
pow 
Powers 
double 
double 
pow(2.0,3.0) 
8.0 
cmath 
abs 
Absolute value for int 
int 
int 
abs (-7) 
abs(7) 
7 
7 
cstdlib 
labs 
Absolute value for long 
long 
long 
labs(-70000) labs(70000) 
70000 70000 
cstdlib 
fabs 
Absolute value for double 
double 
double 
fabs(-7.5) fabs(7.5) 
7.5 
7.5 
cmath 
ceil 
Ceiling (round up) 
double 
double 
ceil(3.2) ceil(3.9) 
4.0 
4.0 
cmath 
floor 
Floor (round down) 
double 
double 
floor(3.2) floor(3.9) 
3.0 
3.0 
cmath 
exit 
End program 
int 
void 
exit(1); 
None 
cstdlib 
rand 
Random number 
None 
int 
rand( ) 
Varies 
cstdlib 
srand 
Set seed for rand 
unsigned int 
void 
srand (42); 
None 
cstdlib
///Computes the size of a doghouse that can be purchased //given the user’s budget. #include <iostream> #include <cmath> using namespace std; int main( ){ const double COST_PER_SQ_FT = 10.50; //cost per square feet double budget, area, lengthSide; cout << "Enter the amount budgeted for your doghouse $"; cin >> budget; area = budget/COST_PER_SQ_FT; lengthSide = sqrt(area); cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(2); cout << "For a price of $" << budget << endl << "I can build you a luxurious square doghousen" << "that is " << lengthSide << " feet on each side.n"; return 0; } 
Predefined Functions
#include <iostream> 
#include <cstdlib> 
using namespace std; 
int main( ){ 
int month, day; 
cout << "Welcome to your friendly weather program.n" 
<< "Enter today’s date as two integers for the month and the day:n"; 
cin >> month; 
cin >> day; 
srand(month*day); //using seed number=month*day 
int prediction; 
char ans; 
cout << "Weather for today:n"; 
do{ 
prediction = rand( ) % 3 ;// Scaling 
switch (prediction){ 
case 0: 
cout << "The day will be sunny!!n"; 
break; 
case 1: 
cout << "The day will be cloudy.n"; 
break; 
case 2: 
cout << "The day will be stormy!n"; 
break; 
default: 
cout << "Weather program is not functioning properly.n"; 
} 
cout << "Want the weather for the next day?(y/n): "; 
cin >> ans; 
} while (ans == 'y' || ans == 'Y'); 
cout << "That's it from your 24-hour weather program.n"; 
Return 0 ; 
} 
Code discussion 3
Pseudorandom Number Generator 
Code discussion 3 
The code does …
Local & global Variables !
Local & global Variables 
•Local Variables 
•It’s scope is the current ‘Block’ and all the ‘nested- blocks’ . 
•You can use the same name of variables in different scopes ! 
#include<iostream> 
using namespace std ; 
int main (){ 
float x; 
cout<<" Enter the number: n"; 
cin>>x; 
{ 
float x=22; 
} 
cout<<"the number x : "<<x<<endl; 
system("pause"); return 0; 
} 
Block!
Local & global Variables 
•Local Variables 
•It’s scope is the current ‘Block’ and all the ‘nested- blocks’ . 
•You can use the same name of variables in different scopes ! 
#include<iostream> using namespace std ; int main (){ float x; cout<<" Enter the number: n"; cin>>x; { float x=22; } cout<<"the number x : "<<x<<endl; system("pause"); return 0; }
Local & global Variables 
•Local Variables 
•It’s scope is the current ‘Block’ and all the ‘nested- blocks’ . 
•You can use the same name of variables in different scopes ! 
#include<iostream> 
using namespace std ; 
int main (){ 
float x; 
cout<<" Enter the number: n"; 
cin>>x; 
{ 
float x=22; 
} 
cout<<"the number x : "<<x<<endl; 
system("pause"); return 0; 
}
Local & global Variables 
•Local Variables 
•It’s scope is the current ‘Block’ and all the ‘nested- blocks’ . 
•You can use the same name of variables in different scopes ! 
#include<iostream> using namespace std ; int main (){ float x; cout<<" Enter the number: n"; cin>>x; { float x=22; } cout<<"the number x : "<<x<<endl; system("pause"); return 0; }
Local & global Variables 
•Local Variables 
•It’s scope is the current ‘Block’ and all the ‘nested- blocks’ . 
•You can use the same name of variables in different scopes ! 
#include<iostream> using namespace std ; int main (){ float x; cout<<" Enter the number: n"; cin>>x; { float x=22; } cout<<"the number x : "<<x<<endl; system("pause"); return 0; }
Local & global Variables 
•Local Variables 
•It’s scope is the current ‘Block’ and all the ‘nested- blocks’ . 
•You can use the same name of variables in different scopes ! 
#include<iostream> using namespace std ; int main (){ float x; cout<<" Enter the number: n"; cin>>x; { float x=22; } cout<<"the number x : "<<x<<endl; system("pause"); return 0; }
•Local Variables
Local & global Variables 
•Global Variables 
•At the first of program ( after “using namespace std” ) 
•It’s scope , all ‘blocks’ 
•If you have global variable (name x ) and other local variable ( name x too ) 
•If you want global x , you will write ::x
•Global Variables
Parameters and Overloading
Calling by value & by reference
Calling by value & by reference
Calling by value & by reference 
Without var 
With var
Calling by value & by reference 
Without var 
With var 
But “ & ” instead of var .
•Calling by value
•Calling by value 
•The Output :
•Calling by reference
•Calling by reference
•Calling by reference 
•The Output :
Overloading !
Overloading 
•The same functions names ,but different meanings 
•Returned_value Fname ( int v1 , double v1 …. ) 
•Returned_value Fname ( double v1 , double v1 …. ) 
•Returned_value Fname ( char v1 , double v1 …. )
Overloading 
•The same functions names ,but different meanings 
•Returned_value Fname ( int v1 , double v1 …. ) 
•Returned_value Fname ( double v1 , double v1 …. ) 
•Returned_value Fname ( char v1 , double v1 …. ) 
Difference here 
At parameters !
Overloading 
•The same functions names ,but different meanings 
•Returned_value Fname ( int v1 , double v1 …. ) 
•Returned_value Fname ( double v1 , double v1 …. ) 
•Returned_value Fname ( char v1 , double v1 …. ) 
Difference here At parameters ! 
In numbers of them , and in their kinds
Overloading 
•The same functions names ,but different meanings 
•Returned_value Fname ( int v1 , double v1 …. ) 
•Returned_value Fname ( double v1 , double v1 …. ) 
•Returned_value Fname ( char v1 , double v1 …. ) 
Difference here At parameters ! 
In numbers of them , and in their kinds 
Not here at returned value !
Overloading 
•The same functions names ,but different meanings 
•Returned_value Fname ( int v1 , double v1 …. ) 
•Returned_value Fname ( double v1 , double v1 …. ) 
•Returned_value Fname ( char v1 , double v1 …. ) 
•You will see it on operators + , - , * ….
Overloading
Overloading
Overloading
•Default Arguments
Homework 
•Write a program that calls a function , in function the user input a Float number (ex: 3.6) , then the output is “ (3) and (0.6) “ 
•Write a program that calls a Recursive function , in function the user input an integer number (ex: 3) , then the output is “ (3! = 6) “
That’s for today 
That’s for today guys !!
That’s for today 
Go and Play !
2 bytes team 
Group : group link 
Mobile phone- Kinan : 0994385748 
Facebook account : kinan’s account 
2 bytes team

More Related Content

What's hot

c programming
c programmingc programming
c programming
Arun Umrao
 
NS2: AWK and GNUplot - PArt III
NS2: AWK and GNUplot - PArt IIINS2: AWK and GNUplot - PArt III
NS2: AWK and GNUplot - PArt III
Ajit Nayak
 
Recursion to iteration automation.
Recursion to iteration automation.Recursion to iteration automation.
Recursion to iteration automation.
Russell Childs
 
c programming
c programmingc programming
c programming
Arun Umrao
 
C++ L08-Classes Part1
C++ L08-Classes Part1C++ L08-Classes Part1
C++ L08-Classes Part1
Mohammad Shaker
 
jq: JSON - Like a Boss
jq: JSON - Like a Bossjq: JSON - Like a Boss
jq: JSON - Like a Boss
Bob Tiernay
 
Ns2: Introduction - Part I
Ns2: Introduction - Part INs2: Introduction - Part I
Ns2: Introduction - Part I
Ajit Nayak
 
Academy PRO: ES2015
Academy PRO: ES2015Academy PRO: ES2015
Academy PRO: ES2015
Binary Studio
 
Ns2: OTCL - PArt II
Ns2: OTCL - PArt IINs2: OTCL - PArt II
Ns2: OTCL - PArt II
Ajit Nayak
 
Introduction to JQ
Introduction to JQIntroduction to JQ
Introduction to JQ
Knoldus Inc.
 
Unit 3
Unit 3 Unit 3
Unit 3
GOWSIKRAJAP
 
Numerical Methods with Computer Programming
Numerical Methods with Computer ProgrammingNumerical Methods with Computer Programming
Numerical Methods with Computer Programming
Utsav Patel
 
Programmation fonctionnelle en JavaScript
Programmation fonctionnelle en JavaScriptProgrammation fonctionnelle en JavaScript
Programmation fonctionnelle en JavaScript
Loïc Knuchel
 
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
ssuserd6b1fd
 
Groovy grails types, operators, objects
Groovy grails types, operators, objectsGroovy grails types, operators, objects
Groovy grails types, operators, objects
Husain Dalal
 
6. Generics. Collections. Streams
6. Generics. Collections. Streams6. Generics. Collections. Streams
6. Generics. Collections. Streams
DEVTYPE
 
Javascript
JavascriptJavascript
Javascript
Vlad Ifrim
 
Леонид Шевцов «Clojure в деле»
Леонид Шевцов «Clojure в деле»Леонид Шевцов «Clojure в деле»
Леонид Шевцов «Clojure в деле»
DataArt
 
Implementing Software Machines in C and Go
Implementing Software Machines in C and GoImplementing Software Machines in C and Go
Implementing Software Machines in C and Go
Eleanor McHugh
 
Basic C++ 11/14 for Python Programmers
Basic C++ 11/14 for Python ProgrammersBasic C++ 11/14 for Python Programmers
Basic C++ 11/14 for Python Programmers
Appier
 

What's hot (20)

c programming
c programmingc programming
c programming
 
NS2: AWK and GNUplot - PArt III
NS2: AWK and GNUplot - PArt IIINS2: AWK and GNUplot - PArt III
NS2: AWK and GNUplot - PArt III
 
Recursion to iteration automation.
Recursion to iteration automation.Recursion to iteration automation.
Recursion to iteration automation.
 
c programming
c programmingc programming
c programming
 
C++ L08-Classes Part1
C++ L08-Classes Part1C++ L08-Classes Part1
C++ L08-Classes Part1
 
jq: JSON - Like a Boss
jq: JSON - Like a Bossjq: JSON - Like a Boss
jq: JSON - Like a Boss
 
Ns2: Introduction - Part I
Ns2: Introduction - Part INs2: Introduction - Part I
Ns2: Introduction - Part I
 
Academy PRO: ES2015
Academy PRO: ES2015Academy PRO: ES2015
Academy PRO: ES2015
 
Ns2: OTCL - PArt II
Ns2: OTCL - PArt IINs2: OTCL - PArt II
Ns2: OTCL - PArt II
 
Introduction to JQ
Introduction to JQIntroduction to JQ
Introduction to JQ
 
Unit 3
Unit 3 Unit 3
Unit 3
 
Numerical Methods with Computer Programming
Numerical Methods with Computer ProgrammingNumerical Methods with Computer Programming
Numerical Methods with Computer Programming
 
Programmation fonctionnelle en JavaScript
Programmation fonctionnelle en JavaScriptProgrammation fonctionnelle en JavaScript
Programmation fonctionnelle en JavaScript
 
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
 
Groovy grails types, operators, objects
Groovy grails types, operators, objectsGroovy grails types, operators, objects
Groovy grails types, operators, objects
 
6. Generics. Collections. Streams
6. Generics. Collections. Streams6. Generics. Collections. Streams
6. Generics. Collections. Streams
 
Javascript
JavascriptJavascript
Javascript
 
Леонид Шевцов «Clojure в деле»
Леонид Шевцов «Clojure в деле»Леонид Шевцов «Clojure в деле»
Леонид Шевцов «Clojure в деле»
 
Implementing Software Machines in C and Go
Implementing Software Machines in C and GoImplementing Software Machines in C and Go
Implementing Software Machines in C and Go
 
Basic C++ 11/14 for Python Programmers
Basic C++ 11/14 for Python ProgrammersBasic C++ 11/14 for Python Programmers
Basic C++ 11/14 for Python Programmers
 

Viewers also liked

Function lecture
Function lectureFunction lecture
Function lecture
DIT University, Dehradun
 
C++ Function
C++ FunctionC++ Function
C++ Function
PingLun Liao
 
Pre defined Functions in C
Pre defined Functions in CPre defined Functions in C
Pre defined Functions in C
Prabhu Govind
 
Function in c++
Function in c++Function in c++
Function in c++Kumar
 
Call by value
Call by valueCall by value
Call by valueDharani G
 
C functions
C functionsC functions
Lovely Professional University Distance Education
Lovely Professional University Distance EducationLovely Professional University Distance Education
Lovely Professional University Distance Education
Aastha Groups
 
16717 functions in C++
16717 functions in C++16717 functions in C++
16717 functions in C++
LPU
 
C programming - String
C programming - StringC programming - String
C programming - String
Achyut Devkota
 
Functions
FunctionsFunctions
Functions
Online
 
C++ Function
C++ FunctionC++ Function
C++ FunctionHajar
 
Computer Programming- Lecture 5
Computer Programming- Lecture 5 Computer Programming- Lecture 5
Computer Programming- Lecture 5
Dr. Md. Shohel Sayeed
 
String in c
String in cString in c
String in c
Suneel Dogra
 
Function in C
Function in CFunction in C
Function in C
Dr. Abhineet Anand
 
functions of C++
functions of C++functions of C++
functions of C++
tarandeep_kaur
 
Organizing (Management Functions)
Organizing (Management Functions)Organizing (Management Functions)
Organizing (Management Functions)
Christian de la Cruz
 
Functionsbsitact
FunctionsbsitactFunctionsbsitact
Functionsbsitact
Juan Apolinario Reyes
 

Viewers also liked (20)

Function lecture
Function lectureFunction lecture
Function lecture
 
C++ Function
C++ FunctionC++ Function
C++ Function
 
Pre defined Functions in C
Pre defined Functions in CPre defined Functions in C
Pre defined Functions in C
 
Function in c++
Function in c++Function in c++
Function in c++
 
Call by value
Call by valueCall by value
Call by value
 
C functions
C functionsC functions
C functions
 
Lovely Professional University Distance Education
Lovely Professional University Distance EducationLovely Professional University Distance Education
Lovely Professional University Distance Education
 
16717 functions in C++
16717 functions in C++16717 functions in C++
16717 functions in C++
 
C programming - String
C programming - StringC programming - String
C programming - String
 
Functions
FunctionsFunctions
Functions
 
C++ Function
C++ FunctionC++ Function
C++ Function
 
Parameter passing to_functions_in_c
Parameter passing to_functions_in_cParameter passing to_functions_in_c
Parameter passing to_functions_in_c
 
Computer Programming- Lecture 5
Computer Programming- Lecture 5 Computer Programming- Lecture 5
Computer Programming- Lecture 5
 
String in c
String in cString in c
String in c
 
Function in c
Function in cFunction in c
Function in c
 
Function in C
Function in CFunction in C
Function in C
 
functions of C++
functions of C++functions of C++
functions of C++
 
Function in C program
Function in C programFunction in C program
Function in C program
 
Organizing (Management Functions)
Organizing (Management Functions)Organizing (Management Functions)
Organizing (Management Functions)
 
Functionsbsitact
FunctionsbsitactFunctionsbsitact
Functionsbsitact
 

Similar to 2 BytesC++ course_2014_c3_ function basics&parameters and overloading

C++ process new
C++ process newC++ process new
C++ process new
敬倫 林
 
Cpp tutorial
Cpp tutorialCpp tutorial
Cpp tutorial
Vikas Sharma
 
Lecture 9_Classes.pptx
Lecture 9_Classes.pptxLecture 9_Classes.pptx
Lecture 9_Classes.pptx
NelyJay
 
C++ practical
C++ practicalC++ practical
C++ practical
Rahul juneja
 
CppTutorial.ppt
CppTutorial.pptCppTutorial.ppt
CppTutorial.ppt
HODZoology3
 
Managing console
Managing consoleManaging console
Managing console
Shiva Saxena
 
Add an interactive command line to your C++ application
Add an interactive command line to your C++ applicationAdd an interactive command line to your C++ application
Add an interactive command line to your C++ application
Daniele Pallastrelli
 
Lec 2.pptx
Lec 2.pptxLec 2.pptx
Lec 2.pptx
AbdulMaalik19
 
Chapter i(introduction to java)
Chapter i(introduction to java)Chapter i(introduction to java)
Chapter i(introduction to java)
Chhom Karath
 
54602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee0108310154602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee01083101
premrings
 
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyC++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
GrejoJoby1
 
Look Ma, “update DB to HTML5 using C++”, no hands! 
Look Ma, “update DB to HTML5 using C++”, no hands! Look Ma, “update DB to HTML5 using C++”, no hands! 
Look Ma, “update DB to HTML5 using C++”, no hands! aleks-f
 
Pads lab manual final
Pads lab manual finalPads lab manual final
Pads lab manual final
AhalyaR
 
Oop object oriented programing topics
Oop object oriented programing topicsOop object oriented programing topics
Oop object oriented programing topics
(•̮̮̃•̃) Prince Do Not Work
 
Lecture2.ppt
Lecture2.pptLecture2.ppt
Lecture2.ppt
TarekHemdan3
 
Project in programming
Project in programmingProject in programming
Project in programming
sahashi11342091
 

Similar to 2 BytesC++ course_2014_c3_ function basics&parameters and overloading (20)

CP 04.pptx
CP 04.pptxCP 04.pptx
CP 04.pptx
 
C++ process new
C++ process newC++ process new
C++ process new
 
Oop1
Oop1Oop1
Oop1
 
Cpp tutorial
Cpp tutorialCpp tutorial
Cpp tutorial
 
Lecture 9_Classes.pptx
Lecture 9_Classes.pptxLecture 9_Classes.pptx
Lecture 9_Classes.pptx
 
C++ practical
C++ practicalC++ practical
C++ practical
 
CppTutorial.ppt
CppTutorial.pptCppTutorial.ppt
CppTutorial.ppt
 
Managing console
Managing consoleManaging console
Managing console
 
C++ file
C++ fileC++ file
C++ file
 
C++ file
C++ fileC++ file
C++ file
 
Add an interactive command line to your C++ application
Add an interactive command line to your C++ applicationAdd an interactive command line to your C++ application
Add an interactive command line to your C++ application
 
Lec 2.pptx
Lec 2.pptxLec 2.pptx
Lec 2.pptx
 
Chapter i(introduction to java)
Chapter i(introduction to java)Chapter i(introduction to java)
Chapter i(introduction to java)
 
54602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee0108310154602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee01083101
 
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyC++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
 
Look Ma, “update DB to HTML5 using C++”, no hands! 
Look Ma, “update DB to HTML5 using C++”, no hands! Look Ma, “update DB to HTML5 using C++”, no hands! 
Look Ma, “update DB to HTML5 using C++”, no hands! 
 
Pads lab manual final
Pads lab manual finalPads lab manual final
Pads lab manual final
 
Oop object oriented programing topics
Oop object oriented programing topicsOop object oriented programing topics
Oop object oriented programing topics
 
Lecture2.ppt
Lecture2.pptLecture2.ppt
Lecture2.ppt
 
Project in programming
Project in programmingProject in programming
Project in programming
 

More from kinan keshkeh

10 Little Tricks to Get Your Class’s Attention (and Hold It)
10 Little Tricks to Get Your  Class’s Attention (and Hold It)10 Little Tricks to Get Your  Class’s Attention (and Hold It)
10 Little Tricks to Get Your Class’s Attention (and Hold It)
kinan keshkeh
 
Simpson and lagranje dalambair math methods
Simpson and lagranje dalambair math methods Simpson and lagranje dalambair math methods
Simpson and lagranje dalambair math methods
kinan keshkeh
 
Shapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptShapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop concept
kinan keshkeh
 
Shapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptShapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop concept
kinan keshkeh
 
GeneticAlgorithms_AND_CuttingWoodAlgorithm
GeneticAlgorithms_AND_CuttingWoodAlgorithm  GeneticAlgorithms_AND_CuttingWoodAlgorithm
GeneticAlgorithms_AND_CuttingWoodAlgorithm
kinan keshkeh
 
Algorithm in discovering and correcting words errors in a dictionary or any w...
Algorithm in discovering and correcting words errors in a dictionary or any w...Algorithm in discovering and correcting words errors in a dictionary or any w...
Algorithm in discovering and correcting words errors in a dictionary or any w...
kinan keshkeh
 
2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph
kinan keshkeh
 
2Bytesprog2 course_2014_c8_units
2Bytesprog2 course_2014_c8_units2Bytesprog2 course_2014_c8_units
2Bytesprog2 course_2014_c8_units
kinan keshkeh
 
2Bytesprog2 course_2014_c7_double_lists
2Bytesprog2 course_2014_c7_double_lists2Bytesprog2 course_2014_c7_double_lists
2Bytesprog2 course_2014_c7_double_lists
kinan keshkeh
 
2Bytesprog2 course_2014_c6_single linked list
2Bytesprog2 course_2014_c6_single linked list2Bytesprog2 course_2014_c6_single linked list
2Bytesprog2 course_2014_c6_single linked list
kinan keshkeh
 
2Bytesprog2 course_2014_c5_pointers
2Bytesprog2 course_2014_c5_pointers2Bytesprog2 course_2014_c5_pointers
2Bytesprog2 course_2014_c5_pointers
kinan keshkeh
 
2Bytesprog2 course_2014_c4_binaryfiles
2Bytesprog2 course_2014_c4_binaryfiles2Bytesprog2 course_2014_c4_binaryfiles
2Bytesprog2 course_2014_c4_binaryfiles
kinan keshkeh
 
2Bytesprog2 course_2014_c3_txtfiles
2Bytesprog2 course_2014_c3_txtfiles2Bytesprog2 course_2014_c3_txtfiles
2Bytesprog2 course_2014_c3_txtfiles
kinan keshkeh
 
2Bytesprog2 course_2014_c2_records
2Bytesprog2 course_2014_c2_records2Bytesprog2 course_2014_c2_records
2Bytesprog2 course_2014_c2_records
kinan keshkeh
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets
kinan keshkeh
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets
kinan keshkeh
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets
kinan keshkeh
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets
kinan keshkeh
 
2 BytesC++ course_2014_c13_ templates
2 BytesC++ course_2014_c13_ templates2 BytesC++ course_2014_c13_ templates
2 BytesC++ course_2014_c13_ templates
kinan keshkeh
 
2 BytesC++ course_2014_c12_ polymorphism
2 BytesC++ course_2014_c12_ polymorphism2 BytesC++ course_2014_c12_ polymorphism
2 BytesC++ course_2014_c12_ polymorphism
kinan keshkeh
 

More from kinan keshkeh (20)

10 Little Tricks to Get Your Class’s Attention (and Hold It)
10 Little Tricks to Get Your  Class’s Attention (and Hold It)10 Little Tricks to Get Your  Class’s Attention (and Hold It)
10 Little Tricks to Get Your Class’s Attention (and Hold It)
 
Simpson and lagranje dalambair math methods
Simpson and lagranje dalambair math methods Simpson and lagranje dalambair math methods
Simpson and lagranje dalambair math methods
 
Shapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptShapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop concept
 
Shapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptShapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop concept
 
GeneticAlgorithms_AND_CuttingWoodAlgorithm
GeneticAlgorithms_AND_CuttingWoodAlgorithm  GeneticAlgorithms_AND_CuttingWoodAlgorithm
GeneticAlgorithms_AND_CuttingWoodAlgorithm
 
Algorithm in discovering and correcting words errors in a dictionary or any w...
Algorithm in discovering and correcting words errors in a dictionary or any w...Algorithm in discovering and correcting words errors in a dictionary or any w...
Algorithm in discovering and correcting words errors in a dictionary or any w...
 
2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph
 
2Bytesprog2 course_2014_c8_units
2Bytesprog2 course_2014_c8_units2Bytesprog2 course_2014_c8_units
2Bytesprog2 course_2014_c8_units
 
2Bytesprog2 course_2014_c7_double_lists
2Bytesprog2 course_2014_c7_double_lists2Bytesprog2 course_2014_c7_double_lists
2Bytesprog2 course_2014_c7_double_lists
 
2Bytesprog2 course_2014_c6_single linked list
2Bytesprog2 course_2014_c6_single linked list2Bytesprog2 course_2014_c6_single linked list
2Bytesprog2 course_2014_c6_single linked list
 
2Bytesprog2 course_2014_c5_pointers
2Bytesprog2 course_2014_c5_pointers2Bytesprog2 course_2014_c5_pointers
2Bytesprog2 course_2014_c5_pointers
 
2Bytesprog2 course_2014_c4_binaryfiles
2Bytesprog2 course_2014_c4_binaryfiles2Bytesprog2 course_2014_c4_binaryfiles
2Bytesprog2 course_2014_c4_binaryfiles
 
2Bytesprog2 course_2014_c3_txtfiles
2Bytesprog2 course_2014_c3_txtfiles2Bytesprog2 course_2014_c3_txtfiles
2Bytesprog2 course_2014_c3_txtfiles
 
2Bytesprog2 course_2014_c2_records
2Bytesprog2 course_2014_c2_records2Bytesprog2 course_2014_c2_records
2Bytesprog2 course_2014_c2_records
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets
 
2 BytesC++ course_2014_c13_ templates
2 BytesC++ course_2014_c13_ templates2 BytesC++ course_2014_c13_ templates
2 BytesC++ course_2014_c13_ templates
 
2 BytesC++ course_2014_c12_ polymorphism
2 BytesC++ course_2014_c12_ polymorphism2 BytesC++ course_2014_c12_ polymorphism
2 BytesC++ course_2014_c12_ polymorphism
 

Recently uploaded

Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)
abdulrafaychaudhry
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
informapgpstrackings
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 

Recently uploaded (20)

Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 

2 BytesC++ course_2014_c3_ function basics&parameters and overloading

  • 1. Kinan keshkeh IT Engineering-Damascus University 3rd year Summer course- 2014 2 bytes team
  • 2. • Welcome again ! • Who has any Ques? • So Let’s Go ! • What we will take : • Functions. • parameters& overloading
  • 4. Functions •Two ways to write functions in your program: •Declaration / calling / definition
  • 5. Functions •Two ways to write functions in your program: •Declaration / calling / definition Before main Inside main After main
  • 6. Functions •Two ways to write functions in your program: •Declaration / calling / definition •Declaration + definition / calling
  • 7. Functions •Declaration / calling / definition #include<iostream> using namespace std ; Float avg(float x, float y ) ; int main () { float x,y; cout<<" Enter the first number: n"; cin>>x; cout<<" Enter the second number: n"; cin>>y; float c=avg(x,y); cout<<"the avg : "<<c<<endl; system("pause"); return 0; } float avg(float x, float y ) { return (x+y)/2; }
  • 8. #include<iostream> using namespace std ; Float avg(float x, float y ) ; int main () { float x,y; cout<<" Enter the first number: n"; cin>>x; cout<<" Enter the second number: n"; cin>>y; float c=avg(x,y); cout<<"the avg : "<<c<<endl; system("pause"); return 0; } float avg(float x, float y ) { return (x+y)/2; } Functions •Declaration / calling / definition Declaration
  • 9. #include<iostream> using namespace std ; Float avg(float x, float y ) ; int main () { float x,y; cout<<" Enter the first number: n"; cin>>x; cout<<" Enter the second number: n"; cin>>y; float c=avg(x,y); cout<<"the avg : "<<c<<endl; system("pause"); return 0; } float avg(float x, float y ) { return (x+y)/2; } Functions •Declaration / calling / definition Declaration calling
  • 10. #include<iostream> using namespace std ; Float avg(float x, float y ) ; int main () { float x,y; cout<<" Enter the first number: n"; cin>>x; cout<<" Enter the second number: n"; cin>>y; float c=avg(x,y); cout<<"the avg : "<<c<<endl; system("pause"); return 0; } float avg(float x, float y ) { return (x+y)/2; } Functions •Declaration / calling / definition Declaration calling Definition
  • 11. Functions •Declaration + definition / calling #include<iostream> using namespace std ; float avg(float x, float y ) { return (x+y)/2; } int main () { float x,y; cout<<" Enter the first number: n"; cin>>x; cout<<" Enter the second number: n"; cin>>y; float c=avg(x,y); cout<<"the avssg : "<<c<<endl; system("pause"); return 0; }
  • 12. Functions •Declaration + definition / calling #include<iostream> using namespace std ; float avg(float x, float y ) { return (x+y)/2; } int main () { float x,y; cout<<" Enter the first number: n"; cin>>x; cout<<" Enter the second number: n"; cin>>y; float c=avg(x,y); cout<<"the avssg : "<<c<<endl; system("pause"); return 0; } Declaration+ definition
  • 13. Functions •Declaration + definition / calling #include<iostream> using namespace std ; float avg(float x, float y ) { return (x+y)/2; } int main () { float x,y; cout<<" Enter the first number: n"; cin>>x; cout<<" Enter the second number: n"; cin>>y; float c=avg(x,y); cout<<"the avssg : "<<c<<endl; system("pause"); return 0; } Declaration+ definition calling
  • 14. Functions #include<iostream> using namespace std ; float avg(float x , float y ) { return (x+y)/2; } int main () { float x,y; cout<<" Enter the first number: n"; cin>>x; cout<<" Enter the second number: n"; cin>>y; float c=avg(x,y); cout<<"the avssg : "<<c<<endl; system("pause"); return 0; } Returned value
  • 15. Functions #include<iostream> using namespace std ; float avg(float x , float y ) { return (x+y)/2; } int main () { float x,y; cout<<" Enter the first number: n"; cin>>x; cout<<" Enter the second number: n"; cin>>y; float c=avg(x,y); cout<<"the avssg : "<<c<<endl; system("pause"); return 0; } It could be Void , then no return and no “ = ”
  • 16. Functions #include<iostream> using namespace std ; float avg(float x , float y ) { return (x+y)/2; } int main () { float x,y; cout<<" Enter the first number: n"; cin>>x; cout<<" Enter the second number: n"; cin>>y; float c=avg(x,y); cout<<"the avssg : "<<c<<endl; system("pause"); return 0; } Attention !! “ , ” Not “ ; ”
  • 17. Functions #include<iostream> using namespace std ; float avg(float x , float y ) { return (x+y)/2; } int main () { float x,y; cout<<" Enter the first number: n"; cin>>x; cout<<" Enter the second number: n"; cin>>y; float c=avg(x,y); cout<<"the avssg : "<<c<<endl; system("pause"); return 0; } Variables like in procedures & functions in Pascal !
  • 18. Functions #include<iostream> using namespace std ; float avg(float x , float y ) { return (x+y)/2; } int main () { float x,y; cout<<" Enter the first number: n"; cin>>x; cout<<" Enter the second number: n"; cin>>y; float c=avg(x,y); cout<<"the avssg : "<<c<<endl; system("pause"); return 0; } Also , it could be null Float avg()
  • 20. Predefined Functions •It’s existing in libraries in C++ •You can call it without writing any definition or declaration !! •You have to put using namespace std with all functions !
  • 21. Predefined Functions Name Description Type of Arguments Type of Value Example Value Library Header sqrt Square root double double sqrt(4.0) 2.0 cmath pow Powers double double pow(2.0,3.0) 8.0 cmath abs Absolute value for int int int abs(-7) abs(7) 7 7 cstdlib labs Absolute value for long long long labs(-70000) labs(70000) 70000 70000 cstdlib fabs Absolute value for double double double fabs(-7.5) fabs(7.5) 7.5 7.5 cmath ceil Ceiling (round up) double double ceil(3.2) ceil(3.9) 4.0 4.0 cmath floor Floor (round down) double double floor(3.2) floor(3.9) 3.0 3.0 cmath exit End program int void exit(1); None cstdlib rand Random number None int rand( ) Varies cstdlib srand Set seed for rand unsigned int void srand(42); None cstdlib
  • 22. Predefined Functions Name Description Type of Arguments Type of Value Example Value Library Header sqrt Square root double double sqrt(4.0) 2.0 cmath pow Powers double double pow(2.0,3.0) 8.0 cmath abs Absolute value for int int int abs (-7) abs(7) 7 7 cstdlib labs Absolute value for long long long labs(-70000) labs(70000) 70000 70000 cstdlib fabs Absolute value for double double double fabs(-7.5) fabs(7.5) 7.5 7.5 cmath ceil Ceiling (round up) double double ceil(3.2) ceil(3.9) 4.0 4.0 cmath floor Floor (round down) double double floor(3.2) floor(3.9) 3.0 3.0 cmath exit End program int void exit(1); None cstdlib rand Random number None int rand( ) Varies cstdlib srand Set seed for rand unsigned int void srand (42); None cstdlib
  • 23. ///Computes the size of a doghouse that can be purchased //given the user’s budget. #include <iostream> #include <cmath> using namespace std; int main( ){ const double COST_PER_SQ_FT = 10.50; //cost per square feet double budget, area, lengthSide; cout << "Enter the amount budgeted for your doghouse $"; cin >> budget; area = budget/COST_PER_SQ_FT; lengthSide = sqrt(area); cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(2); cout << "For a price of $" << budget << endl << "I can build you a luxurious square doghousen" << "that is " << lengthSide << " feet on each side.n"; return 0; } Predefined Functions
  • 24. #include <iostream> #include <cstdlib> using namespace std; int main( ){ int month, day; cout << "Welcome to your friendly weather program.n" << "Enter today’s date as two integers for the month and the day:n"; cin >> month; cin >> day; srand(month*day); //using seed number=month*day int prediction; char ans; cout << "Weather for today:n"; do{ prediction = rand( ) % 3 ;// Scaling switch (prediction){ case 0: cout << "The day will be sunny!!n"; break; case 1: cout << "The day will be cloudy.n"; break; case 2: cout << "The day will be stormy!n"; break; default: cout << "Weather program is not functioning properly.n"; } cout << "Want the weather for the next day?(y/n): "; cin >> ans; } while (ans == 'y' || ans == 'Y'); cout << "That's it from your 24-hour weather program.n"; Return 0 ; } Code discussion 3
  • 25. Pseudorandom Number Generator Code discussion 3 The code does …
  • 26. Local & global Variables !
  • 27. Local & global Variables •Local Variables •It’s scope is the current ‘Block’ and all the ‘nested- blocks’ . •You can use the same name of variables in different scopes ! #include<iostream> using namespace std ; int main (){ float x; cout<<" Enter the number: n"; cin>>x; { float x=22; } cout<<"the number x : "<<x<<endl; system("pause"); return 0; } Block!
  • 28. Local & global Variables •Local Variables •It’s scope is the current ‘Block’ and all the ‘nested- blocks’ . •You can use the same name of variables in different scopes ! #include<iostream> using namespace std ; int main (){ float x; cout<<" Enter the number: n"; cin>>x; { float x=22; } cout<<"the number x : "<<x<<endl; system("pause"); return 0; }
  • 29. Local & global Variables •Local Variables •It’s scope is the current ‘Block’ and all the ‘nested- blocks’ . •You can use the same name of variables in different scopes ! #include<iostream> using namespace std ; int main (){ float x; cout<<" Enter the number: n"; cin>>x; { float x=22; } cout<<"the number x : "<<x<<endl; system("pause"); return 0; }
  • 30. Local & global Variables •Local Variables •It’s scope is the current ‘Block’ and all the ‘nested- blocks’ . •You can use the same name of variables in different scopes ! #include<iostream> using namespace std ; int main (){ float x; cout<<" Enter the number: n"; cin>>x; { float x=22; } cout<<"the number x : "<<x<<endl; system("pause"); return 0; }
  • 31. Local & global Variables •Local Variables •It’s scope is the current ‘Block’ and all the ‘nested- blocks’ . •You can use the same name of variables in different scopes ! #include<iostream> using namespace std ; int main (){ float x; cout<<" Enter the number: n"; cin>>x; { float x=22; } cout<<"the number x : "<<x<<endl; system("pause"); return 0; }
  • 32. Local & global Variables •Local Variables •It’s scope is the current ‘Block’ and all the ‘nested- blocks’ . •You can use the same name of variables in different scopes ! #include<iostream> using namespace std ; int main (){ float x; cout<<" Enter the number: n"; cin>>x; { float x=22; } cout<<"the number x : "<<x<<endl; system("pause"); return 0; }
  • 34. Local & global Variables •Global Variables •At the first of program ( after “using namespace std” ) •It’s scope , all ‘blocks’ •If you have global variable (name x ) and other local variable ( name x too ) •If you want global x , you will write ::x
  • 37. Calling by value & by reference
  • 38. Calling by value & by reference
  • 39. Calling by value & by reference Without var With var
  • 40. Calling by value & by reference Without var With var But “ & ” instead of var .
  • 42. •Calling by value •The Output :
  • 45. •Calling by reference •The Output :
  • 47. Overloading •The same functions names ,but different meanings •Returned_value Fname ( int v1 , double v1 …. ) •Returned_value Fname ( double v1 , double v1 …. ) •Returned_value Fname ( char v1 , double v1 …. )
  • 48. Overloading •The same functions names ,but different meanings •Returned_value Fname ( int v1 , double v1 …. ) •Returned_value Fname ( double v1 , double v1 …. ) •Returned_value Fname ( char v1 , double v1 …. ) Difference here At parameters !
  • 49. Overloading •The same functions names ,but different meanings •Returned_value Fname ( int v1 , double v1 …. ) •Returned_value Fname ( double v1 , double v1 …. ) •Returned_value Fname ( char v1 , double v1 …. ) Difference here At parameters ! In numbers of them , and in their kinds
  • 50. Overloading •The same functions names ,but different meanings •Returned_value Fname ( int v1 , double v1 …. ) •Returned_value Fname ( double v1 , double v1 …. ) •Returned_value Fname ( char v1 , double v1 …. ) Difference here At parameters ! In numbers of them , and in their kinds Not here at returned value !
  • 51. Overloading •The same functions names ,but different meanings •Returned_value Fname ( int v1 , double v1 …. ) •Returned_value Fname ( double v1 , double v1 …. ) •Returned_value Fname ( char v1 , double v1 …. ) •You will see it on operators + , - , * ….
  • 52.
  • 57. Homework •Write a program that calls a function , in function the user input a Float number (ex: 3.6) , then the output is “ (3) and (0.6) “ •Write a program that calls a Recursive function , in function the user input an integer number (ex: 3) , then the output is “ (3! = 6) “
  • 58. That’s for today That’s for today guys !!
  • 59. That’s for today Go and Play !
  • 60. 2 bytes team Group : group link Mobile phone- Kinan : 0994385748 Facebook account : kinan’s account 2 bytes team