Chapter 10

 < Day Day Up > 



Chapter 9

  1. Describe in your own words the definition of a function.

    A function is a logical, named grouping of related code statements designed to perform a specific processing activity.

  2. List and describe the three characteristics of a good function.

    Maximally cohesive (singular purpose), well-named, and minimally coupled.

  3. What is the difference between a function's interface and its implementation? What constitutes a function's interface? What constitutes a function's implementation? Why is it important or desirable to separate a function's interface from its implementation?

    The function interface consists of the function name, its parameter list (number and type of parameters), and return type. The function implementation consists of the required code to implement the interface. Function users should care only about the function interface. It's important to separate the interface from the implementation because the interface can be distributed in a header file and the implementation can be distributed as a library module, keeping the source code secrets safe from tampering.

  4. What is the purpose of the #ifndef, #define, & #endif preprocessor directives as they apply to header files?

    To prevent multiple header file inclusions. Header files must often be #include(d) in multiple source files. The use of #ifndef, #define, #endif directives allows the header file to be used in multiple source files but limits the actual importing of the contents to one time.

  5. List at least three benefits to giving functions good names.

    To aid code readability and to make it easy for users to understand the purpose of your function.

  6. In what two ways can arguments be passed to functions? What is the difference between the two ways? What advantages or disadvantages are associated with each way?

    Arguments can be passed to functions by value or by reference. When passed by value, a copy of the object is made and passed to the function. For large object, pass by value may be an intensive operation. When passed by reference, a pointer (or reference) to the object is passed and the object is manipulated via the pointer. (pointer or reference)

  7. What is the difference between an automatic local variable and a static local variable?

    An automatic local variable will be created and initialized each time the function is called, whereas the static local variable will be created once and preserved across function calls.

  8. hat is meant by the phrase, "Maximize Cohesion - Minimize Coupling"?

    Maximize Cohesion - A function's purpose should be singular. (A function call should result in no surprises)

    Minimize Coupling - A function should use local variables and avoid the use of global variables.

  9. Describe how functions can be overloaded.

    By changing the number and type of parameters. (changing the function signature)

  10. Given the following function pointers describe what type of function each can point to:

    (void)(*fun_ptr)(); (float)(*fun_ptr)(int, char*, float); (char*)(*fun_ptr)(float, float); 

    Pointer to function that returns void and takes no arguments.

    Pointer to function that returns float and takes three arguments (int, char*, and float).

    Pointer to function that returns char* and takes two floats as arguments.



 < Day Day Up > 



C++ for Artists. The Art, Philosophy, and Science of Object-Oriented Programming
C++ For Artists: The Art, Philosophy, And Science Of Object-Oriented Programming
ISBN: 1932504028
EAN: 2147483647
Year: 2003
Pages: 340
Authors: Rick Miller

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net