CSCI 230, Fall 2006,

Final Exam.


  1. [5 points] What is dynamic data and how is it different from static data?
  2. [5 points] What is a memory leak? How can memory leaks be avoided.
  3. [10 points] What does the following code segment do? (Describe what happens at each line, refer to the line numbers in your discussion).
    1. int * a;
    2. int b;
    3. a = & b;
    4. *a = 7;
    5. cout << *a << endl;
  4. [5 points] Give code that prompts the user for an array size, and then allocates an array of integers that size.
  5. [10 points] Write a routine that takes an array, the size of the array, and replaces it with a new array ten elements larger. All data in the original array should be copied to the new array.
  6. [5 points] What is a deep copy, what is a shallow copy? Where does this issue become a problem?
  7. [5 points] Create an example where a deep copy is required. Give code segments and data structure declarations.
  8. [5 points] Describe the linked list data structure. Draw a picture and label the elements.
    struct nodeT {
        int data;
        nodeT * next;
    }
         
  9. [5 points] Write a routine that takes a pointer to a valid list of nodeT (as defined above), and prints the list.
  10. [5 points] Write a routine that takes a pointer to a valid list of nodeT (as defined above), and an element, and adds the element to the list in the first position.
  11. [10 points] Write a routine that takes a pointer to a valid list of nodeT (as defined above), and deletes every other element, starting with the first element in the list.
  12. [30 points] Create list based string class. This class should store the string in a linked list of characters. You should provide a class specification and implementation. You should support the following operations
    1. creation of an empty string.
    2. add a character at the end of a string
    3. a copy operator.
    4. string output
    5. string comparison.
    6. A class destructor.