C++ Chapter 4: Procedural Abstraction & Functions That Return a Value

The flashcards below were created by user senator77 on FreezingBlue Flashcards.

  1. In other programming languages, subparts such as subprograms, procedures, or methods, C++ calls these parts:
  2. The value the function starts out with is called its
  3. The expression sqrt(9) is called a
    function call.
  4. An expression consisting of the function name followed by arguments enclosed in parentheses is a:
    function call.
  5. The name inside the angular brackets <> is the name of the file known as a:
    header file.
  6. A header file for a library provides the compiler with certain basic informatino about the library, and an include directive delivers this information to the compiler. This enables the linker to find object code for the functions in the library so that it can correctly link the library to your program.
  7. A pseudorandom number is one that appears to be random but is really determined by a predictable formula.
    Ri = (Ri-7 * 7) % 11
  8. We can get a random number by calling the function rand, which will return an integer in the range 0 to RAND_MAX. RAND_MAX is a constant defined in cstdlib and is guaranteed to be 32767 or higher.
  9. It is important to seed the random number generator only once.
  10. The notation static_cast<double>(9) is called a type cast. This notation can be used as a predefined function and will convert a value of some other type to a value of type double.
  11. You can define your own functions, either in the same file as the main part of your program or in a separate file so that the functions can be used by several different programs.
  12. The function declaration or function prototype describes how the function is called. C++ requires that either the complete function definition or the function declaration appears in the code before the function is called.
  13. A formal parameter is used as a kind of blank or place holder to stand in for the argument. Formal parameters names will end with _par.
  14. The first word in a function declaration specifies the type of the value returned by the function.
  15. The function call is the expression on the right-hand side of the equal sign:
    bill = total_cost(number, price)
  16. A function definition describes how the function computes the value it returns.
  17. The function header is written the same way as the function declaration, except that the header does not have a semicolon at the end.
  18. The function body follows the function header and completes the function definition. The function body consists of declarations and executable statements enclosed within a pair of braces.
  19. The return statement consists of the keyword return followed by an expression:
    return (subtotal + subtotal * TAX_RATE);
  20. A function may return a bool value.
  21. You are not required to list formal parameters in a function declaration.
  22. Function headers must always list the formal parameter names.
  23. Function declarations are normally placed before the main part of the program and function definitions are normally placed after the main part of the program.
  24. A function definition may contain more than one return statement.
  25. A programmer who uses a function in a program need to know what the function does but should not need to know how the function accomplishes its task. This is often referred to as treating the function like a black box.
  26. Writing and using functions as if they were black boxes is called:
    procedural abstraction.
  27. The variables that belong to a function are called:
    local variables.
  28. Formal parameters are variables that are local to the function definition so they can be used just like a local variable that is declared in the function definition.
  29. When a function is called, the formal parameters for the (which are local variables) are initialized to the values of the arguments.
  30. The scope of a local variable refers to the part of the program that can directly access that variable and is sometimes referred to as:
    local scope.
  31. The scope rule states that identifiers declared within their block are local to that block and accessible only from the point they are defined to the end fo their block.
  32. When you give 2 or more function definitions for the same function name, that is called:
  33. In order to tell which function definition to use, the compiler checks the number of arguments and the types of the arguments in the function call.
  34. If a function requires an argument of type double and you give it an argument of type int, C++ will automatically convert the int argument to the value of type double.
  35. C++ does not convert an int argument to a value of type double unless that is the only way it can find a matching function definition.
  36. A good plan of attack for designing the algorithm for a program is to break down the task to be accomplished into a few subtasks, then decompose each subtask into smaller subtaks, and so forth until the subtask are simple enough that they can easily be implemented as C++ code. This approach is called top-down design.
  37. A function that returns a value is like a small program. The arguments to the function serve as the input to this "small program" and the value returned is like the output of the "small program".
  38. When a subtask for a program takes some values as input and produces a single value as its only result, then that subtask can be implemented as a function.
  39. A function should be defined so that it can be used as a black box. The programmer who uses the function should not need to know any details about how the function is coded. All the programmer should need to know is the function declaration and the accompanying comment that describes the value returned. This rule is sometimes called the principle of procedural abstraction.
  40. A variable that is declared in a function definition is said to be local to the function.
  41. Global named constants are declared using the const modifier. Declarations for global named constants are normally placed at the start of the program after the include directive and before the function declarations.
  42. Call-by-value formal parameters (which are the only kind of formal parameter discussed) are variables that are local to the function. Occasionally, it is useful to use a formal parameter as a local variable.
  43. When you have 2 or more function definitions for the same function name, that is called overloading the function name. When you overload a function name, the function definitions must have different numbers of formal parameters or some formal parameters of different types.
Card Set:
C++ Chapter 4: Procedural Abstraction & Functions That Return a Value
2012-02-12 04:36:56
top down design predefined functions programmer defined local variables procedural abstraction overloading

C++ Chapter 4: Procedural Abstraction & Functions That Return a Value
Show Answers: