W6 - FUNTIONS Flashcards

1
Q

W6-1: What is MODULAR DESIGN?

A

_ Procedural programming involves SEPARATING source code into SELF-CONTAINED components that can be accessed multiple times from different locations in a COMPLETE program.

_ This approach enables SEPARATE coding of each component and assembly of various components into a complete program.

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

W6-2: How MODULAR DESIGN works?

A

_ Modular design identifies the COMPONENTS of a programming project that can be developed SEPARATELY

_ Each module consists of a set of LOGICAL constructs that are related to one another.

_ A module may refer to other modules.

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

W6-3: DESIGN PRINCIPLES:

A
Some general GUIDELINES for defining a module include:
_ the module is easy to UPGRADE
_ the module contains a READABLE amount of code
_ the module may be used as part of the solution to some other problem
For a STRUCTURED design:
_ each module has one ENTRY point and one EXIT point
_ each module is highly COHESIVE
_ each module exhibits LOW coupling
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

W6-4: What is COHESION?

A
COHESION describes the focus: 
a highly COHESIVE module performs a SINGLE task and only that task. 

In creating a cohesive module, we ask whether our tasks belong to that module:
_ a reason to INCLUDE a task is its relation to the other tasks within the module.
_ A reason to EXCLUDE a task is its independence from other tasks within the module.

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

W6-5: What is COUPLING?

A

_ COUPLING describes the degree of interrelatedness of a module w/t other modules.

_ The less INFO that passes btw the module and the other modules the better the design.

_ We prefer designs in which each module completely control its OWN computations and avoids transferring control data to any other module.

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

W6-6: Definition of CALLS, RETURNS, CALLER

A

_ (C) supports modular design through FUNCTION syntax

_ Functions transfer CONTROL btw one another.

_ When a function TRANSFERS control to another function, => it CALLS the other function.

_ Once the other function COMPLETES its task and transfers control to the CALLER function
=> that other function RETURNS control to its CALLER

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

W6-7: Definition of FUNCTION

A

_ A function consists of a HEADER and a BODY.

_ The BODY is the code block that contains the DETAILED instructions to be performed by the function.

_ The HEADER immediately precedes the body and includes the following IN ORDER
1/ the type of the function’s return value
2/ the function’s identifier
3/ a parentheses-enclosed list of parameters that receive data from the caller

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

W6-8: void Functions

A

_ A function that does not have to return any value has NO return type.

_ declare its return type as VOID and EXCLUDE any expression from the return statement.

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

W6-9: No Parameters

A

_ A function that does not have to receive any data does not require parameters.

_ insert the keyword VOID btw the parentheses.

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

W6-10: main

A

_ The main() function is a FUNCTION itself.
_ It is the function to which OS transfers CONTROL after loading the program into RAM.

_ main() returns a value of int type to OS once it has completed execution.  
_ A value of 0 indicates success to OS
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

W6-11: What is a FUNCTION CALL?

A

_ A FUNCTION CALL transfers control from the CALLER to function being called.

_ Once the function being called has executed its instructions, it returns control to the CALLER.

_ Execution continues at the point immediately following the CALL statement.

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

W6-12: Pass By Value

A

_ the mechanism of allocating SEPARATE memory locations for parameters and using the arguments in the FUNCTION CALL to initialize these parameters: pass by value.

_ Pass by value facilitates modular design by localizing consequences.

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