ㅎㅎ Fourth step for Learning C++ Programming Two functions Recursive function Call by value Call by reference Array 2-D Array Array Searching
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
[ Practice 01 Two functions ]
[ Explain 01 Two functions ]
[ Practice 02 Recursive function ]
[ Explain 02 Recursive function ]
[ Practice 03 Call by value ]
[ Explain 03 Call by value ] ① ③ ②
[ Practice 04 Call by reference ]
[ Practice 04 Call by reference ] ① ③ ②
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
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
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
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
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 Ο Ο
[ Practice 05 Array ]
[ Explain 05 Array ] index→ 0 1 2 index → 0 1 2
[ Practice 06 Array 2 ]
[ Explain 06 Array 2 ]
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
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
[ Practice 07 2-D Array ]
[ Expain 07 2-D Array ]
[ Practice 08 Array Searching ]
[ Explain 08 Array Searching ]
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
[ Practice 09 Bubble Sort ]
[ Explain 09 Bubble Sort ]