Coding - Practical 5 Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What do functions enable?

A

Multiple statements to be executed by a single statement referred to as a function call.

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

What are the two steps in making your own functions?

A
  1. Write a function declaration (in the IAP.h file, underneath the FUNCTIONS label).
  2. Write the function definition (at the bottom of the IAP.cpp file, after the IAP run function.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does the function declaration do?

A

The function declaration tells the compiler how the function can be used (to enable error checking at compile time).

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

What does the function definition do?

A

The function definition specifies what the function does when it is called.

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

What is the general form of the function declaration?

A

return-type functionName ( argument-type(s) );

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

In the function declaration, what does the return type do (e.g. void)?

A

The return-type indicates the data type of the value which is returned from the function.

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

In the function declaration, what does the function name do?

A

The function-name should indicate what the function does.

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

In the function declaration, what does the argument type do?

A

The argument-types indicate the data types of any values that are passed into the function.

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

What must happen if a function does not return anything?

A

If a function does not return anything, the return type must be written as void.

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

Give an example of: A function that does not return anything, nor have any arguments

A

void makeErrorTone ();

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

Give an example of: A function that does not return anything, but takes a single argument.

A

void printTime (int time);

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

Give an example of: A function that returns a int value, and takes a single argument.

A

int convertCtoF (int centigrade);

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

Give an example of: A function that does not return anything, but takes 3 arguments.

A

void setNote (int note, int velocity, int wave);

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

Where should function definitions appear?

A

Function definitions should appear in IAP.cpp separated from the IAP::run() function.

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

What does a function definition look like?

A

The first line of the definition should match the declaration, but have the IAP:: statement placed between the return type and function name.

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