CS 509, Advanced Programming II

Fall 2002 - Test 5


  1. A colleague of yours added some debugging print statements to a program that was crashing, but is now complaining that the program runs far slower than it did before the print statements were added. To which output stream is your colleague's program writing its debugging output? Explain.

  2. Suppose the following class

    struct C {
      f() const { 
        ?()
        }
    
      g() Xg {
        h()
        }
    
      h() Xh {
        }
      };
    

    compiles without errors when ? is g but has compile-time errors when ? is h. What are Xg and Xh? Explain.

  3. Here are two functions that delete a value from a vector:

    void delete_value_1(vector & ivec, int v) {
      const vector::iterator e = ivec.end();
      vector::iterator s = ivec.begin();
      while ((s = find(s, e, v)) != e)
        ivec.erase(s);
      }
    
    void delete_value_2(vector & ivec, int v) {
      const vector::iterator e = ivec.end();
      vector::iterator s = remove(ivec.begin(), e, v);
      ivec.erase(s, e);
      }
    

    Do an analysis that determines which of the versions, if any, is asymptotically better than the other.

  4. Write a test case to determine of an array-sequence implementation handles invalid index ranges correctly. Your test case should be a brief - no more than 5 line - code fragment; be sure to explain what the expected results are.


This page last modified on 16 November 2002.