SlideShare a Scribd company logo
1 of 48
Download to read offline
Kinan keshkeh 
IT Engineering-Damascus University 
3rd year 
Summer course- 2014 
2 bytes team
•How are you today ? 
•Feel good with Functions ? 
•Any Ques ?
•Do you want to become a real programmer ?!!
Smashing keyboards !!
Arrays !
Arrays 
•Type_Name Array_Name [Declared_Size] ;
Arrays 
•Type_Name Array_Name [Declared_Size] ; 
The size of Array
Arrays 
•Type_Name Array_Name [Declared_Size] ; 
The size of Array 
But the index : 0  size -1
Arrays 
•Type_Name Array_Name [Declared_Size] ; 
• int score[5]; 
• int next, score[5], max ;
Arrays 
#include <iostream> using namespace std; int main( ) { const int NUMBER_OF_STUDENTS=5; int i, score[NUMBER_OF_STUDENTS],max; cout << "Enter "<< NUMBER_OF_STUDENTS<<" scores:n"; cin >> score[0]; max = score[0]; for (i = 1; i < NUMBER_OF_STUDENTS ; i++){ cin >> score[i]; If (score[i] > max) max = score[i]; } //max is the largest of the values score[0],..., score[i]. cout << "The highest score is " << max << endl << "The scores and theirn" << "differences from the highest are:n"; for (i = 0; i < NUMBER_OF_STUDENTS; i++) cout << score[i] << " off by " << (max - score[i]) << endl; return 0; } 
Enter 5 scores: 
5 9 2 10 6 
The highest score is 10 
The scores and their 
differences from the highest are: 
5 off by 5 
9 off by 1 
2 off by 8 
10 off by 0 
6 off by 4
•Array in Memory 
•If you pass the domain 0 size -1 , you will not get any error message ! 
•In print especially : you will have random values . 
•In cin (inputting values) : you will change other variables values. 
Arrays in memory 
Arrays
Arrays 
•Array in Memory 
•If you pass the domain 0 size -1 , you will not get any error message !
•Initializing Arrays 
•Initialized with random values in memory . 
• int score[5]={ 1, 20 ,100 }; 
• int score[5]; 
• int score[5]={ 1, 20 ,100 , 5 , 3 }; 
• score[3] == 0 ; score[4] == 0 ; 
• int score[] ={ 1, 20 ,100 , 5 , 3 }; 
Initializing Arrays 
Arrays
Arrays 
•Initializing Arrays 
•Initialized with random values in memory . 
• int score[5]={ 1, 20 ,100 }; 
• int score[5]; 
• int score[5]={ 1, 20 ,100 , 5 , 3 }; 
• score[3] == 0 ; score[4] == 0 ; 
• int score[] ={ 1, 20 ,100 , 5 , 3 };
Arrays 
•Initializing Arrays 
•Initialized with random values in memory . 
• int score[5]={ 1, 20 ,100 }; 
• int score[5]; 
• int score[5]={ 1, 20 ,100 , 5 , 3 }; 
• score[3] == 0 ; score[4] == 0; 
• int score[] ={ 1, 20 ,100 , 5 , 3 }; 
• int score[] ={ 1, 20 };
Arrays 
•Initializing Arrays 
•Initialized with random values in memory . 
• int score[5]={ 1, 20 ,100 }; 
• int score[5]; 
• int score[5]={ 1, 20 ,100 , 5 , 3 }; 
• score[3] == 0 ; score[4] == 0 ; 
• int score[] ={ 1, 20 ,100 , 5 , 3 }; 
• int score[] ={ 1, 20 };
•Array in Functions 
•It’s like calling variables by reference. 
Array in Functions 
Arrays
Arrays 
#include <iostream> using namespace std; void fillUp(int a[], int size); void asSort(int a[], int size); void print(int a[], int size); int main(){ const int numberOfScores = 5; int score[numberOfScores]; fillUp(score,numberOfScores); asSort(score,numberOfScores); cout <<"the ascendent array is: "; print(score,numberOfScores); return 0; } void fillUp(int a[], int size){ cout << "Enter " << size << " numbers:n"; for (int i = 0; i < size; i++) cin >> a[i]; } void asSort(int a[], int size){ for (int i = 0; i < size-1; i++) for (int j = i+1; j < size; j++) if (a[i]>a[j]){ int temp=a[i]; a[i]=a[j]; a[j]=temp; } } void print(int a[], int size){ for (int i = 0; i < size-1; i++) cout<<a[i]<<", "; cout<<a[size-1]<<endl; }
Arrays 
#include <iostream> 
using namespace std; 
void fillUp(int a[], int size); 
void asSort(int a[], int size); 
void print(int a[], int size); 
int main(){ 
const int numberOfScores = 5; 
int score[numberOfScores]; 
fillUp(score,numberOfScores); 
asSort(score,numberOfScores); 
cout <<"the ascendent array is: "; 
print(score,numberOfScores); 
return 0; 
} 
void fillUp(int a[], int size){ 
cout << "Enter " << size << " numbers:n"; 
for (int i = 0; i < size; i++) 
cin >> a[i]; 
} 
void asSort(int a[], int size){ 
for (int i = 0; i < size-1; i++) 
for (int j = i+1; j < size; j++) 
if (a[i]>a[j]){ 
int temp=a[i]; 
a[i]=a[j]; 
a[j]=temp; 
} 
} 
void print(int a[], int size){ 
for (int i = 0; i < size-1; i++) 
cout<<a[i]<<", "; 
cout<<a[size-1]<<endl; 
} 
Like calling 
by 
reference
Arrays 
#include <iostream> using namespace std; void fillUp(int a[], int size); void asSort(int a[], int size); void print(int a[], int size); int main(){ const int numberOfScores = 5; int score[numberOfScores]; fillUp(score,numberOfScores); asSort(score,numberOfScores); cout <<"the ascendent array is: "; print(score,numberOfScores); return 0; } void fillUp(int a[], int size){ cout << "Enter " << size << " numbers:n"; for (int i = 0; i < size; i++) cin >> a[i]; } void asSort(int a[], int size){ for (int i = 0; i < size-1; i++) for (int j = i+1; j < size; j++) if (a[i]>a[j]){ int temp=a[i]; a[i]=a[j]; a[j]=temp; } } void print(int a[], int size){ for (int i = 0; i < size-1; i++) cout<<a[i]<<", "; cout<<a[size-1]<<endl; } 
So , The array values ,are stored in array after calling !
Arrays 
#include <iostream> using namespace std; void fillUp(int a[], int size); void asSort(int a[], int size); void print(int a[], int size); int main(){ const int numberOfScores = 5; int score[numberOfScores]; fillUp(score,numberOfScores); asSort(score,numberOfScores); cout <<"the ascendent array is: "; print(score,numberOfScores); return 0; } void fillUp(int a[], int size){ cout << "Enter " << size << " numbers:n"; for (int i = 0; i < size; i++) cin >> a[i]; } void asSort(int a[], int size){ for (int i = 0; i < size-1; i++) for (int j = i+1; j < size; j++) if (a[i]>a[j]){ int temp=a[i]; a[i]=a[j]; a[j]=temp; } } void print(int a[], int size){ for (int i = 0; i < size-1; i++) cout<<a[i]<<", "; cout<<a[size-1]<<endl; } 
The function knows the array position in memory and its type.
Arrays 
#include <iostream> 
using namespace std; 
void fillUp(int a[], int size); 
void asSort(int a[], int size); 
void print(int a[], int size); 
int main(){ 
const int numberOfScores = 5; 
int score[numberOfScores]; 
fillUp(score,numberOfScores); 
asSort(score,numberOfScores); 
cout <<"the ascendent array is: "; 
print(score,numberOfScores); 
return 0; 
} 
void fillUp(int a[], int size){ 
cout << "Enter " << size << " numbers:n"; 
for (int i = 0; i < size; i++) 
cin >> a[i]; 
} 
void asSort(int a[], int size){ 
for (int i = 0; i < size-1; i++) 
for (int j = i+1; j < size; j++) 
if (a[i]>a[j]){ 
int temp=a[i]; 
a[i]=a[j]; 
a[j]=temp; 
} 
} 
void print(int a[], int size){ 
for (int i = 0; i < size-1; i++) 
cout<<a[i]<<", "; 
cout<<a[size-1]<<endl; 
} 
So , you don’t have to write its size !!
Arrays 
#include <iostream> 
using namespace std; 
void fillUp(int a[], int size); 
void asSort(int a[], int size); 
void print(int a[], int size); 
int main(){ 
const int numberOfScores = 5; 
int score[numberOfScores]; 
fillUp(score,numberOfScores); 
asSort(score,numberOfScores); 
cout <<"the ascendent array is: "; 
print(score,numberOfScores); 
return 0; 
} 
void fillUp(int a[], int size){ 
cout << "Enter " << size << " numbers:n"; 
for (int i = 0; i < size; i++) 
cin >> a[i]; 
} 
void asSort(int a[], int size){ 
for (int i = 0; i < size-1; i++) 
for (int j = i+1; j < size; j++) 
if (a[i]>a[j]){ 
int temp=a[i]; 
a[i]=a[j]; 
a[j]=temp; 
} 
} 
void print(int a[], int size){ 
for (int i = 0; i < size-1; i++) 
cout<<a[i]<<", "; 
cout<<a[size-1]<<endl; 
} 
Put in calling the array name !
Arrays 
#include <iostream> 
using namespace std; 
void fillUp(int a[], int size); 
void asSort(int a[], int size); 
void print(int a[], int size); 
int main(){ 
const int numberOfScores = 5; 
int score[numberOfScores]; 
fillUp(score,numberOfScores); 
asSort(score,numberOfScores); 
cout <<"the ascendent array is: "; 
print(score,numberOfScores); 
return 0; 
} 
void fillUp(int a[], int size){ 
cout << "Enter " << size << " numbers:n"; 
for (int i = 0; i < size; i++) 
cin >> a[i]; 
} 
void asSort(int a[], int size){ 
for (int i = 0; i < size-1; i++) 
for (int j = i+1; j < size; j++) 
if (a[i]>a[j]){ 
int temp=a[i]; 
a[i]=a[j]; 
a[j]=temp; 
} 
} 
void print(int a[], int size){ 
for (int i = 0; i < size-1; i++) 
cout<<a[i]<<", "; 
cout<<a[size-1]<<endl; 
} 
Enter 5 numbers: 1 4 2 3 1 the ascendent sorted array is: 1, 1, 2, 3, 4
Arrays 
•Array in Functions 
•It’s like calling variables by reference. 
•Constant Array Parameter: 
•void print(const int a[], int size)
Arrays 
•Array in Functions 
•It’s like calling variables by reference. 
•Constant Array Parameter: 
•void print(const int a[], int size) 
to prevent changing in its values !
Arrays 
#include <iostream> using namespace std; void fillUp(int a[], int size); void asSort(int a[], int size); void print(int a[], int size); int main(){ const int numberOfScores = 5; int score[numberOfScores]; fillUp(score,numberOfScores); asSort(score,numberOfScores); cout <<"the ascendent array is: "; print(score,numberOfScores); return 0; } void fillUp(int a[], int size){ cout << "Enter " << size << " numbers:n"; for (int i = 0; i < size; i++) cin >> a[i]; } void asSort(int a[], int size){ for (int i = 0; i < size-1; i++) for (int j = i+1; j < size; j++) if (a[i]>a[j]){ int temp=a[i]; a[i]=a[j]; a[j]=temp; } } void print(int a[], int size){ for (int i = 0; i < size-1; i++) cout<<a[i]<<", "; cout<<a[size-1]<<endl; }
Arrays 
#include <iostream> 
using namespace std; 
void fillUp(int a[], int size); 
void asSort(int a[], int size); 
void print(int a[], int size); 
int main(){ 
const int numberOfScores = 5; 
int score[numberOfScores]; 
fillUp(score,numberOfScores); 
asSort(score,numberOfScores); 
cout <<"the ascendent array is: "; 
print(score,numberOfScores); 
return 0; 
} 
void fillUp(int a[], int size){ 
cout << "Enter " << size << " numbers:n"; 
for (int i = 0; i < size; i++) 
cin >> a[i]; 
} 
void asSort(int a[], int size){ 
for (int i = 0; i < size-1; i++) 
for (int j = i+1; j < size; j++) 
if (a[i]>a[j]){ 
int temp=a[i]; 
a[i]=a[j]; 
a[j]=temp; 
} 
} 
void print( const int a[], int size){ 
for (int i = 0; i < size-1; i++) 
cout<<a[i]<<", "; 
cout<<a[size-1]<<endl; 
}
Arrays 
#include <iostream> using namespace std; void fillUp(int a[], int size); void asSort(int a[], int size); void print(int a[], int size); int main(){ const int numberOfScores = 5; int score[numberOfScores]; fillUp(score,numberOfScores); asSort(score,numberOfScores); cout <<"the ascendent array is: "; print(score,numberOfScores); return 0; } void fillUp(int a[], int size){ cout << "Enter " << size << " numbers:n"; for (int i = 0; i < size; i++) cin >> a[i]; } void asSort(int a[], int size){ for (int i = 0; i < size-1; i++) for (int j = i+1; j < size; j++) if (a[i]>a[j]){ int temp=a[i]; a[i]=a[j]; a[j]=temp; } } void print( const int a[], int size){ for (int i = 0; i < size-1; i++) cout<<a[i]<<", "; cout<<a[size-1]<<endl; }
Arrays 
•Array in Functions 
•It’s like calling variables by reference. 
•Constant Array Parameter: 
•void print(const int a[], int size) 
•Functions can’t returns Arrays !! 
•Int a[] add(int a [] , int b[] , int size )
Arrays 
•Array in Functions 
•It’s like calling variables by reference. 
•Constant Array Parameter: 
•void print(const int a[], int size) 
False !! 
•Functions can’t returns Arrays !! 
•Int a[] add(int a [] , int b[] , int size )
Arrays 
•Array in Functions 
•It’s like calling variables by reference. 
•Constant Array Parameter: 
•void print(const int a[], int size) 
In pointers … 
True 
•Functions can’t returns Arrays !! 
•Int * add(int a [] , int b[] , int size )
Arrays 
•Like in Pascal , you will reserve a Maximum size (cause you are unable to know how many numbers for.ex the user want to input . 
•So , determine max size , then save the real size in variable . 
•void fillUp(int b[], int size, int maxSize)
•Multidimensional Arrays 
•Type Array_Name[Size_Dim_1][Size_Dim_2]...[Size_Dim_Last]; 
Multidimensional Arrays 
Arrays
Arrays 
•Multidimensional Arrays 
•One dim array : const int size=6 ; int arr[size]; 
•Two dim array : const int rows=3 ; const int columns=5; int arr[rows][columns]; 
•Dimension:
Arrays 
•Multidimensional Arrays 
•One dim array : const int size=6 ; int arr[size]; 
•Two dim array : const int rows=3 ; const int columns=5; int arr[rows][columns]; 
•Initialize : 
•Dimension: 
•One dim array : int arr[size]= {20 , 10 , 5 , 6 }; 
•Two dim array : int arr[rows][columns]={ {20 , 10 , 5 , 6 } , {4, 7, 1, 2} , {50, 10 , 4, 6 } };
Arrays 
•Multidimensional Arrays 
•One dim array : const int size=6 ; int arr[size]; 
•Two dim array : const int rows=3 ; const int columns=5; int arr[rows][columns]; 
•Initialize : 
•Dimension: 
•One dim array : int arr[]= {20 , 10 , 5 , 6 }; 
•Two dim array : int arr[rows][columns]={ {20 , 10 , 5 , 6 } , {4, 7, 1, 2} , {50, 10 , 4, 6 } }; 
Like this one dim 
It could be []
Arrays 
•Multidimensional Arrays 
•One dim array : const int size=6 ; int arr[size]; 
•Two dim array : const int rows=3 ; const int columns=5; int arr[rows][columns]; 
•Initialize : 
•Dimention: 
•One dim array : int arr[]= {20 , 10 , 5 , 6 }; 
•Two dim array : int arr[][columns]={ {20 , 10 , 5 , 6 } , {4, 7, 1, 2} , {50, 10 , 4, 6 } }; 
This in two dim 
it could be []
Arrays 
•Multidimensional Arrays 
•In functions: 
•One dim array : void getPage(char p[] , int sizeDimension1); 
•Two dim array : void getPage(char p[][100] , int sizeDimension1);
Arrays 
•Multidimensional Arrays 
•In functions: 
•One dim array : void getPage(char p[] , int sizeDimension1); 
•Two dim array : void getPage(char p[][100] , int sizeDimension1); 
function must knows the other dimensions !
Arrays 
•Multidimensional Arrays 
•Inputting by user: 
•One dim array : int arr[size]; for ( int i=0 ; i<size ; i++ ) cin>>arr[i]; 
•Two dim array : int arr[rows][columns]; for ( int i=0 ; i<rows ; i++ ) for ( int j=0 ; i<columns ; j++ ) cin>>arr[i][j]
Arrays 
•Multidimensional Arrays 
•One dim array : const int size=6 ; int arr[size]; 
•Two dim array : const int rows=3 ; const int columns=5; int arr[rows][columns]; 
•Dimention: 
•Three dim array: double _3dPicture[10][20][30];
Homework
Homework
Homework 
•Write a program that calls a function calculates the Average of students marks and print it . 
•And another function that finds the max mark of them .
That’s for today 
That’s for today guys !!
That’s for today 
Go and eat !
2 bytes team 
Group : group link 
Mobile phone- Kinan : 0994385748 
Facebook account : kinan’s account 
2 bytes team

More Related Content

What's hot (20)

C++ L03-Control Structure
C++ L03-Control StructureC++ L03-Control Structure
C++ L03-Control Structure
 
Array
ArrayArray
Array
 
P2 2017 python_strings
P2 2017 python_stringsP2 2017 python_strings
P2 2017 python_strings
 
C programming
C programmingC programming
C programming
 
Cse115 lecture14strings part01
Cse115 lecture14strings part01Cse115 lecture14strings part01
Cse115 lecture14strings part01
 
Array notes
Array notesArray notes
Array notes
 
Arrays in C language
Arrays in C languageArrays in C language
Arrays in C language
 
C++ L04-Array+String
C++ L04-Array+StringC++ L04-Array+String
C++ L04-Array+String
 
Swift Study #2
Swift Study #2Swift Study #2
Swift Study #2
 
C Prog - Array
C Prog - ArrayC Prog - Array
C Prog - Array
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Lecture 2: arrays and pointers
Lecture 2: arrays and pointersLecture 2: arrays and pointers
Lecture 2: arrays and pointers
 
Data structure
Data structureData structure
Data structure
 
Combinator parsing
Combinator parsingCombinator parsing
Combinator parsing
 
STOCK APPLICATION USING CORBA
STOCK APPLICATION USING CORBASTOCK APPLICATION USING CORBA
STOCK APPLICATION USING CORBA
 
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
 
Programs
ProgramsPrograms
Programs
 
C++ L06-Pointers
C++ L06-PointersC++ L06-Pointers
C++ L06-Pointers
 
SPL 13 | Character Array(String) in C
SPL 13 | Character Array(String) in CSPL 13 | Character Array(String) in C
SPL 13 | Character Array(String) in C
 
Useful c programs
Useful c programsUseful c programs
Useful c programs
 

Viewers also liked

Canon eos rebel t2i 18 mp
Canon eos rebel t2i 18 mpCanon eos rebel t2i 18 mp
Canon eos rebel t2i 18 mpbuycanon
 
The Truth About - Diversity, Inclusion, Feminism, Charity, Green, CSR, Ethics...
The Truth About - Diversity, Inclusion, Feminism, Charity, Green, CSR, Ethics...The Truth About - Diversity, Inclusion, Feminism, Charity, Green, CSR, Ethics...
The Truth About - Diversity, Inclusion, Feminism, Charity, Green, CSR, Ethics...Aditya Yadav
 
Bangladeshi Mobile Users in Facebook
Bangladeshi Mobile Users in FacebookBangladeshi Mobile Users in Facebook
Bangladeshi Mobile Users in FacebookMonoshita Ayruani
 
Friendship
FriendshipFriendship
FriendshipMateo323
 
Evaluación de inteligencias múltiples (2)
Evaluación de inteligencias múltiples (2)Evaluación de inteligencias múltiples (2)
Evaluación de inteligencias múltiples (2)gustavohuizar
 
642 1588-1-sm
642 1588-1-sm642 1588-1-sm
642 1588-1-smnunukaz
 
How2lrnwuripodfinal
How2lrnwuripodfinalHow2lrnwuripodfinal
How2lrnwuripodfinalamtrac
 
No49 振り返りの基礎はこれだ!年末特別版 suc3rum-20141219
No49 振り返りの基礎はこれだ!年末特別版 suc3rum-20141219No49 振り返りの基礎はこれだ!年末特別版 suc3rum-20141219
No49 振り返りの基礎はこれだ!年末特別版 suc3rum-20141219Sukusuku Scrum
 
Ed White masccc 2013
Ed White masccc 2013Ed White masccc 2013
Ed White masccc 2013Jen Boudrie
 
TPC Letter to the Current Owner Offering a Meeting 25 February 2013
TPC Letter to the Current Owner Offering a Meeting 25 February 2013TPC Letter to the Current Owner Offering a Meeting 25 February 2013
TPC Letter to the Current Owner Offering a Meeting 25 February 2013ThePars1885
 
Week 2 Concepts+Models
Week 2 Concepts+ModelsWeek 2 Concepts+Models
Week 2 Concepts+ModelsJohn
 
Avalanche
AvalancheAvalanche
Avalancheoriwwe
 
Bes 2009 26.11.09 Itc Intermediary Presentation
Bes 2009 26.11.09 Itc Intermediary PresentationBes 2009 26.11.09 Itc Intermediary Presentation
Bes 2009 26.11.09 Itc Intermediary Presentationmichael keyes
 
Mechanical
MechanicalMechanical
MechanicalFakin
 

Viewers also liked (20)

Ckd Portfolio
Ckd PortfolioCkd Portfolio
Ckd Portfolio
 
Canon eos rebel t2i 18 mp
Canon eos rebel t2i 18 mpCanon eos rebel t2i 18 mp
Canon eos rebel t2i 18 mp
 
The Truth About - Diversity, Inclusion, Feminism, Charity, Green, CSR, Ethics...
The Truth About - Diversity, Inclusion, Feminism, Charity, Green, CSR, Ethics...The Truth About - Diversity, Inclusion, Feminism, Charity, Green, CSR, Ethics...
The Truth About - Diversity, Inclusion, Feminism, Charity, Green, CSR, Ethics...
 
Notion réseaux
Notion réseauxNotion réseaux
Notion réseaux
 
Bangladeshi Mobile Users in Facebook
Bangladeshi Mobile Users in FacebookBangladeshi Mobile Users in Facebook
Bangladeshi Mobile Users in Facebook
 
Ind guj-001-ppt
Ind guj-001-pptInd guj-001-ppt
Ind guj-001-ppt
 
S subramanian
S subramanianS subramanian
S subramanian
 
Friendship
FriendshipFriendship
Friendship
 
Evaluación de inteligencias múltiples (2)
Evaluación de inteligencias múltiples (2)Evaluación de inteligencias múltiples (2)
Evaluación de inteligencias múltiples (2)
 
642 1588-1-sm
642 1588-1-sm642 1588-1-sm
642 1588-1-sm
 
Viky
VikyViky
Viky
 
How2lrnwuripodfinal
How2lrnwuripodfinalHow2lrnwuripodfinal
How2lrnwuripodfinal
 
No49 振り返りの基礎はこれだ!年末特別版 suc3rum-20141219
No49 振り返りの基礎はこれだ!年末特別版 suc3rum-20141219No49 振り返りの基礎はこれだ!年末特別版 suc3rum-20141219
No49 振り返りの基礎はこれだ!年末特別版 suc3rum-20141219
 
Ed White masccc 2013
Ed White masccc 2013Ed White masccc 2013
Ed White masccc 2013
 
TPC Letter to the Current Owner Offering a Meeting 25 February 2013
TPC Letter to the Current Owner Offering a Meeting 25 February 2013TPC Letter to the Current Owner Offering a Meeting 25 February 2013
TPC Letter to the Current Owner Offering a Meeting 25 February 2013
 
Week 2 Concepts+Models
Week 2 Concepts+ModelsWeek 2 Concepts+Models
Week 2 Concepts+Models
 
Freedom As an active state
Freedom As an active stateFreedom As an active state
Freedom As an active state
 
Avalanche
AvalancheAvalanche
Avalanche
 
Bes 2009 26.11.09 Itc Intermediary Presentation
Bes 2009 26.11.09 Itc Intermediary PresentationBes 2009 26.11.09 Itc Intermediary Presentation
Bes 2009 26.11.09 Itc Intermediary Presentation
 
Mechanical
MechanicalMechanical
Mechanical
 

Similar to 2 BytesC++ course_2014_c4_ arrays

#include iostream #include fstream #include map #include.pdf
#include iostream #include fstream #include map #include.pdf#include iostream #include fstream #include map #include.pdf
#include iostream #include fstream #include map #include.pdfinbox5
 
Array and string in C++_093547 analysis.pptx
Array and string in C++_093547 analysis.pptxArray and string in C++_093547 analysis.pptx
Array and string in C++_093547 analysis.pptxJumanneChiyanda
 
Mcs011 solved assignment by divya singh
Mcs011 solved assignment by divya singhMcs011 solved assignment by divya singh
Mcs011 solved assignment by divya singhDIVYA SINGH
 
Programming with GUTs
Programming with GUTsProgramming with GUTs
Programming with GUTsKevlin Henney
 
Programming with GUTs
Programming with GUTsProgramming with GUTs
Programming with GUTsKevlin Henney
 
COA_remaining_lab_works_077BCT033.pdf
COA_remaining_lab_works_077BCT033.pdfCOA_remaining_lab_works_077BCT033.pdf
COA_remaining_lab_works_077BCT033.pdfJavedAnsari236392
 
SP-First-Lecture.ppt
SP-First-Lecture.pptSP-First-Lecture.ppt
SP-First-Lecture.pptFareedIhsas
 
Templates in C++
Templates in C++Templates in C++
Templates in C++Tech_MX
 
#include stdio.hint main() {     int count;     FILE myFi.pdf
#include stdio.hint main() {     int count;     FILE myFi.pdf#include stdio.hint main() {     int count;     FILE myFi.pdf
#include stdio.hint main() {     int count;     FILE myFi.pdfanithareadymade
 
Network lap pgms 7th semester
Network lap pgms 7th semesterNetwork lap pgms 7th semester
Network lap pgms 7th semesterDOSONKA Group
 
11 1. multi-dimensional array eng
11 1. multi-dimensional array eng11 1. multi-dimensional array eng
11 1. multi-dimensional array eng웅식 전
 
c++ #include -iostream- using namespace std- void InsertionSort(int nu.pdf
c++ #include -iostream- using namespace std- void InsertionSort(int nu.pdfc++ #include -iostream- using namespace std- void InsertionSort(int nu.pdf
c++ #include -iostream- using namespace std- void InsertionSort(int nu.pdfkuldeepkumarapgsi
 
Programming Fundamentals Arrays and Strings
Programming Fundamentals   Arrays and Strings Programming Fundamentals   Arrays and Strings
Programming Fundamentals Arrays and Strings imtiazalijoono
 

Similar to 2 BytesC++ course_2014_c4_ arrays (20)

#include iostream #include fstream #include map #include.pdf
#include iostream #include fstream #include map #include.pdf#include iostream #include fstream #include map #include.pdf
#include iostream #include fstream #include map #include.pdf
 
Array and string in C++_093547 analysis.pptx
Array and string in C++_093547 analysis.pptxArray and string in C++_093547 analysis.pptx
Array and string in C++_093547 analysis.pptx
 
Mcs011 solved assignment by divya singh
Mcs011 solved assignment by divya singhMcs011 solved assignment by divya singh
Mcs011 solved assignment by divya singh
 
Programming with GUTs
Programming with GUTsProgramming with GUTs
Programming with GUTs
 
Programming with GUTs
Programming with GUTsProgramming with GUTs
Programming with GUTs
 
COA_remaining_lab_works_077BCT033.pdf
COA_remaining_lab_works_077BCT033.pdfCOA_remaining_lab_works_077BCT033.pdf
COA_remaining_lab_works_077BCT033.pdf
 
SP-First-Lecture.ppt
SP-First-Lecture.pptSP-First-Lecture.ppt
SP-First-Lecture.ppt
 
Java arrays
Java    arraysJava    arrays
Java arrays
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Array
ArrayArray
Array
 
2DArrays.ppt
2DArrays.ppt2DArrays.ppt
2DArrays.ppt
 
Templates in C++
Templates in C++Templates in C++
Templates in C++
 
#include stdio.hint main() {     int count;     FILE myFi.pdf
#include stdio.hint main() {     int count;     FILE myFi.pdf#include stdio.hint main() {     int count;     FILE myFi.pdf
#include stdio.hint main() {     int count;     FILE myFi.pdf
 
Array-part1
Array-part1Array-part1
Array-part1
 
Network lap pgms 7th semester
Network lap pgms 7th semesterNetwork lap pgms 7th semester
Network lap pgms 7th semester
 
11 1. multi-dimensional array eng
11 1. multi-dimensional array eng11 1. multi-dimensional array eng
11 1. multi-dimensional array eng
 
Java introduction
Java introductionJava introduction
Java introduction
 
c++ #include -iostream- using namespace std- void InsertionSort(int nu.pdf
c++ #include -iostream- using namespace std- void InsertionSort(int nu.pdfc++ #include -iostream- using namespace std- void InsertionSort(int nu.pdf
c++ #include -iostream- using namespace std- void InsertionSort(int nu.pdf
 
Programming Fundamentals Arrays and Strings
Programming Fundamentals   Arrays and Strings Programming Fundamentals   Arrays and Strings
Programming Fundamentals Arrays and Strings
 
Arrays in java
Arrays in javaArrays in java
Arrays in java
 

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

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
 

2 BytesC++ course_2014_c4_ arrays

  • 1. Kinan keshkeh IT Engineering-Damascus University 3rd year Summer course- 2014 2 bytes team
  • 2. •How are you today ? •Feel good with Functions ? •Any Ques ?
  • 3. •Do you want to become a real programmer ?!!
  • 6. Arrays •Type_Name Array_Name [Declared_Size] ;
  • 7. Arrays •Type_Name Array_Name [Declared_Size] ; The size of Array
  • 8. Arrays •Type_Name Array_Name [Declared_Size] ; The size of Array But the index : 0  size -1
  • 9. Arrays •Type_Name Array_Name [Declared_Size] ; • int score[5]; • int next, score[5], max ;
  • 10. Arrays #include <iostream> using namespace std; int main( ) { const int NUMBER_OF_STUDENTS=5; int i, score[NUMBER_OF_STUDENTS],max; cout << "Enter "<< NUMBER_OF_STUDENTS<<" scores:n"; cin >> score[0]; max = score[0]; for (i = 1; i < NUMBER_OF_STUDENTS ; i++){ cin >> score[i]; If (score[i] > max) max = score[i]; } //max is the largest of the values score[0],..., score[i]. cout << "The highest score is " << max << endl << "The scores and theirn" << "differences from the highest are:n"; for (i = 0; i < NUMBER_OF_STUDENTS; i++) cout << score[i] << " off by " << (max - score[i]) << endl; return 0; } Enter 5 scores: 5 9 2 10 6 The highest score is 10 The scores and their differences from the highest are: 5 off by 5 9 off by 1 2 off by 8 10 off by 0 6 off by 4
  • 11. •Array in Memory •If you pass the domain 0 size -1 , you will not get any error message ! •In print especially : you will have random values . •In cin (inputting values) : you will change other variables values. Arrays in memory Arrays
  • 12. Arrays •Array in Memory •If you pass the domain 0 size -1 , you will not get any error message !
  • 13. •Initializing Arrays •Initialized with random values in memory . • int score[5]={ 1, 20 ,100 }; • int score[5]; • int score[5]={ 1, 20 ,100 , 5 , 3 }; • score[3] == 0 ; score[4] == 0 ; • int score[] ={ 1, 20 ,100 , 5 , 3 }; Initializing Arrays Arrays
  • 14. Arrays •Initializing Arrays •Initialized with random values in memory . • int score[5]={ 1, 20 ,100 }; • int score[5]; • int score[5]={ 1, 20 ,100 , 5 , 3 }; • score[3] == 0 ; score[4] == 0 ; • int score[] ={ 1, 20 ,100 , 5 , 3 };
  • 15. Arrays •Initializing Arrays •Initialized with random values in memory . • int score[5]={ 1, 20 ,100 }; • int score[5]; • int score[5]={ 1, 20 ,100 , 5 , 3 }; • score[3] == 0 ; score[4] == 0; • int score[] ={ 1, 20 ,100 , 5 , 3 }; • int score[] ={ 1, 20 };
  • 16. Arrays •Initializing Arrays •Initialized with random values in memory . • int score[5]={ 1, 20 ,100 }; • int score[5]; • int score[5]={ 1, 20 ,100 , 5 , 3 }; • score[3] == 0 ; score[4] == 0 ; • int score[] ={ 1, 20 ,100 , 5 , 3 }; • int score[] ={ 1, 20 };
  • 17. •Array in Functions •It’s like calling variables by reference. Array in Functions Arrays
  • 18. Arrays #include <iostream> using namespace std; void fillUp(int a[], int size); void asSort(int a[], int size); void print(int a[], int size); int main(){ const int numberOfScores = 5; int score[numberOfScores]; fillUp(score,numberOfScores); asSort(score,numberOfScores); cout <<"the ascendent array is: "; print(score,numberOfScores); return 0; } void fillUp(int a[], int size){ cout << "Enter " << size << " numbers:n"; for (int i = 0; i < size; i++) cin >> a[i]; } void asSort(int a[], int size){ for (int i = 0; i < size-1; i++) for (int j = i+1; j < size; j++) if (a[i]>a[j]){ int temp=a[i]; a[i]=a[j]; a[j]=temp; } } void print(int a[], int size){ for (int i = 0; i < size-1; i++) cout<<a[i]<<", "; cout<<a[size-1]<<endl; }
  • 19. Arrays #include <iostream> using namespace std; void fillUp(int a[], int size); void asSort(int a[], int size); void print(int a[], int size); int main(){ const int numberOfScores = 5; int score[numberOfScores]; fillUp(score,numberOfScores); asSort(score,numberOfScores); cout <<"the ascendent array is: "; print(score,numberOfScores); return 0; } void fillUp(int a[], int size){ cout << "Enter " << size << " numbers:n"; for (int i = 0; i < size; i++) cin >> a[i]; } void asSort(int a[], int size){ for (int i = 0; i < size-1; i++) for (int j = i+1; j < size; j++) if (a[i]>a[j]){ int temp=a[i]; a[i]=a[j]; a[j]=temp; } } void print(int a[], int size){ for (int i = 0; i < size-1; i++) cout<<a[i]<<", "; cout<<a[size-1]<<endl; } Like calling by reference
  • 20. Arrays #include <iostream> using namespace std; void fillUp(int a[], int size); void asSort(int a[], int size); void print(int a[], int size); int main(){ const int numberOfScores = 5; int score[numberOfScores]; fillUp(score,numberOfScores); asSort(score,numberOfScores); cout <<"the ascendent array is: "; print(score,numberOfScores); return 0; } void fillUp(int a[], int size){ cout << "Enter " << size << " numbers:n"; for (int i = 0; i < size; i++) cin >> a[i]; } void asSort(int a[], int size){ for (int i = 0; i < size-1; i++) for (int j = i+1; j < size; j++) if (a[i]>a[j]){ int temp=a[i]; a[i]=a[j]; a[j]=temp; } } void print(int a[], int size){ for (int i = 0; i < size-1; i++) cout<<a[i]<<", "; cout<<a[size-1]<<endl; } So , The array values ,are stored in array after calling !
  • 21. Arrays #include <iostream> using namespace std; void fillUp(int a[], int size); void asSort(int a[], int size); void print(int a[], int size); int main(){ const int numberOfScores = 5; int score[numberOfScores]; fillUp(score,numberOfScores); asSort(score,numberOfScores); cout <<"the ascendent array is: "; print(score,numberOfScores); return 0; } void fillUp(int a[], int size){ cout << "Enter " << size << " numbers:n"; for (int i = 0; i < size; i++) cin >> a[i]; } void asSort(int a[], int size){ for (int i = 0; i < size-1; i++) for (int j = i+1; j < size; j++) if (a[i]>a[j]){ int temp=a[i]; a[i]=a[j]; a[j]=temp; } } void print(int a[], int size){ for (int i = 0; i < size-1; i++) cout<<a[i]<<", "; cout<<a[size-1]<<endl; } The function knows the array position in memory and its type.
  • 22. Arrays #include <iostream> using namespace std; void fillUp(int a[], int size); void asSort(int a[], int size); void print(int a[], int size); int main(){ const int numberOfScores = 5; int score[numberOfScores]; fillUp(score,numberOfScores); asSort(score,numberOfScores); cout <<"the ascendent array is: "; print(score,numberOfScores); return 0; } void fillUp(int a[], int size){ cout << "Enter " << size << " numbers:n"; for (int i = 0; i < size; i++) cin >> a[i]; } void asSort(int a[], int size){ for (int i = 0; i < size-1; i++) for (int j = i+1; j < size; j++) if (a[i]>a[j]){ int temp=a[i]; a[i]=a[j]; a[j]=temp; } } void print(int a[], int size){ for (int i = 0; i < size-1; i++) cout<<a[i]<<", "; cout<<a[size-1]<<endl; } So , you don’t have to write its size !!
  • 23. Arrays #include <iostream> using namespace std; void fillUp(int a[], int size); void asSort(int a[], int size); void print(int a[], int size); int main(){ const int numberOfScores = 5; int score[numberOfScores]; fillUp(score,numberOfScores); asSort(score,numberOfScores); cout <<"the ascendent array is: "; print(score,numberOfScores); return 0; } void fillUp(int a[], int size){ cout << "Enter " << size << " numbers:n"; for (int i = 0; i < size; i++) cin >> a[i]; } void asSort(int a[], int size){ for (int i = 0; i < size-1; i++) for (int j = i+1; j < size; j++) if (a[i]>a[j]){ int temp=a[i]; a[i]=a[j]; a[j]=temp; } } void print(int a[], int size){ for (int i = 0; i < size-1; i++) cout<<a[i]<<", "; cout<<a[size-1]<<endl; } Put in calling the array name !
  • 24. Arrays #include <iostream> using namespace std; void fillUp(int a[], int size); void asSort(int a[], int size); void print(int a[], int size); int main(){ const int numberOfScores = 5; int score[numberOfScores]; fillUp(score,numberOfScores); asSort(score,numberOfScores); cout <<"the ascendent array is: "; print(score,numberOfScores); return 0; } void fillUp(int a[], int size){ cout << "Enter " << size << " numbers:n"; for (int i = 0; i < size; i++) cin >> a[i]; } void asSort(int a[], int size){ for (int i = 0; i < size-1; i++) for (int j = i+1; j < size; j++) if (a[i]>a[j]){ int temp=a[i]; a[i]=a[j]; a[j]=temp; } } void print(int a[], int size){ for (int i = 0; i < size-1; i++) cout<<a[i]<<", "; cout<<a[size-1]<<endl; } Enter 5 numbers: 1 4 2 3 1 the ascendent sorted array is: 1, 1, 2, 3, 4
  • 25. Arrays •Array in Functions •It’s like calling variables by reference. •Constant Array Parameter: •void print(const int a[], int size)
  • 26. Arrays •Array in Functions •It’s like calling variables by reference. •Constant Array Parameter: •void print(const int a[], int size) to prevent changing in its values !
  • 27. Arrays #include <iostream> using namespace std; void fillUp(int a[], int size); void asSort(int a[], int size); void print(int a[], int size); int main(){ const int numberOfScores = 5; int score[numberOfScores]; fillUp(score,numberOfScores); asSort(score,numberOfScores); cout <<"the ascendent array is: "; print(score,numberOfScores); return 0; } void fillUp(int a[], int size){ cout << "Enter " << size << " numbers:n"; for (int i = 0; i < size; i++) cin >> a[i]; } void asSort(int a[], int size){ for (int i = 0; i < size-1; i++) for (int j = i+1; j < size; j++) if (a[i]>a[j]){ int temp=a[i]; a[i]=a[j]; a[j]=temp; } } void print(int a[], int size){ for (int i = 0; i < size-1; i++) cout<<a[i]<<", "; cout<<a[size-1]<<endl; }
  • 28. Arrays #include <iostream> using namespace std; void fillUp(int a[], int size); void asSort(int a[], int size); void print(int a[], int size); int main(){ const int numberOfScores = 5; int score[numberOfScores]; fillUp(score,numberOfScores); asSort(score,numberOfScores); cout <<"the ascendent array is: "; print(score,numberOfScores); return 0; } void fillUp(int a[], int size){ cout << "Enter " << size << " numbers:n"; for (int i = 0; i < size; i++) cin >> a[i]; } void asSort(int a[], int size){ for (int i = 0; i < size-1; i++) for (int j = i+1; j < size; j++) if (a[i]>a[j]){ int temp=a[i]; a[i]=a[j]; a[j]=temp; } } void print( const int a[], int size){ for (int i = 0; i < size-1; i++) cout<<a[i]<<", "; cout<<a[size-1]<<endl; }
  • 29. Arrays #include <iostream> using namespace std; void fillUp(int a[], int size); void asSort(int a[], int size); void print(int a[], int size); int main(){ const int numberOfScores = 5; int score[numberOfScores]; fillUp(score,numberOfScores); asSort(score,numberOfScores); cout <<"the ascendent array is: "; print(score,numberOfScores); return 0; } void fillUp(int a[], int size){ cout << "Enter " << size << " numbers:n"; for (int i = 0; i < size; i++) cin >> a[i]; } void asSort(int a[], int size){ for (int i = 0; i < size-1; i++) for (int j = i+1; j < size; j++) if (a[i]>a[j]){ int temp=a[i]; a[i]=a[j]; a[j]=temp; } } void print( const int a[], int size){ for (int i = 0; i < size-1; i++) cout<<a[i]<<", "; cout<<a[size-1]<<endl; }
  • 30. Arrays •Array in Functions •It’s like calling variables by reference. •Constant Array Parameter: •void print(const int a[], int size) •Functions can’t returns Arrays !! •Int a[] add(int a [] , int b[] , int size )
  • 31. Arrays •Array in Functions •It’s like calling variables by reference. •Constant Array Parameter: •void print(const int a[], int size) False !! •Functions can’t returns Arrays !! •Int a[] add(int a [] , int b[] , int size )
  • 32. Arrays •Array in Functions •It’s like calling variables by reference. •Constant Array Parameter: •void print(const int a[], int size) In pointers … True •Functions can’t returns Arrays !! •Int * add(int a [] , int b[] , int size )
  • 33. Arrays •Like in Pascal , you will reserve a Maximum size (cause you are unable to know how many numbers for.ex the user want to input . •So , determine max size , then save the real size in variable . •void fillUp(int b[], int size, int maxSize)
  • 34. •Multidimensional Arrays •Type Array_Name[Size_Dim_1][Size_Dim_2]...[Size_Dim_Last]; Multidimensional Arrays Arrays
  • 35. Arrays •Multidimensional Arrays •One dim array : const int size=6 ; int arr[size]; •Two dim array : const int rows=3 ; const int columns=5; int arr[rows][columns]; •Dimension:
  • 36. Arrays •Multidimensional Arrays •One dim array : const int size=6 ; int arr[size]; •Two dim array : const int rows=3 ; const int columns=5; int arr[rows][columns]; •Initialize : •Dimension: •One dim array : int arr[size]= {20 , 10 , 5 , 6 }; •Two dim array : int arr[rows][columns]={ {20 , 10 , 5 , 6 } , {4, 7, 1, 2} , {50, 10 , 4, 6 } };
  • 37. Arrays •Multidimensional Arrays •One dim array : const int size=6 ; int arr[size]; •Two dim array : const int rows=3 ; const int columns=5; int arr[rows][columns]; •Initialize : •Dimension: •One dim array : int arr[]= {20 , 10 , 5 , 6 }; •Two dim array : int arr[rows][columns]={ {20 , 10 , 5 , 6 } , {4, 7, 1, 2} , {50, 10 , 4, 6 } }; Like this one dim It could be []
  • 38. Arrays •Multidimensional Arrays •One dim array : const int size=6 ; int arr[size]; •Two dim array : const int rows=3 ; const int columns=5; int arr[rows][columns]; •Initialize : •Dimention: •One dim array : int arr[]= {20 , 10 , 5 , 6 }; •Two dim array : int arr[][columns]={ {20 , 10 , 5 , 6 } , {4, 7, 1, 2} , {50, 10 , 4, 6 } }; This in two dim it could be []
  • 39. Arrays •Multidimensional Arrays •In functions: •One dim array : void getPage(char p[] , int sizeDimension1); •Two dim array : void getPage(char p[][100] , int sizeDimension1);
  • 40. Arrays •Multidimensional Arrays •In functions: •One dim array : void getPage(char p[] , int sizeDimension1); •Two dim array : void getPage(char p[][100] , int sizeDimension1); function must knows the other dimensions !
  • 41. Arrays •Multidimensional Arrays •Inputting by user: •One dim array : int arr[size]; for ( int i=0 ; i<size ; i++ ) cin>>arr[i]; •Two dim array : int arr[rows][columns]; for ( int i=0 ; i<rows ; i++ ) for ( int j=0 ; i<columns ; j++ ) cin>>arr[i][j]
  • 42. Arrays •Multidimensional Arrays •One dim array : const int size=6 ; int arr[size]; •Two dim array : const int rows=3 ; const int columns=5; int arr[rows][columns]; •Dimention: •Three dim array: double _3dPicture[10][20][30];
  • 45. Homework •Write a program that calls a function calculates the Average of students marks and print it . •And another function that finds the max mark of them .
  • 46. That’s for today That’s for today guys !!
  • 47. That’s for today Go and eat !
  • 48. 2 bytes team Group : group link Mobile phone- Kinan : 0994385748 Facebook account : kinan’s account 2 bytes team