Download presentation
Presentation is loading. Please wait.
Published byBrett Leonard Miller Modified over 6 years ago
1
ㅎㅎ Fourth step for Learning C++ Programming Two functions
Recursive function Call by value Call by reference Array 2-D Array Array Searching
2
You have decide on what the function will look like:
Writing a function You have decide on what the function will look like: Return type Name Types of parameters (number of parameters) You have to write the body (the actual code). 09/2014
3
[ Practice 01 Two functions ]
4
[ Explain 01 Two functions ]
5
[ Practice 02 Recursive function ]
6
[ Explain 02 Recursive function ]
7
[ Practice 03 Call by value ]
8
[ Explain 03 Call by value ]
① ③ ②
9
[ Practice 04 Call by reference ]
10
[ Practice 04 Call by reference ]
① ③ ②
11
An array is a sequence of consecutive memory elements.
C++ Arrays An array is a sequence of consecutive memory elements. The contents of all elements are of the same type. Could be an array of int, double, char, … We can refer to individual elements by giving the position number (index) of the element in the array. 10/2014
12
int foo[6]; Each int is 4 bytes foo[0] foo[1] foo[5] 4 bytes
Memory and Arrays 4 bytes Each int is 4 bytes foo[0] foo[1] int foo[6]; foo[5] 10/2014
13
C++ Arrays indexing start at 0 !!!!!!!
The first element is the 0th element! If you declare an array of n elements, the last one is number n-1. If you try to access element number n it is an error! 10/2014
14
foo[17] foo[i+3] foo[a+b+c]
Array Subscripts The element numbers are called subscripts. foo[i] A subscript can be any integer expression: These are all valid subscripts: foo[17] foo[i+3] foo[a+b+c] 10/2014
15
Initialization Rules for Arrays
1. int cards[4] = {3, 6, 8, 10}; //valid 2. int hand[4] = {}; 3. hand[4]; //invalid 4. float hotelTips[5] = {5.0, 2.5}; //valid - hotelTips[0] = 5.0, - hotelTips[1] = 2.5 5. long totals[500] = {0}; 6. short things[] = {1, 5, 3, 8}; Ο Ο X O Ο Ο
16
[ Practice 05 Array ]
17
[ Explain 05 Array ] index→ index →
18
[ Practice 06 Array 2 ]
19
[ Explain 06 Array 2 ]
20
2-D Array: int A[3][4] Col 0 Col 1 Col 2 Col 3 Row 0 A[0][0] A[0][1]
10/2014
21
2-D Array: int A[3][4] Memory Organization
{ A[0][0] A[0][1] A[0][2] A[1][0] A[1][1] A[1][2] A[2][0] A[2][1] A[2][2] A[3][0] A[3][1] A[3][2] A[0] A[1] A[2] A[3] char A[4][3]; { A is an array of size 4. Each element of A is an array of 3 chars { { 10/2014
22
[ Practice 07 2-D Array ]
23
[ Expain 07 2-D Array ]
24
[ Practice 08 Array Searching ]
25
[ Explain 08 Array Searching ]
26
Bubble-Sort description
The index j in the inner loop travels up the array, comparing adjacent entries in the array (at j and j+1), while the outer loop causes the inner loop to make repeated passes through the array. After the first pass, the largest element is guaranteed to be at the end of the array, after the second pass, the second largest element is in position, and so on. 10/2014
27
[ Practice 09 Bubble Sort ]
28
[ Explain 09 Bubble Sort ]
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.