Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3 views

Modular Programming

Modular programming is the practice of dividing a large program into smaller, manageable sections called modules, which can be developed independently. It offers advantages such as easier debugging and reduced code repetition, but can also lead to issues with variable naming and module linking. Key concepts include main modules, sub-modules, parameters, global and local variables, and methods of argument passing.

Uploaded by

rauniyarchanda01
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Modular Programming

Modular programming is the practice of dividing a large program into smaller, manageable sections called modules, which can be developed independently. It offers advantages such as easier debugging and reduced code repetition, but can also lead to issues with variable naming and module linking. Key concepts include main modules, sub-modules, parameters, global and local variables, and methods of argument passing.

Uploaded by

rauniyarchanda01
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

MODULAR PROGRAMMING

1) What is modular programming?


Ans: The process of breaking a large program into small manageable task and designed them independently is
called modular programming. Modular programming helps the programmer for coding in easy way.
2) What is main module?
Ans: It the upper level part of modular programming which controls the entire sub program. Mainly it is a
data entry section for sub programs.
3) What is Sub module/procedure?
Ans: It is a small program written under main module, which process the data and returns the output. There
may be one or more sub modules under a main module. There are two types of sub programs through:
i. SUB …END SUB
ii. FUNCTION…..END FUNCTION
4) Advantages of modular programming:
 It is easy and efficient to handle large project
 Debugging is easier.
 It reduces the task of repeated coding, since same module can be used in different places.
5) Write down the disadvantages of modular programming.
 Can lead problems with variable names.
 Can lead to problem when modules are linked because link must thoroughly test.
6) What is Argument?
Ans: It is the list of variables, array name or constant which are actually passed to the procedures at the time of
calling function. It is also called real or actual parameter.
7) What is Parameter?
Ans: It the list of variables or array name which are passed to the procedure formally, while declaring the
function or sub procedure. It may be null. It is of two types;
- Formal Parameter
- Actual Parameter
Formal parameters are variable which are used to specify or declare types of data to be passed to the
procedures either sub or function. A formal parameter is always variable.
Actual or Real Parameter: Actual or Real parameters are arguments which are used to pass real value or data
to the procedure. Actual parameter may be variables or constant values.
Example:
DECLARE SUB SUM (A,B)
M=10
N=20
In this example,
CALL SUM (A,B) M and N are actual parameters or Arguments.
END A,P,B and D are formal Parameters.
SUB SUM (P,D)
S=P+D
PRINT “SUM OF TWO NUMBERS=”;S
END SUB
8) What is Global Variable?
Ans: The variable declared outside the modules is called global variable. It can be accessed from both main
module and sub module in the program. Generally, variable declared inside parameter, with Dim shared and
Common shared is global variables.
9) What is Local Variable?
Ans: The variable which is restricted only inside a particular module is called local variable. By default, the
entire variable is local in modular programming.
10) What is SUB…END SUB statement?
Ans: The SUB….END SUB is a procedural statement which is used to define a sub procedure. It declares sub
name related parameter and program codes. The procedure name in SUB statement should be defined same as
the declaration level.
11) What is CALL statement?
Ans: This statement is used to transfer the control between main module and sub procedure. Without this
statement, a program does not return the output.
12) What is FUNCTION…. END FUNCTION?
Ans: It is a user defined function, which accepts data, processes them and returns a value of specific type.
Function… End Function marks the beginning and ending of Function procedure.
13) What is Common Shared?
Ans: This statement is used to make the variable accessible in both main module and sub module. It makes the
variable global. It is declared in main module.
Syntax : COMMON [ SHARED] VARIABLE
Eg. Common shared n,…
14) What do you understand by calling a function?
Ans: To execute the function by passing argument for specific data value is called invoking or calling a
function. It can be called by the following ways:
Variable method (Expression method), eg. V= sum(a,b)
Print method (statement method) , eg: print sum(a,b)
15) What do you understand by Argument passing by value?
Ans: This is the method of passing the real or direct value to the procedure parameter from the calling section.
The arguments and parameters use different memory address. In this method, the values of parameters are
transferred to the parameters to that any change made in the value of parameter does not change the value of
argument.
Example:
DECLARE SUB ADD(A,B)
CLS
CALL ADD(10, 20)
END
SUB ADD(A,B)
S=A+B
PRINT “SUM OF TWO NUMBERS= ”; S
END SUB
16) What do you understand by Argument passing by reference?
Ans: This is the most common method of passing the address or reference to the variable from main module to
sub module instead of value. In this method, the parameters use the same memory address of the arguments
so that any changes made in the value of param eter will change the value of argument too.
Example:
DECLARE SUB KE(M,V)
CLS
INPUT “ENTER THE MASS”;M
INPUT “ENTER THE VELOCITY”;V
CALL KE(M,V)
END
SUB KE(M,V)
K=(1/2)*M*V^2
PRINT “KINETIC ENERGY=”;K
END SUB

You might also like