Chapter-13 Review Questions and Exercises

Short answers

1. What is the difference between a class and an instance of the class?

2. What is the difference between the following Person structure and Person class?

    struct Person {
        string name;
        int age;
    };
    
    class Person {
        string name;
        int age;
    };

3. What is the default access specification of class members?

4. Look at the following function header for a member function.

   void Circle::getRadius()

      A. What is the name of the function?
      B. What class is the function a member of?

5. A contractor uses a blueprint to build a set of identical houses.
   Are classes analogous to the blueprint or the houses?

6. What is a mutator function? What is an accessor function?

7. Is it a good idea to make member variables private? Why or why not?

8. Can you think of a good reason to avoid writing statements in a class member
   function that use cout or cin ?

9. Under what circumstances should a member function be private?

10. What is a constructor? What is a destructor?

11. What is a default constructor?
    Is it possible to have more than one default constructor?

12. Is it possible to have more than one constructor?
    Is it possible to have more than one destructor?

13. If a class object is dynamically allocated in memory,
    does its constructor execute? If so, when?

14. When defining an array of class objects, how do you pass arguments to the
    constructor for each object in the array?

15. What are a class's responsibilities?

16. How do you identify the classes in a problem domain description?


Fill-in-the-Blank

17. The two common programming methods in practice today are _________ and _________.

18. _________ programming is centered around functions or procedures.

19. _________ programming is centered around objects.

20. _________ is an object's ability to contain and manipulate its own data.

21. In C++ the _________ is the construct primarily used to create objects.

22. A class is very similar to a _________.

23. A(n) _________ is a key word inside a class declaration that establishes a
    member's accessibility.

24. The default access specification of class members is _________.

25. The default access specification of a struct in C++ is _________.

26. Defining a class object is often called the _________ of a class.

27. Members of a class object may be accessed through a pointer to the object
    by using the _________ operator.

28. If you were writing the declaration of a class named Coin, what would you
    name the file it was stored in? _________

29. If you were writing the external definitions of the Coin class's member
    functions, you would save them in a file named _________.

30. When a member function's body is written inside a class declaration, the
    function is _________.

31. A(n) _________ is automatically called when an object is created.

32. A(n) _________ is a member function with the same name as the class.

33. _________ are useful for performing initialization or setup routines in a
    class object.

34. Constructors cannot have _________.

35. A(n) _________ constructor is one that requires no arguments.

36. A(n) _________ is a member function that is automatically called when an
    object is destroyed.

37. A destructor has the same name as the class, but is preceded by
    what character. ______

38. Like constructors, destructors cannot have a(n) _________ type.

40. A class may have more than one constructor, as long as each has a different _________.

41. A class may only have one default _________ and one _________.

42. A(n) _________ may be used to pass arguments to the constructors of
    elements in an object array.