Do Visit This Link To Get Other Materials Of Class 10 Computer Science:- Click Here

MODULAR PROGRAMMING

 

Meaning :  The process of  developing program by dividing it into two or more manageable/functional   parts ie; main module and sub module, is called modular programming.

 

Main module: It the upper level part of modular programming which controls all the sub program. Mainly it is a data entry section for sub programs.

 

*Sub module/Procedure:  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 viz;

i. SUB …END SUB

ii. FUNCTION…..END FUNCTION

 

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.

a. Parameter: 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.

 

b. Arguments : It is the list of  variables, array name or constant which are actually passed to the procedures at the time of calling function. It should not be null. It is also called real or actual parameter.

 

c. Global variable : 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 are global variables.

 

d. Local variable:  The variable which is restricted only inside a particular module is called local variable. By default, the entire variable is local in modular programming.

 

a. CALL :  This statement is used to transfer the control between main module and sub procedure. Without this statement, a program does not return the output.

 

FUNCTION…. END FUNCTION:  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.

 

Features:

·                    It returns the specific type of value.

·                    It is recursive.

 

Types of function :

a)                  User defined function:  The function defined by the user in order to return a particle type of value in the program is called user defined function. Eg. Function …End Function and  Def… Fn. It can be called in the different sections within the same program

b)                  Library function :  The functions which are stored in Qbasic program is called library function. It is also known as inbuilt function. It can be called in any programs. For ex. LEN(), INT(), etc.

 

Calling a Function :  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)

 

Common Shared : 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 : CCOMMON  [ SHARED] VARIABLE

Eg. Common shared n,…

 

Dim Shared : It makes the variable accessible by sharing it in both main module and sub module. It is also declared in main module.

Syntax: DIM SHARD VARIBLE(SIZE)as type

Eg: Dim shared  P(10) as integer

 

Passing Arguments to procedures:  When a procedure is called, the calling statements pass the value to the procedure via arguments. There are two methods of passing arguments. They are;

 

*By value : In this method, the values passed to the procedure, does not modify its original value in calling procedure. It is done by enclosing the argument in parenthesis. Eg:  Call Total( x,(y)); here ‘y’ argument  is passed by value.

* By  reference:  In this method,  the value is passed from parameters are copied to the procedure so that any changes in called procedure will affect the value in calling procedure. By default, all arguments are passed by reference in modular programming.