2.2 Flashcards
1
Q
2.2.1
1. What is modularity?
2. What are the different names for modules?
A
- Modularity is the concept of breaking a large program or problem down into smaller chunks. The goal is to design a program so that each module carries out a single, specific task.
- The different names for modules are: subroutines, procedures, functions and methods.
2
Q
2.2.1
1. What is a procedure?
2. What is a function?
A
- A procedure is a block of code that takes in zero, one or more parameters and performs a set task, but does not return a value.
- A function is a block of code that takes in zero, one or more parameters, performs a set task, and returns a value. The return value from a function does not need to be assigned to a variable, as long as it returns a valid item.
3
Q
2.2.1
1. What is the outline of a subroutine?
2. What are the two methods for passing data into a subroutine?
A
- The first line of a subroutine specifies the interface for that subroutine. Depending on the programming language, the layout of a subroutine is slightly different, but the basic outline is: the name of the subroutine, the list of parameters it requires when it is called, the order of those parameters, and the data type for those parameters, and if it is a function, then it also includes a return value.
- The two methods for passing data into a subroutine are: passing by value, passing by reference.
Passing by value means the variable used is a local variable self-contained within the function. Passing by reference means editing the global variable in the program.