Coding - Practical 5 Flashcards
What do functions enable?
Multiple statements to be executed by a single statement referred to as a function call.
What are the two steps in making your own functions?
- Write a function declaration (in the IAP.h file, underneath the FUNCTIONS label).
- Write the function definition (at the bottom of the IAP.cpp file, after the IAP run function.
What does the function declaration do?
The function declaration tells the compiler how the function can be used (to enable error checking at compile time).
What does the function definition do?
The function definition specifies what the function does when it is called.
What is the general form of the function declaration?
return-type functionName ( argument-type(s) );
In the function declaration, what does the return type do (e.g. void)?
The return-type indicates the data type of the value which is returned from the function.
In the function declaration, what does the function name do?
The function-name should indicate what the function does.
In the function declaration, what does the argument type do?
The argument-types indicate the data types of any values that are passed into the function.
What must happen if a function does not return anything?
If a function does not return anything, the return type must be written as void.
Give an example of: A function that does not return anything, nor have any arguments
void makeErrorTone ();
Give an example of: A function that does not return anything, but takes a single argument.
void printTime (int time);
Give an example of: A function that returns a int value, and takes a single argument.
int convertCtoF (int centigrade);
Give an example of: A function that does not return anything, but takes 3 arguments.
void setNote (int note, int velocity, int wave);
Where should function definitions appear?
Function definitions should appear in IAP.cpp separated from the IAP::run() function.
What does a function definition look like?
The first line of the definition should match the declaration, but have the IAP:: statement placed between the return type and function name.