1 |
h15 |
CS32 S20 |
Name: | ||||
---|---|---|---|---|
(as it would appear on official course roster) | ||||
Umail address: | @umail.ucsb.edu | section 3pm, 4pm, 5pm, 6pm |
||
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 05/19 09:30AM | Tue 05/26 11:59PM |
You may collaborate on this homework with AT MOST one person, an optional "homework buddy".
MAY ONLY BE TURNED IN ON GRADESCOPE BEFORE THE DUE DATE,
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
- (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.
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.
- Filling in your name and umail address.
- 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)
- (2 pts)
- (6 pts) What is the purpose of a destructor?
- (4 pts) Write the function prototype for the destructor for a class with the name
Foobar
. - (4 pts) Write the function prototype for a copy constructor for a class with the name
Foobar
. - (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?
- (4 pts) Write the function prototype for an overloaded assignment operator for the class
Foobar
. - (6 pts) Why does C++ provide users with both a delete operator and delete [ ] operator?