Computer Science 112a Object Oriented Programming and Data Structures Fall 1997 Second written exam Ileana Streinu Name: 112a-ax account: The exam is open book: you may consult your notes, books, even computer programs that you have written before. All the work should be yours. Show all your work: you may get partial credit. Add extra sheets if necessary. 1. (10 points) Given the following C++ struct definition: struct sometype{ int data; sometype* somelink; sometype* otherlink; char code; } and the typedef: typedef sometype* someptr; Define an array A1 whose elements are of type sometype, and an array A2 whose elements are of type someptr, both of 10 entries. Write a C++ expression to access the otherlink field of the 7th entry in array A1, and an expression to access the data field in the struct pointed to by the 5th element in array A2. 2. (30 points) Given the following structure definition: struct node{ int data; node * left; node * right; }; the typedef: typedef node* nodePtr; and the following definitions of variables: node n1, *n2, n3[5]; nodePtr n4, *n5, n6[5]; Which of the following are valid C++ expressions? (2 points each correct answer) a. n1->data b. n1.data c. n2.left d. n2 -> left e. n4.left f. data -> left g. n3[2].right h. n3[2] -> right i. n3[2].right -> data j. n6[2].right -> data k. n6[4]->right.data l. n6[4]->right->data m. n5.data n. n5 -> data o. *n5 -> data 3. (10 points) What is the following recursive function computing? You can answer with a mathematical formula or explain in English (in no more than two lines) what is doing. int funct(int n) { if (n == 0) return(0); else return ( n + funct(n-1)); } Now trace the stack behavior for the following function call: funct(3) 4. (10 points) You are given the following arrays and the for loop: int table1[MAX]; int* table2[MAX]; int i; for (i = 0; i