Functions Flashcards
To introduce the concept of void functions (procedures) 2. To work with void functions (procedures) that have no parameters 3. To introduce and work with void functions (procedures) that have pass by value and pass by reference parameters
A key element of structured (well organized and documented) programs is their
_____.
modularity
modularity is the breaking of code into
small units.
void functions do not ___
return a value
The int main() section of our program is a function and, up until now, has been the only ___ used in our programs.
coded module
We also have used _____such as pow and sqrt which are defined in library routines and “imported” to our program with the #include directive.
pre-defined functions
We now explore the means of breaking our own code into modules. The main function
should contain little more than ____ to other functions.
“calls”
Calling a function basically means starting the ____ contained in that module..
execution of the instructions
Sometimes a function may need information _____ in order to perform designated tasks.
“passed”
Information is passed to or from a function through __.
parameters.
Parameters are the ___ between functions.
components of communication
_______ printDescription(); // ____________
type functionname(); // Function prototype
int main() { cout << "Welcome to the Payroll Program." << endl; functionname(); // \_\_\_\_\_\_\_\_\_\_\_\_ return 0; }
functionname(); // Call to the function
void printDescription() // The function heading { // \_\_\_\_ This function prints a program description // \_\_\_\_\_ none }
type functionname() // The function heading // Task: // Data in:
The function heading void printDescription() consists of the _____ of the function preceded by the word _____.
name , void.
The word void means that this function will not _____
return a value to the module that called it.
void functionname() { Just like the main function, all functions begin with a \_\_\_\_ brace and end with a \_\_\_ brace. In between these braces are the \_\_\_\_\_ of the function. In this case they consist solely of cout statements that tell what the program does. }
left, right, instructions
This function is called by main with the simple instruction printDescription();.Notice the call consists only of the ___ of the function (not the word void ______ it) followed by the set of parentheses and a semicolon.
name, preceding,
void calPaycheck(float, int); parameters
calPaycheck(payRate, hours);
parameters
passed
void calPaycheck(float rate, int time) parameters
// Function prototype
// Call to the calPaycheck function pass parameters-They match in a one-to-one correspondence with the parameters in the function heading which are called rate and time:
// The function heading // Task: // Data in:
Let us look at all three parts—prototype, call and heading:
1. The heading ____ have ____ data ____ and name for all its _____.
MUST, both, data type and name, parameters
Let us look at all three parts—prototype, call and heading:
2. The prototype ___ have the data type and ____ have the name for its ____.
MUST, can, parameters
Let us look at all three parts—prototype, call and heading:
3. The call ____ have the ____ but MUST ___ have the ____ type for its _____.
MUST, name, NOT, data , parameters
void calPaycheck(float, int, float&);
// prototype for a function with 3 parameters. // The first two are passed by value. // The third is passed by reference.
pass by value
calPaycheck(payRate, hours, grossPay); // Call to the calPaycheck function
etPay = grossPay - (grossPay * .20);
formal parameter has no effect
on its corresponding actual parameter
passed by reference,
void calPaycheck(float rate, int time, float& gross) { gross = rate * time; }
which means that the calling function will give the called function the location of its actual parameter instead of a copy of the value that is stored in that
location.
The word ________ precedes the name of every function prototype and heading that does not return a value back to the calling routine.
void
Pass by __________ indicates that a copy of the actual parameter is placed in the memory location of its corresponding formal parameter.
Value
______ parameters are found in the call to a function.
formal
A prototype must give the _______ of its formal
parameters and may give their ________.
data types, names
A ________ after a data type in the function heading and in the prototype indicates that the parameter will be passed by reference.
&
void Functions that do not return a value are often called in ______ other programming languages
procedures
Pass by _____ indicates that the location of an actual parameter, rather than just a copy of its value, is passed to the called function.
Referance
A call must have the ______ of its actual parameters and must NOT have the ______ of those parameters.
formal, data types
refers to the region of a program where a variable is
“active.”
scope
____ and _____parameters are found in the function heading.
data type and formal