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

1
Q

A key element of structured (well organized and documented) programs is their
_____.

A

modularity

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

modularity is the breaking of code into

A

small units.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

void functions do not ___

A

return a value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

The int main() section of our program is a function and, up until now, has been the only ___ used in our programs.

A

coded module

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

We also have used _____such as pow and sqrt which are defined in library routines and “imported” to our program with the #include directive.

A

pre-defined functions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

We now explore the means of breaking our own code into modules. The main function
should contain little more than ____ to other functions.

A

“calls”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Calling a function basically means starting the ____ contained in that module..

A

execution of the instructions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Sometimes a function may need information _____ in order to perform designated tasks.

A

“passed”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Information is passed to or from a function through __.

A

parameters.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Parameters are the ___ between functions.

A

components of communication

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

_______ printDescription(); // ____________

A

type functionname(); // Function prototype

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
int main() 
{ 
cout << "Welcome to the Payroll Program." << endl; 
functionname(); // \_\_\_\_\_\_\_\_\_\_\_\_
return 0; 
}
A

functionname(); // Call to the function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
void printDescription() // The function heading
{
// \_\_\_\_ This function prints a program description
// \_\_\_\_\_ none
}
A
type functionname() // The function heading
// Task:
// Data in:
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

The function heading void printDescription() consists of the _____ of the function preceded by the word _____.

A

name , void.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

The word void means that this function will not _____

A

return a value to the module that called it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q
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.
}
A

left, right, instructions

17
Q

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.

A

name, preceding,

18
Q
void calPaycheck(float, int);
                             parameters

calPaycheck(payRate, hours);
parameters
passed

void calPaycheck(float rate, int time)
                                parameters
A

// 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:
19
Q

Let us look at all three parts—prototype, call and heading:

1. The heading ____ have ____ data ____ and name for all its _____.

A

MUST, both, data type and name, parameters

20
Q

Let us look at all three parts—prototype, call and heading:

2. The prototype ___ have the data type and ____ have the name for its ____.

A

MUST, can, parameters

21
Q

Let us look at all three parts—prototype, call and heading:

3. The call ____ have the ____ but MUST ___ have the ____ type for its _____.

A

MUST, name, NOT, data , parameters

22
Q

void calPaycheck(float, int, float&);

A
// prototype for a function with 3 parameters.
// The first two are passed by value.
// The third is passed by reference.
23
Q

pass by value

calPaycheck(payRate, hours, grossPay); // Call to the calPaycheck function
etPay = grossPay - (grossPay * .20);

A

formal parameter has no effect

on its corresponding actual parameter

24
Q

passed by reference,

void calPaycheck(float rate, int time, float& gross)
{
gross = rate * time;
}
A

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.

25
Q

The word ________ precedes the name of every function prototype and heading that does not return a value back to the calling routine.

A

void

26
Q

Pass by __________ indicates that a copy of the actual parameter is placed in the memory location of its corresponding formal parameter.

A

Value

27
Q

______ parameters are found in the call to a function.

A

formal

28
Q

A prototype must give the _______ of its formal

parameters and may give their ________.

A

data types, names

29
Q

A ________ after a data type in the function heading and in the prototype indicates that the parameter will be passed by reference.

A

&

30
Q

void Functions that do not return a value are often called in ______ other programming languages

A

procedures

31
Q

Pass by _____ indicates that the location of an actual parameter, rather than just a copy of its value, is passed to the called function.

A

Referance

32
Q

A call must have the ______ of its actual parameters and must NOT have the ______ of those parameters.

A

formal, data types

33
Q

refers to the region of a program where a variable is

“active.”

A

scope

34
Q

____ and _____parameters are found in the function heading.

A

data type and formal