CS 107 - 8/5/15 The last lecture!!! Final Exam: Friday 8/7/15 at 12:00noon 2 hours for the exam. Same format as the Midterm: - 20 multiple choice questions - 3 write code questions Topics for the exam will include: - Material from Exam 1 - types & varaibles - operators - if statements - looping - Nest versions of info from exam 1 - for statements - arrays - dynamic (grow) - static array declaration: int arr1[50]; - dynamic array declaration: int* arr2; - functions - pass-by-value vs pass-by-reference void funct1 ( int pbvalue, int & pbreference ) { .... - simple recursion - return values and return statements - "returning" multiple values from a function - structures - parallel array alternative - file input/output - end of file check Project 5 is due this evening Exam Questions Ideas: Array questions What is the value in variable z when the following code finishes? int arr[5]; int z; int i; for ( i = 0 ; i < 5 ; i++) arr[i] = 3 * i; z = 0; for ( i = 0 ; i < 5 ; i++ ) z = z + arr[i]; arr: 0 3 6 9 12 pos: 0 1 2 3 4 z: 0 3 9 18 30 What are the values stored in the array when the following code finishes? int arr[5]; int x; int i; for ( i = 0 ; i < 5 ; i++) arr[i] = 3 * i; x = 0; for ( i = 0 ; i < 5 ; i++) { x = x + arr[i]; arr[i] = x; } arr: 0 3 9 18 30 pos: 0 1 2 3 4 x: 0 3 9 18 30 What are the values stored in the array when the following code finishes? int arr[5]; int x; int i; for ( i = 0 ; i < 5 ; i++) arr[i] = 3 * i; x = 0; for ( i = 4 ; i >= 0 ; i--) { x = x + arr[i]; arr[i] = x; } arr: 30 30 27 21 12 pos: 0 1 2 3 4 x: 0 12 21 27 30 What are the values stored in the array when the following code finishes? int arr[5]; int x; int i; for ( i = 0 ; i < 5 ; i++) arr[i] = 3 * i; x = 0; for ( i = 4 ; i >= 0 ; i--) { x = x + arr[i]; arr[4 - i] = x; } arr: 12 21 27 48 50 pos: 0 1 2 3 4 x: 0 12 21 27 48 50 What are the values stored in the array when the following code finishes? int arr[5]; int x; int i; for ( i = 0 ; i < 5 ; i++) arr[i] = 3 * i; x = 0; for ( i = 0 ; i < 5 ; i++) { x = arr[i]; arr[i] = arr[4 - i]; arr[4 - i] = x; } arr: 0 3 6 9 12 pos: 0 1 2 3 4 x: 0 What is the value of z when the following code finishes? void f1 ( int a, int & b) { int temp = a; a = b; b = temp; } int main() { int x, y, z; x = 3; y = 5; f1 ( x, y); z = x + y; } x: 3 y: 3 z: 6 a: 5 b: use y instead temp: 3 What is the value of z when the following code finishes? int f1 ( int a, int & b) { int temp = a; a = b; b = temp; return a + b; } int main() { int x, y, z; x = 3; y = 5; z = f1 ( x, y); z = x + y + z; } x: 3 y: 5 3 z: 8 14 a: 5 b: use y instead temp: 3 Recursive question: int power ( int a, int b) { if ( b <= 0 ) return 1; else return a * power (a, b-1); } int main () { int z; z = power (3, 4); } power 3 0 1 power 3 1 3 power 3 2 9 power 3 3 27 power 3 4 81 main: 81 a b return z