In: Computer Science
Select all the answers that apply to modular design:
1. |
A module may not refer to other modules. |
|
2. |
Modular design is an important part of procedural programming. |
|
3. |
Modular design identifies the components of a program that can be developed independently. |
|
4. |
Each module consists of a set of logical constructs that are related to one another. |
/////////////////////
Place the following parts of a function header into their correct order:
- 1. 2. 3. 4. 5.
closing parenthesis
- 1.
2. 3.
4. 5.
return type
- 1.
2. 3.
4. 5.
type parameters
- 1.
2. 3.
4. 5.
opening parenthesis
- 1.
2. 3.
4. 5.
identifier
//////////////////////////////
Select all of the following statements that are true about function coupling.
It is preferable that each module complete it's own calculations and does not pass control to another module. |
||
A module that receives a value and returns the tax owing on that value using a sliding scale is highly coupled. |
||
The less information that passes between the module and the other modules the better the design. |
||
A module that receives 2 dates and returns the number of days between the dates is highly coupled. |
||
Coupling describes the degree of interrelatedness of a module with other modules. |
//////////////////////////////////////////
A function that does not return anything must declare the return type as void and is not required to have a return statement, however it is considered a best practice to include "return;" as the last line anyway.
True
False
/////////////////////////////////////////
Consider the following code:
#include<stdio.h>
void addTwo(int* param1, int* param2)
{
*param1 -= 2;
*param2 += 3;
return;
}
int main(void)
{
int arg1 = 5, arg2 = 7;
addTwo(&arg1, &arg2);
printf("arg1 = %d and arg2 = %d\n", arg1,
arg2);
return 0;
}
Select all of the following answers which are true:
1. |
This call would cause a run time error: addTwo(arg1, arg2); |
|
2. |
addTwo(&arg1, &arg2); |
|
3. |
addTwo(&arg1, &arg2); |
|
4. |
The ability to pass pointers to functions allows us to code functions that can change 2 or more variables when the function is executed. |
/////////////////////////////////////////////////////////
Consider this C program:
#include<stdio.h>
void addOne(int *in)
{
*in += 1;
return;
}
int main(void)
{
int arg1 = 4;
addOne(&arg1);
printf("The value stored in arg1 is %d\n",
arg1);
return 0;
}
Select from the following answers all that are true:
1. |
addOne(&arg1); When this function call executes the address of arg1 is stored inside the pointer named in. |
|
2. |
*in += 1; Adds 1 to the value stored at the address held inside the pointer in. |
|
3. |
printf("The value stored in arg1 is %d\n", arg1); |
|
4. |
When the function addOne() finishes execution the statement return; is required to return control to main() |
|
5. |
When the function addOne runs, the pointer variable in stores a copy of the value stored in arg1. |
//////////////////////////////////////////////////////////
The following tasks could be performed in one cohesive module:
True
False
///////////////////////////////////////////
Consider the following code:
#include<stdio.h>
int addThese(int arg1, int arg2)
{
return arg1 + arg2;
}
int main(void)
{
int sum1 = 2, sum2 = 3, answer = 0;
answer = addThese(sum1, sum2);
printf("%d\n", answer);
return 0;
}
Select all of the following statements which are true.
arg1 and arg2 are parameters |
||
sum1 and sum2 are arguments |
||
sum1 and sum2 are parameters |
||
arg1 and arg2 are arguments |
/////////////////////////////////////
We can access the data in a variable through either the variable name or by dereferencing its address.
True
False
////////////////////////////////////////
Consider this code snippet:
int x = 0;
int *p = &x;
*p = 79567;
After this code snippet runs the address of x is set to 79567.
True
False
/////////////////////////////////////
A function that does not receive any data when called has no parameters and must use the term void in the parameter list.
True
False
//////////////////////////////////////////////////////////////////
Order the following statements so they represent the correct order of operation of the following program:
#include<stdio.h>
int main(void)
{
printf( "Hello world!\n");
return 0;
}
- 1. 2. 3. 4.
the printf function outputs "Hello world!" followed by a new line
- 1.
2. 3.
4.
main() returns control to the OS, with value zero(0)
- 1.
2. 3.
4.
printf() returns control to main()
- 1.
2. 3.
4.
main() transfers control to printf()
///////////////////////////////////////////////////////////////////////////////////
The following tasks could be performed in one cohesive module:
True
False
///////////////////////////////////////////////////////
Every variable in a C program has a unique address.
True
False
////////////////////////////////////////////////////////////////
A pointer variable is not strongly typed, which means that the address of a floating point variable may be stored in an int type pointer.
True
False
A) Answers that apply to modular design: 3,4
1)A module may not refer to other modules- Each module executes a specific code and fulfilfills a particular functionality of the program. To do so it takes in input from some module(s) and gives output to be used by them. Hence every module must refer to some of the modules in the program. No module can remain isolated. So this statement does not apply to modular design.
2)Modular design is an important part of procedural programming- A procedure call basically calls a function and a subroutine that is a part of the same monolithic program.This practice is called structured programming. In case of Modular design divides the goal into sub goals and each subgoal is executed through a separate module, with proper interfacing among them. So this statement does not apply to modular design.
3)Modular design identifies the components of a program that can be developed independently- The philosophy behind modular design approach is to solve the problem by didviding it into subproblems, each of which are independently solvable. So this statement correctly applies to modular design.
4)Each module consists of a set of logical constructs that are related to one another- Each module is responsible for executing a specific purpose which is done by means of logical constructs. So this statement correctly applies to modular design.
B) The correct order is-
1)return type
2)identifier
3)opening parenthesis
4)type parameters
5)closing parenthesis
Example: int add( int, int)
add is a function to add two integer values and return the sum which is again of type integer.
C)Statements that are true about function coupling:
1)It is preferable that each module complete it's own calculations and does not pass control to another module. True. This is the basic definition of modular design
2)A module that receives a value and returns the tax owing on that value using a sliding scale is highly coupled. False. This is an example of data coupling which is the best form of coupling. So these modules are loosely coupled,
3)The less information that passes between the module and the other modules the better the design. True. This prevents interdependance of modules on one another.
4)A module that receives 2 dates and returns the number of days between the dates is highly coupled. False. This is an example of data coupling which is the best form of coupling. So these modules are loosely coupled.
5)Coupling describes the degree of interrelatedness of a module with other modules.True. A good design should aim to minimize coupling.
D) A function that does not return anything must declare the return type as void and is not required to have a return statement, however it is considered a best practice to include "return;" as the last line anyway.
This statement is TRUE because it makes the code safe and there is a clear ending of the code
E) Select all of the following answers which are true-
1)This call would cause a run time error:FALSE
2)addTwo(&arg1, &arg2);
//outputs "arg1 = 3 and arg2 = 10": TRUE
3)addTwo(&arg1, &arg2);
//outputs "arg1 = 10 and arg2 = 3": FALSE
4)The ability to pass pointers to functions allows us to code functions that can change 2 or more variables when the function is executed.: TRUE
F)Select from the following answers all that are true:
1) addOne(&arg1);
When this function call executes the address of arg1 is stored inside the pointer named in. TRUE
2)*in += 1;
Adds 1 to the value stored at the address held inside the pointer in.TRUE
3) printf("The value stored in arg1 is %d\n", arg1);
//outputs "The value stored in arg1 is 5" :
TRUE
4)When the function addOne() finishes execution the statement return; is required to return control to main(): TRUE
5)When the function addOne runs, the pointer variable in stores a copy of the value stored in arg1. TRUE
G) The following tasks could be performed in one cohesive module:
This statement is FALSE. The three tasks are independent in nature and must be done in separate modules.
H)Select all of the following statements which are true.
1)arg1 and arg2 are parameters : TRUE
2)sum1 and sum2 are arguments : TRUE
3)sum1 and sum2 are parameters : FALSE
4)arg1 and arg2 are arguments : FALSE
I)We can access the data in a variable through either the variable name or by dereferencing its address:TRUE
J)int x = 0;
int *p = &x;
*p = 79567;
After this code snippet runs the address of x is set to 79567.
The statement is FALSE. Pointer p contains address of x which is already 79567
K)A function that does not receive any data when called has no parameters and must use the term void in the parameter list.: TRUE. This ensures clean coding
L)Correct order is-
1) main() transfers control to printf()
2) the printf function outputs "Hello world!" followed by a new line
3) printf() returns control to main()
4) main() returns control to the OS, with value zero(0)
M) The following tasks could be performed in one cohesive module:
The statement is TRUE. The formula for GST can be progrmmed to compute tax in one module.
N) We can access the data in a variable through either the variable name or by dereferencing its address:TRUE
O)Every variable in a C program has a unique address. This statement is TRUE
P)A pointer variable is not strongly typed, which means that the address of a floating point variable may be stored in an int type pointer. This statement is FALSE