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 2007
Midterm Makeup – Take Home Examination
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. Write all the code for a class that implements the std::istream
interface and supplies a member function that supports pushing
back any number of characters previously retrieved from the
stream. All other functions behave as in the istream class itself.
Embed this class in a CSE687 namespace. Please explore
overriding the std::streambuf class to accomplish this.
4. Draw a UML class diagram that represents your design for Project
#4. Discuss how the Dependency Inversion Principle could apply to
this design. The question does not ask if you did, but rather, how
could you apply DIP for this design.
5. 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.
6. 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));
pf3

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!

Midterm Makeup – Take Home Examination

  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. Write all the code for a class that implements the std::istream interface and supplies a member function that supports pushing back any number of characters previously retrieved from the stream. All other functions behave as in the istream class itself. Embed this class in a CSE687 namespace. Please explore overriding the std::streambuf class to accomplish this.
  4. Draw a UML class diagram that represents your design for Project #4. Discuss how the Dependency Inversion Principle could apply to this design. The question does not ask if you did, but rather, how could you apply DIP for this design.
  5. 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.
  6. 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));
  1. Please describe how the Interface Segregation Principle applies to your Project #2.
  2. Please provide the definition of a template-based function that accepts an object of the template type and, if that type is an STL container, returns the type of the container’s elements. You need only ensure that your code is correct for two of the STL containers, but it must accept any of the STL containers. You may assume that users of your function will supply some STL container type as the template parameter.
  3. Given the declarations: template class B { … private: const T t; } class C : public B<std::string> { … private: const int len; } write a constructor for B that takes a T argument. Write a constructor for C that sets len to the length of its base’s string argument. Do you need to modify the contents of B in any way to do that? You may assume that the only data members are the ones shown.
  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. Given the partial class declaration: class D : public B { private: int x; public: D(const D &d); // some more public stuff here }; Show how to correctly define a copy constructor and assignment operator for class D.
  6. How would a class prevent clients from copying or assigning objects of the class.
  7. 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.