Sams Teach Yourself C++ in 21 Days

(singke) #1
Answers 829

D


Day 6


Quiz ................................................................................................................


  1. The dot operator is the period (.). It is used to access the members of a class or
    structure.

  2. Definitions of variables set aside memory. Declarations of classes don’t set aside
    memory.

  3. 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.

  4. Public data members can be accessed by clients of the class. Private data members
    can be accessed only by member functions of the class.

  5. 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.

  6. Although member data can be public, it is good programming practice to make it
    private and to provide public accessor functions to the data.

  7. Yes. Each object of a class has its own data members.

  8. Declarations end with a semicolon after the closing brace; function definitions
    do not.

  9. The header for a Catfunction,Meow(), that takes no parameters and returns void
    looks like this:
    void Cat::Meow()

  10. The constructor is called to initialize a class. This special function has the same
    name as the class.


Exercises ........................................................................................................


  1. The following is one possible solution:
    class Employee
    {
    int Age;
    int YearsOfService;
    int Salary;
    };

  2. 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

Free download pdf