1
h12
CS32 S18
Name:
(as it would appear on official course roster)
Umail address: @umail.ucsb.edu
Optional: name you wish to be called
if different from name above.
Optional: name of "homework buddy"
(leaving this blank signifies "I worked alone"

h12: Dynamic Classes

ready? assigned due points
true Tue 05/08 08:00AM Tue 05/15 12:30PM

You may collaborate on this homework with AT MOST one person, an optional "homework buddy".

MAY ONLY BE TURNED IN IN THE LECTURE LISTED ABOVE AS THE DUE DATE,
OR IF APPLICABLE, SUBMITTED ON GRADESCOPE. There is NO MAKEUP for missed assignments;
in place of that, we drop the four lowest scores (if you have zeros, those are the four lowest scores).


Reading: Dynamic Classes, PS 11.4, DS 4.4

  1. (10 pts) Fill in the information in the header. The following are required to get the 10 "participation" points.
    • Filling in your name and umail address.

    Also: For paper submission PLEASE submit on ONE SHEET OF PAPER, double-sided if at all possible. If you must submit on two printed sheets write name on BOTH sheets and no staples, paperclips, or folded corners.

  2. Some classes have private data members with pointers to values allocated on the heap. Your textbook calls the heap the "freestore", and it calls these values on the heap "dynamic variables". When you have a class with dynamic variables, i.e. when you have attributes that are pointers to things on the heap, you likely need to think about the "big-three", i.e. three special kinds of things that you need to implement in your class. What are the names of this so-called 'big three?' You may list them in any order:

    • (2 pts)
       
    • (2 pts)
       
    • (2 pts)
       
  3. (6 pts) What is the purpose of a destructor?
     

  4. (4 pts) Write the function prototype for the destructor for a class with the name Foobar.
     

  5. (4 pts) Write the function prototype for a copy constructor for a class with the name Foobar.
     

  6. (10 pts) The parameter to the copy constructor is a const reference. Sometimes you use a const reference instead of pass-by-value for reasons of efficiency, but in the case of a copy constructor, there is an even more fundamental reason why pass-by-value CANNOT be used. Why is that?
     
  7. (4 pts) Write the function prototype for an overloaded assignment operator for the class Foobar.
     

  8. (6 pts) Why does C++ provide users with both a delete operator and delete [ ] operator?