Docsity

CSE687 Object Oriented Design Midterm Makeup Exam Questions - Prof. James Fawcett, Exams of Engineering

Toggle sidebar
bg1
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.
pf2

Partial preview of the text

Download CSE687 Object Oriented Design Midterm Makeup Exam Questions - Prof. James Fawcett and more Exams Engineering in PDF only on Docsity!

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.

CSE687 Object Oriented Design Spring 2003

  1. Given the class declarations: class B { public: virtual 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 *dptr = new D(d1); dptr -> mf(3);
  2. Suppose Tr is not the same type as Targ. Can you find a logical error in the following declaration of a global function f? Tr& f(Targ);
  3. How would you create a class that can not create any objects? Why would you want to do that?
  4. Show how to declare, define, and invoke a template-based function that finds the largest element of an array of some type. Are there any types for which you would expect compilation of this function to fail? Please explain.
  5. Support or refute the claim that C-Language modules support software reuse. In what ways do C++ classes improve on this support?
  6. What is an Object?
  7. Given the declaration: void X::mf(Y &y); How would you change the declaration to declare that the operation of this function will not change the state of the object invoking it? What can you do with the re-declared function that you could not do in its original form?
  8. Support or refute the claim that it is safer to return a reference to an object than a pointer to the object.
  9. How is a C-Language module similar to a C++ class? How is it different?
  10. State precisely all the conditions under which a class will support the creation of arrays of objects.