Final exam for CIS 67, Spring 97 Name: _______________________ Answer questions 1 - 7 for array scores and happy declared as: int scores[10], happy[20]; 1. Show the values of the first and last elements of array scores and happy after the loop below executes. for (int i = 0, i < 10; i++) { scores[i] = i * i; happy[i + 10] = scores[i]; } scores[0] is _____ scores[9] is ____ happy[0] is _____ happy[19] is ____ 2. Assume the elements of array scores contain increasing multiples of 10, starting with 10 in scores[0], 20 in scores[1], and so on. What is displayed by the following code fragment: index = -1; mystery = 50; for (int i = 0; i < 10; i++) if (scores[i] == mystery) index = i; cout << index << endl; 3. What is displayed if the second line is replaced by mystery = 55; 4. What is displayed if the condition is changed to: (scores[i] >= mystery) and the second line is unchanged? 5. How many comparisons would be performed in a selection sort of array scores as described in question 2? Selection sort: comparisons ____________ 6. You have a function named switch_array with the following description and prototype: // Exchanges the values stored in its 2 array arguments. void switch_array (int a_1[], int a_2[]); What additional argument(s) does function switch_array need to do its job correctly? 7. Given the above prototype for switch_array, write a function call that passes arrays scores and happy as actual arguments to function switch_array. Answer questions 8 - 11 assuming the declarations below. struct person { string name; int dependents; int age; }; person me, you; 8. Write a statement that increases the dependents field of me by 1. 9.(True/False) The statement you = me; copies all data in variable me to you. (True/False) The condition (you == me) is true if corresponding fields of variables me and you contain the same data. 10. Write a function called is_older that returns true if the person represented by its first argument (struct type person) is older than the person represented by its second argument (same type). 11. Write a loop that changes the data in the name field of me to all uppercase letters. 12. Now assume that person is a class with the same data members as struct person. Complete the public part of the class definition below. Assume the function increment_age always adds 1 to age and increase_dependents adds to dependents an amount which is passed as an argument. Function make_name_uppercase converts the name field to all uppercase characters. public: ____________ // constructor ______ increment_age ____________ ______ increase_dependents ___________ ______ make_name_uppercase ___________ ______ read_person ____________ ______ write_person ____________ // accessor functions: _______ _____________ _______ _____________ _______ _____________ For questions 13 to 15, assume that function main has the declarations: person me, you; int babies; 13. Write a statement for function main that increases the dependents field of you by the value of babies. 14. Write a statement for function main that changes the name field of me to all uppercase characters. 15. Write a function called is_older that returns true if the person represented by its first argument (class type person) is older than the person represented by its second argument (same type). Assume is_older is not a member function of class person. 16. Declare a struct type group_s with an array field persons that can store up to 100 objects of type person. The struct type group_s should also have an integer field that represents the actual size of the array (the number of person objects currently stored). 17. Assume function main declares a variable my_class of type group_s. Write statements to increment by 1 the age field of every person in my_class whose name field has the same value as your_name (a string variable). 18. Program: Write member functions person, increment_age, increase_dependents, and get_name for class person.