CSCI 240 - Possible Questions for Quiz 7

  1. (2 points) Declare an array named AR to hold 4 integers and fill it with the numbers 2, 4, 6, and 8.

  2. (2 points) Assume an array called AR contains 4 integers. Write a loop to print out the values of the 4 integers.

  3. (2 points) Assume an array called AR contains 4 integers. Write code to exchange the very first and the very last values in the array.

  4. (2 points) Declare an array named AR to hold 1000 integers. In the declaration statement, initialize the array so the very first value is 10, the second is 20, and all the rest are 0.

  5. (2 points) Complete the following sentence: If you declare an array to hold N values, legal subscripts run from _____ to ______.

  6. (2 points) Complete the following sentence: the unsubscripted name of an array is _______________________________.

  7. (2 points) Write code to swap element [2] and element [4] in an array of floats called AR. Declare a simple variable called temp for this question, and assume the array is correctly declared and initialized.

  8. (2 points) Write code to copy the 0th element of an array called AR into all the other elements of the array. Assume there are 10 elements in the array.

  9. (2 points) Complete the following sentence: all the elements of an array must be the same ____________.

  10. (2 points) (True/False) ALL of the declared elements in an array MUST be initialized and used.

  11. (2 points) Write a function called squareAr that squares the first N elements in an array of doubles. The function takes two arguments: an array of doubles and an integer that represents the number of values to be squared (N). The function returns nothing.

  12. (2 points) Write a function called calcAvg that calculates and returns the average of the first N elements in an array of doubles. The function takes two arguments: an array of doubles and an integer that represents the number of values to be use in the calculation (N). The function returns a double: the calculated average. The function can assume N >= 0.