Deitel C++ Chapter 3

  1. What is a function?
    A set of steps that performs a task. It can be called using it's name.
  2. What is a member function?
    A function in a class that performs one of the class's tasks.
  3. Must you create an object before a function can be used?
    Yes, you must create an object of a class before a program can perform the tasks the class describes.
  4. What is a member-function call?
    A message sent to an object that tells the object to perform a task.
  5. How are attributes specified in the object's class?
    As data members.
  6. What does a class definition contain?
    • data members that define the attributes
    • data functions that define the behaviors
  7. What keyword begins a class definition?
    A class definition begins with the keyword class followed immediately by the class name.

    class theName
  8. What is the convential form used for user defined class names?
    It begins with a capital letter and each subsequent word begins with a capital letter. This is known as camel case.

  9. What is the format of the class? (does it use braces or parenthesis, a semi-colon or no)
    Every class's body is enclosed in a pair of braces and ends with a semicolon.

    class myClass
    body here
  10. Which access specifier allows member functions to be called by other functions and by member functions of other classes?
    public access specifier
  11. Access specifiers are always followed by a _____.
    colon :
  12. ________ is a special return type which indicates that a function will perform a task but will not return any data to its calling function when it completes its task.
  13. What does an empty set of parenthesis after a function name indicate?
    The function does not require additional data to perform its task.
  14. How is a function's body delimited?
    • with left and right braces
    • {
    • }
  15. Can you call a member function before you create an object of its class?
  16. Name a reason why C++ is known as an extensible language.
    Each new class you create becomes a new type in C++ that can be used to declare variables and create objects.
  17. A _____ can require one or more parameters that represent additional data to perform a task.
    member function
  18. A _____ supplies arguments for each of the function's parameters.
    function call
  19. How is a member function called?
    • following the object name with a dot (.) operator
    • the function name
    • a set of parentheses containing the function's arguments


  20. What is a string?
    • A string represents a string of characters.
    • defined in the header file <string>
    • the name string belongs to namespace std
  21. What does the function


    • reads characters from its first argument until a newline character is encountered
    • then places all the characters (minus the newline) in the string variable specified as its second argument
    • then discards the newline character
  22. How do you indicate that a function does not require any parameters?
    empty parenthesis()
  23. The number of (a) in a function call must match the number of (b) in the parameter list of the called function's header.
    • (a) arguments
    • (b) parameters
  24. Do the argument types in the function call need to be consistent with the types of the corresponding parameters in the function header?
  25. What are local variables?
    Variables declared in a function's body that can only be used from the point of their declaration in the function to the immediately following closing right brace. When a function terminates, the values of its local variables are lost.
  26. A local variable must be _____ before it can be used in a function.
  27. Can a local variable be accessed outside the function in which it is declared?
    no, only inside the function
  28. Are data members normally public or private?
  29. Are variables or functions available only to the member functions of the class in which they are declared?
    yes, only available to the class's data members and functions
  30. When a program creates an object of a class, what happens to the private data members?
    The private data members are encapsulated (hidden) in the object and are only accessible by member functions of the object's class.
  31. When does a function return a result to its calling function?
    This happens when the function specifies a return type other than void and completes its task.
  32. What is the initial value of a string?
    an empty string (does not contain any characters, or nothing appears on the screen when an empty string is typed)
  33. Do classes often provide member functions to allow clients of the class to set or get private data members?
    Yes, and the names of these member functions normally begin with set or get.
  34. What is the purpse of providing public set and get functions for private data members?
    It allows clients of a class to indirectly access the hidden data. The client knows that it is attempting to modify or obtain the object's data, but the client does not know how the object performs these operations.
  35. Since data members of a class can access the private information directy, should they use the set and get functions of the class to manipulate the private data?
    Yes. If the class's data representation is changed, member functions that access the data only via the set and get functions will not require modification - only the bodies of the set and get functions that directly manipulate the data member will need to change.
  36. Why must a public set function carefully scrutinize any attempt to modify the value of a data member?
    to ensure the new value is appropriate for that data member
  37. What is a constructor and why is it needed?
    • Each class you declare should provide a constructor to intitialize an object of the class when the object is created.
    • A constructor is a special member function that must be defined with the same name as the class, so that the compiler can distinguish it from the class's other member functions.
  38. How are constructors different from functions?
    • Constructors cannot return values
    • Constructors cannot specify a return type (not even void)
    • Constructors are normally declared public
  39. What does C++ require at the time each object is created that helps ensure the object is initialized before it is used in a program?
    a constructor call
  40. What is a default constructor?
    • A constructor that takes no arguments.
    • In any class that does not include a constructor, the compiler provides a default constructor.
    • The class programmer can also define a default constructor explicitly. If the programmer defines a constructor for a class, C++ will not create a default constructor.
  41. Can class definitions be reused by programmers worldwide?
    Yes, when packaged properly.
  42. Where is a class normally defined?
    It is customary to define a class in a header file that has a .h filename extension.
  43. Should the class's clients be required to change if the implementation changes?
  44. What are interfaces?
    Interfaces define and standardize the ways in which things such as people and systems interact.
  45. What does the interface of a class do?
    • It describes the public member functions (also known as public services) that are made available to the class's clients.
    • The interface describes:
    • what services clients can use
    • how to request those services
    • does not specify how the class carries out the services
  46. Why is it considered a fundamental principle of good programming to separate interface from implementation?
    • It makes the programs easier to modify.
    • Changes in the class's implementation do not affect the client as long as the class's interface originally provided to the client remains unchanged.
  47. What does a function prototype contain?
    • a function's name
    • it's return type and the number
    • types and order of the parameters the function expects to receive
  48. When should the member functions be defined in a separate source-code file?
    once a class is defined and its member functions are declared (via function prototypes)
  49. What must precede the function name for each member function defined outside of its corresponding class definition?
    • the class name
    • the binary scope operator ::
  50. What does class string's length member function return?
    the number of characters in a string object
  51. What does class string's member function substr (short for substring) return?
    • a new string object created by copying part of an existing string object
    • The function's first argument specifies the starting position in the original string from which characters are copied.
    • Its second argument specifies the number of characters to copy.
  52. In the UML, each class is modeled in a class diagram as a rectangle with three compartments. What are in these compartments?
    • top: class name, centered horizontally in boldface
    • middle: the class's attributes (data members in C++)
    • bottom: the class's operations (member functions and constructors in C++)
  53. The UML models operations by _____.
    • listing the operation name followed by a set of parenthesis()
    • a + sign = public
  54. The UML models a parameter of an operation by _____.
    listing the parameter name, followed by a colon and the parameter type in parenthesis
  55. Do all the UML data types have the same names as the corresponding C++ types?
    no, UML has its own data types
  56. The UML represents data members as attributes by _____.
    • listing the attribute name, followed by a colon and the attribute type
    • a - sign = private
  57. How does the UML indicate the return type of an operation?
    by placing a colon and the return type after the parenthesis following the operation name
  58. Do UML class diagrams specify return types for operations that do not return a value?
  59. How does the UML model constructors?
    • as operations in a class diagram's third compartment
    • to distinguish a constructor from the operations, the UML places the word "constructor" between guillemets (<< and >>) before the constructor's name
Card Set
Deitel C++ Chapter 3
Classes and Objects