Answers 829
D
Day 6
Quiz ................................................................................................................
- The dot operator is the period (.). It is used to access the members of a class or
structure. - Definitions of variables set aside memory. Declarations of classes don’t set aside
memory. - The declaration of a class is its interface; it tells clients of the class how to interact
with the class. The implementation of the class is the set of member functions—
usually in a related CPP file. - Public data members can be accessed by clients of the class. Private data members
can be accessed only by member functions of the class. - Yes, member functions can be private. Although not shown in this chapter, a mem-
ber function can be private. Only other member functions of the class will be able
to use the private function. - Although member data can be public, it is good programming practice to make it
private and to provide public accessor functions to the data. - Yes. Each object of a class has its own data members.
- Declarations end with a semicolon after the closing brace; function definitions
do not. - The header for a Catfunction,Meow(), that takes no parameters and returns void
looks like this:
void Cat::Meow() - The constructor is called to initialize a class. This special function has the same
name as the class.
Exercises ........................................................................................................
- The following is one possible solution:
class Employee
{
int Age;
int YearsOfService;
int Salary;
}; - The following is one possible answer. Notice that the Get...accessor methods
were also made constant because they won’t change anything in the class.
32 0672327112_app_d.qxd 11/19/04 12:30 PM Page 829