1
h02
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"

h02: Object Oriented Design

ready? assigned due points
true Thu 09/26 02:00PM Tue 10/08 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: Object Oriented Design, PS 10.2

  1. According to Savitch in PS, the scope resolution operator :: and the dot operator . have a similar purpose, but there is a major difference between them.
    1. (5 pts) What do they have in common?
    2. (5 pts) What is the difference between them?
  2. In a class for an object representing a UCSB student:
    1. (5 pts) Would setPerm be an accessor or a mutator function? Circle one: accessor mutator
    2. (5 pts) Would getName be an accessor or a mutator function? Circle one: accessor mutator
  3. (5 pts) What does the term encapsulation refer to?
  4.  
  5. (5 pts) According to Savitch in PS, it is normal practice to make member functions private in what circumstance?
  1. On p. 579 and then again on p. 586 Savitch drives home a point about the syntax of invoking a constructor—what you SHOULD do when invoking a no-arg constructor, and what you should NOT do. Though he doesn't mention it, this is a "trap" that many C++ learners fall into if they learned Java first, because this is a place where C++ and Java syntax differ significantly.

    Suppose you have a no-arg constructor for a class Student.
    1. (5 pts) What is the correct syntax to declare a local variable inside a function or method called s that is of type Student, and is created with the no-arg constructor?
    2. (5 pts) What is the "wrong" syntax for doing that same thing that Savitch specifically warns against doing?
    3. (5 pts) In one of the passages where this is explained, Savitch indicates WHY this other syntax is wrong if your intention is to make s an instance of class Student. This syntax actually has a completely different meaning in C++. What does this alternate syntax mean—that is, what would s be declared to be under this alternate syntax?}
  2. (5 pts) Suppose you have a class Student with private data members as shown below. You could write a constructor like this:
    private:
       int perm;
       std::string name;
    
    Student::Student(int thePerm, std::string theName) {
       perm = thePerm;
       name = theName;
    }
    
    However, there is an alternate way to initialize data members in the so called "constructor initialization section" described in Section 10.2 of PS. Rewrite this constructor so that the body is an empty set of braces, and the code is moved to the so-called "constructor initialization section". (Note that I am not referring to the C++11 "constructor delegation" described on p. 587-588; this is a feature that has been in C++ for many years and is described somewhere before p. 581 - 584).