CS 1044 Test 2 Form A Key Fall 1999 Q A Explanation 1. 1 It is a count-controlled loop because the loop is executed as many times as the input integer value. 2. 4 It is an EOF controlled loop because the length of the file is not known. 3. 3 Execution of the while loop: After Iteration 1: length=20, count=5 After Iteration 2: length=100, count=6 After Iteration 3: length=98, count=7 4. 8 This program segment basically sums up all the elements in the file. 5. 4 This program segment will add all the numbers in the file until one of the numbers is less than 0. So it adds up 4, 3, 2 and then comes out of the while loop because the next input is less than 0. 6. 3 Before the for loop the value of mystery is 4. Therefore, the loop is executed 4 times. The loop sums up 3, 2, -4, and 5. Therefore, the value of sum is 6. 7. 5 Initially the value of j is 5. It is then incremented by 3 in the loop. So the value of j will be 8, 11, 14, 17, 20, 23, 26, 29 ... since the value of j will never be 28, this loop will continue infinitely. 8. 4 The value of j is: After the first iteration: j=8 After the second iteration: j=11 After the third iteration: j=14 After the fourth iteration: j=17, therefore the fourth value printed is 17. 9. 1 A prototype is a declaration but not a definition. This is because the definition of a function contains the actual code of the function. The declaration tells the compiler that such a function actually exists. 10. 3 An '&' is put when the parameter is of type pass-by-reference (i.e. the data flow is into and out of the function). Therefore, parameter 'beta' has an '&' before it, Since 'alpha' is of type pass-by-value, there is not '&' before it. 11. 4 In the function, both the parameters are pass-by-reference. Therefore, a variable should be specified while calling it. A value cannot be passed. 12. 2 Since alpha is declared inside the function, it cannot also have a parameter with the same name. 13. 4 Since the value to be returned by the function is of type 'bool' the function will return 'false'. This is because the value passed to the function is 2.4. Therefore, The value of someFloat is 2.4 inside the function. When it is compared with 0.0 the answer is false. 14. 6 Since the variable 'Ben' is passed by reference to the function DoThis. In the function DoThis 'Alpha' is increased by 10. Therefore, the value of Ben becomes 15. 15. 2 Since the variable 'Jerry' is passed by value the changes made in the function are not reflected in the main program. Therefore, the value of 'Jerry' remains 7. 16. 5 Since Temp is a global variable and it is assigned to be 14 in the function the value printed out is 14. 17. 1 This is because the for loop is not executed because the value of limit is 8. 18. 3 The value of sum: After first iteration: 4 After second iteration: 10 After third iteration: 18 After fourth iteration: 28 19. 3 Because MaxStuff is 40 and 40+10 = 50 20. 6 The value of k: In the first iteration: 4 In the second iteration: 2 In the third iteration: 0 The main thing to remember here is that indexes start with zero. 21. 8 1. would print the index locations: 0,2, .... 4998 2. would print the index locations: 1,3, .... 4999 3. would print the index locations: 0,2, .... 4998 4. would print the index locations: 0,1, .... 2499 times 2 plus 1 5. would print the index locations: 1,3, .... 4999 22. 3 23. 5 The third option would print out "Jake" 4 times. 24. 1 The key point to remember here is that rows are first and columns are second in a two dimentional array. Also the arrays indexes start from 0. 25. 1 26. 3 aRay[2] is equal to 3. And since the size of RayStevens is 4 it's ok. 27. 2 The array elements are changed so it cannot be const int 28. 3 The indices in an array are stored from 0 to Max-1. 29. 1 List[Lo] and List[Hi] are being swapped. Therefore, List[Lo] must be stored in some temporary variable before it is overwritten by List[Hi]'s value in Line H. 30. 5 The answer is tempInt.