1
h15
CS32 F19
Name:
(as it would appear on official course roster)
Umail address: @umail.ucsb.edu section
9am, 10am, 11am, 12pm
Optional: name you wish to be called
if different from name above.
Optional: name of "homework buddy"
(leaving this blank signifies "I worked alone"

h15: Dynamic Classes Review

ready? assigned due points
true Tue 11/19 02:00PM Tue 12/03 02:00PM

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 lowest scores (if you have zeros, those are the lowest scores.)


Reading: Dynamic Classes Review, 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.

    You will find that most of these questions have been discussed in class in some way already. Use this homework as an opportunity to solidify your understanding of these important concepts.

  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?