Test II, CSCI 230, Fall 2009
- The weight for each question is given with the question.
- Use as much paper as you wish, but make your answers are legible.
- Please answer each question thoughtfully and carefully.
- ADT
- [2 points] Define Abstract Data Type (ADT)
- [3 points] Give an example of an abstract data type. Explain how
this example is an ADT.
- Array Definition
- [2 points] What is an array?
- [3 points] What is the difference between an array and a class?
- [3 points] Give the syntax for declaring an array.
- [2 points] Show how to declare an array of integers.
- Array index out of bounds error
- [2 points] What is an array index out of bounds error?
- [2 point] What are the possible results of an array index out
of bounds error.
- [2 points] How can an array index out of bounds error be avoided.
- Arrays as parameters
- [2 points] How are arrays passed as parameters?
- [2 points] Why are arrays passes in this manner?
- [2 points] How can a procedure implementer guarantee that an
array is not changed in a function? Give the syntax
to accomplish this.
- [10 points] A file contains up to 50 integers. Write a routine which will open the file, read the integers into an array (passed by the user) and return the size of the array. Show all code needed for this routine (the routine, an example call, any pre defined constants, ...)
- [10 points] Write a routine which takes an array of characters, and the integer size of that array and returns true if the array is a palindrome. A palindrome is a string that reads the same forward and backward. racecar is an example of a palindrome. The string will only contain lower case letters.
- Recursion
- [2 points] Define recursion.
- [6 points] What is required for a recursive algorithm?
- [5 points] Give the algorithm for binary search.
- [5 points] Write a recursive routine to calculate xn, where
x is a double and n is a non-negative integer.
- [5 points] Give an algorithm which will sort an array of n doubles. If your algorithm requires any auxiliary routines, give these as well.