Docsity

CSE687 Object Oriented Design Mid-Term Makeup Exercise Solutions - Prof. James Fawcett, Exams of Engineering

Toggle sidebar
bg1
CSE687 Object Oriented DesignMidTerm Makeup Spring 2009
Midterm Makeup – Take Home Examination
To complete this makeup successfully you need to provide a Word
document that contains two sets of things:
First, go over each of the questions on your examination and describe,
in that document, what, if anything was wrong with your answer. If
you received less than a score of 1 for a question, you should assume
there is something wrong. This is intended to have you do a critical
examination of each of your answers. You may refer to my solutions if
you wish, but will get no credit for repeating any part of those answers.
The second thing you need to do is to answer, as completely as you
can, all ten questions below. For questions like the first, after you
finish implementing the code, please copy the source code into your
word document.
I cannot accept your makeups after Monday, May 5, 2008. Please slide
the document under my door if I am not in my office.
1. Implement a function that accepts an STL container and displays
string representations of the first N elements on the first line, the
elements from N+1 to 2N on the second line, and so on. Please
format your output so each element is written into a fixed size field.
Your function should compute the field size, allowing for spaces
between fields, so that N fields fill, without wrapping, a single line.
Your function must be able to accept more than one type of
container, say either a list or a vector, but you are required to show
only that it is correct for a vector. Under what circumstances will
your implementation fail to compile?
2. What are the main design strategies used in Object Oriented
Design?
3. Please provide the definition of a function that accepts an array of
pointers to functions with the signature int func(X &x), invokes each
of the functions, and returns the sum of the computed values.
4. If you design a class derived from an abstract base class how do
you insure that clients can construct objects of your class?
5. How would a class prevent clients from copying or assigning objects
of the class.
pf2

Partial preview of the text

Download CSE687 Object Oriented Design Mid-Term Makeup Exercise Solutions - Prof. James Fawcett and more Exams Engineering in PDF only on Docsity!

CSE687 Object Oriented DesignMidTerm Makeup Spring 2009

Midterm Makeup – Take Home Examination

To complete this makeup successfully you need to provide a Word document that contains two sets of things: First, go over each of the questions on your examination and describe, in that document, what, if anything was wrong with your answer. If you received less than a score of 1 for a question, you should assume there is something wrong. This is intended to have you do a critical examination of each of your answers. You may refer to my solutions if you wish, but will get no credit for repeating any part of those answers. The second thing you need to do is to answer, as completely as you can, all ten questions below. For questions like the first, after you finish implementing the code, please copy the source code into your word document. I cannot accept your makeups after Monday, May 5, 2008. Please slide the document under my door if I am not in my office.

  1. Implement a function that accepts an STL container and displays string representations of the first N elements on the first line, the elements from N+1 to 2N on the second line, and so on. Please format your output so each element is written into a fixed size field. Your function should compute the field size, allowing for spaces between fields, so that N fields fill, without wrapping, a single line. Your function must be able to accept more than one type of container, say either a list or a vector, but you are required to show only that it is correct for a vector. Under what circumstances will your implementation fail to compile?
  2. What are the main design strategies used in Object Oriented Design?
  3. Please provide the definition of a function that accepts an array of pointers to functions with the signature int func(X &x), invokes each of the functions, and returns the sum of the computed values.
  4. If you design a class derived from an abstract base class how do you insure that clients can construct objects of your class?
  5. How would a class prevent clients from copying or assigning objects of the class.

CSE687 Object Oriented DesignMidTerm Makeup Spring 2009

  1. Given the code fragments below, where the ellipsis (…) represents code that has not been disclosed to you: class X { … }; class Y { public: explicit Y(const X& x); … }; what can you say about the compilation and execution of each of the following statements? Describe each of the operations that occur as this code executes. Y func(Y y) { … } X x; Y y = func(Y(x));
  2. Suppose that objects of a class are required to correctly carry out copy and assignment operations. Support or refute the claim that the class must implement a copy constructor and assignment operator.
  3. What is object oriented design?
  4. What is the purpose of an abstract base class?
  5. 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?