
CSE687 Object Oriented Design Spring 2003
Midterm Makeup
Provide solutions to every problem on the exam you completed this semester. You
have seen my solutions, and may use them as a guide, but I am expecting you to
restate the solutions or provide new solutions using your own words and ideas.
When you have completed those first 11 questions, provide original answers to the
following 20 questions:
1. Show how to declare, define, and invoke a template-based function that finds the
average of the elements of an array of some type (average is the sum of the
elements divided by the number of elements). Are there any types for which you
would expect compilation of this function to fail? Please explain.
2. Show how to create a list of strings using the list declared in the STL. Define
three literal strings and write code to put them in the list.
3. Write code for a function accepting an array by reference. Throw an exception in
the function if the array is larger than some specific size, say MAX.
4. What is meant by the term abstraction? How does the C++ language support
abstraction?
5. What is a pure virtual function? When would you declare one?
6. Given the class declarations:
class B { public: void mf(int n); protected: int state; };
class D : public B { public: void mf(int n); };
What happens when the statements below are executed?
D d1;
D da[3] = { d1, d1, d1 };
da[0].mf(3);
7. What is the difference between a class and an object?
8. Why is it important not to return by value an object from a function when the
object did not exist before the function invocation?
9. What is meant by the terms binary operator model?
10. Define a constructor for a class representing character strings which takes an
array of characters as one of two arguments. The array elements should be used
to initialize the string’s characters.