SlideShare una empresa de Scribd logo
1 de 60
Descargar para leer sin conexión
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

Más contenido relacionado

La actualidad más candente

NS2: AWK and GNUplot - PArt III
NS2: AWK and GNUplot - PArt IIINS2: AWK and GNUplot - PArt III
NS2: AWK and GNUplot - PArt IIIAjit Nayak
 
Recursion to iteration automation.
Recursion to iteration automation.Recursion to iteration automation.
Recursion to iteration automation.Russell Childs
 
jq: JSON - Like a Boss
jq: JSON - Like a Bossjq: JSON - Like a Boss
jq: JSON - Like a BossBob Tiernay
 
Ns2: Introduction - Part I
Ns2: Introduction - Part INs2: Introduction - Part I
Ns2: Introduction - Part IAjit Nayak
 
Ns2: OTCL - PArt II
Ns2: OTCL - PArt IINs2: OTCL - PArt II
Ns2: OTCL - PArt IIAjit Nayak
 
Introduction to JQ
Introduction to JQIntroduction to JQ
Introduction to JQKnoldus Inc.
 
Numerical Methods with Computer Programming
Numerical Methods with Computer ProgrammingNumerical Methods with Computer Programming
Numerical Methods with Computer ProgrammingUtsav Patel
 
Programmation fonctionnelle en JavaScript
Programmation fonctionnelle en JavaScriptProgrammation fonctionnelle en JavaScript
Programmation fonctionnelle en JavaScriptLoï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, objectsHusain Dalal
 
6. Generics. Collections. Streams
6. Generics. Collections. Streams6. Generics. Collections. Streams
6. Generics. Collections. StreamsDEVTYPE
 
Леонид Шевцов «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 GoEleanor 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 ProgrammersAppier
 

La actualidad más candente (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
 

Destacado (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 a 2 BytesC++ course_2014_c3_ function basics&parameters and overloading

C++ process new
C++ process newC++ process new
C++ process new敬倫 林
 
Lecture 9_Classes.pptx
Lecture 9_Classes.pptxLecture 9_Classes.pptx
Lecture 9_Classes.pptxNelyJay
 
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++ applicationDaniele Pallastrelli
 
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-ee01083101premrings
 
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 JobyGrejoJoby1
 
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 finalAhalyaR
 

Similar a 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
 

Más de 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 conceptkinan 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 conceptkinan 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_graphkinan keshkeh
 
2Bytesprog2 course_2014_c8_units
2Bytesprog2 course_2014_c8_units2Bytesprog2 course_2014_c8_units
2Bytesprog2 course_2014_c8_unitskinan keshkeh
 
2Bytesprog2 course_2014_c7_double_lists
2Bytesprog2 course_2014_c7_double_lists2Bytesprog2 course_2014_c7_double_lists
2Bytesprog2 course_2014_c7_double_listskinan 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 listkinan keshkeh
 
2Bytesprog2 course_2014_c5_pointers
2Bytesprog2 course_2014_c5_pointers2Bytesprog2 course_2014_c5_pointers
2Bytesprog2 course_2014_c5_pointerskinan keshkeh
 
2Bytesprog2 course_2014_c4_binaryfiles
2Bytesprog2 course_2014_c4_binaryfiles2Bytesprog2 course_2014_c4_binaryfiles
2Bytesprog2 course_2014_c4_binaryfileskinan keshkeh
 
2Bytesprog2 course_2014_c3_txtfiles
2Bytesprog2 course_2014_c3_txtfiles2Bytesprog2 course_2014_c3_txtfiles
2Bytesprog2 course_2014_c3_txtfileskinan keshkeh
 
2Bytesprog2 course_2014_c2_records
2Bytesprog2 course_2014_c2_records2Bytesprog2 course_2014_c2_records
2Bytesprog2 course_2014_c2_recordskinan keshkeh
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_setskinan keshkeh
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_setskinan keshkeh
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_setskinan keshkeh
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_setskinan keshkeh
 
2 BytesC++ course_2014_c13_ templates
2 BytesC++ course_2014_c13_ templates2 BytesC++ course_2014_c13_ templates
2 BytesC++ course_2014_c13_ templateskinan keshkeh
 
2 BytesC++ course_2014_c12_ polymorphism
2 BytesC++ course_2014_c12_ polymorphism2 BytesC++ course_2014_c12_ polymorphism
2 BytesC++ course_2014_c12_ polymorphismkinan keshkeh
 

Más de 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
 

Último

%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...chiefasafspells
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is insideshinachiaurasa2
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxAnnaArtyushina1
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...masabamasaba
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benonimasabamasaba
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationJuha-Pekka Tolvanen
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburgmasabamasaba
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 

Último (20)

%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 

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