Chapter 3 Functions 1. The best way to develop and maintain a large program is to divide it into several smaller program modules each of which is more manageable than the original program. Modules are written in C++ as classes and functions. This is called the divide and conquer method. 2. A function is invoked by a function call. The function call mentions the function by name and provides informatuion (as arguments) that the called function needs to perform its task. 3. The purpose of information hiding is for functions to have access only to the information they need to complete their tasks. This is a means of implementing the principle of least privilege, one of the most important principles of good software engineering. 4. Each argument of a function maybe a constant, a variable, or an expression. 5. A local variable is known only in a function definition. Functions are not allowed to know the implementation details of any other functions. 6. The general format of a function definition is return-value-type function-name ( parameter lists ) { declaration statements executable statements } 7. The arguments passed to a function must match in number, data type, and order with the parameters in the function definition and function prototype. 8. A function prototype declares the return-type of the function and declares the number, the type, and order of the parameters the function expects to receive. 9. Function prototype enable the compiler to verify that functions are called correctly. 10. Each standard library has a corresponding header file containing the function prototypes for all the functions in that library, as well as definitions of various symbolic constants needed by those functions. 11. Programmers can and should create and include their own header files. 12. When an argument is passed call-by-value, a local copy of the variable's value is made and the copy is passed to the called function. Changes to the copy in the called function do not affect the original variable's value. 13. To randomize a program, use the standard library function srand. 14. We can use srand (time(0)) to randomize without the need for entering a seed. The time function prototype is located in Time.h. 15. The general equation for scaling and shifting a random number is new_random_number = start_number + rand() % range; 16. The values of enumerate in enum start at 0. 17. C++ provides 4 storage class specifier: auto, register, extern, and static. 18. An identifier's storage class determines when that identifier exists in memory. 19. An identifier's scope is where the identifier can be referenced in a program. 20. An identifier's linkage determines for a multiple source file program if an identifier is known only in the current source file or in any source file with proper declarations. 21. Variables of automatics storage class are created when the block in which they are declared is entered, exist while the block is active, and are destroyed when the block is exited. A function local variables are normally of automatic storage class. 22. The keywords extern and static sare used to declare identifiers for variables and functions of static storage class. 23. Local variables declared static retain their value when the function in which they are declared is exited. 24. The four scopes for an identifier are: function scope, file scope, block scope, and function-prototype scope. 25. A recursive function is a function that calls itself either directly or indirectly. 26. If a recursive function is called with a base case, the function simply returns a result. If the function is called with a more complex problem, the function divides the problem into two conceptual pieces: a piece that the function konws how to do and a slightly smaller version of the original problem. Because the new problem looks like the original problem, the function launches a recursive call to work on the smaller problem. 27. Iteration uses a repetition structure while recursion use a selection structure. 28. Recursion repeatedly invokes the mechanism, and consequently the overhead, of function calls. The can be expensive in both processor time and memory space. 29. An empty parameter list is specified with empty parentheses or void in parentheses. The parentheses are required syntax. 30, It is possible to define several functions with the same name but with different parameter types. This is called function overloading. When an overloaded function is called, the compiler selects the proper function by examining the number and types of arguments in the call. Overloaded functions can have different return values, and MUST have different parameter lists.