Modular Programming
Chapter-9
Class-10
Presenter By: Bhuwan Bist
Computer Teacher,
Adarah Vidya Niketan Secondary
School
Bhuwan_Bista
Overview
• Modular programming is a technique used to divide our
program into many small, manageable and functional
module or block.
• Every modular program has one main module and many sub
module. The sub module of a program is also called as a
procedure.
• Main module is the top level module in which program entry
and exit takes place.
•Sub-Module is a block of statement that is used for specific
task and controlled by main module. Click to adBhuwan_Bista
Structure of Modular Programming
Main
Program-M1
Module-M2
Module-M6 Module-M7
Module-M3 Module-M4 Module-M5
Module-M8
Bhuwan_Bista
Advantages of Modular program
It reduces program codes.
 Increases the readability of program.
 Easy to debug program.
 Program maintenance become easier.
Module can be tested independently
Saving the time during project development.
Click tm Bhuwan_Bista
Types of Procedure in Qbasic Program
In Qbasic, a programmer can name a block of code can
be executed by simple calling out that name. These
name block of code are called procedures.
The two types of procedures are:
1. SUB Procedure
2. FUNCTION Procedure
Click t oBhuwan_Bista
add text
SUB Procedure
 A SUB Procedure is a small manageable and functional part
of program that performs specific task and does not return
any value to the calling module.
 The block of statements is placed with a pair of SUB/END
SUB statement and can be called by its name.
Bhuwan_Bista
Features of SUB Procedure
SUB procedure cannot be a part of an expression and does not
return any value.
SUB procedure do not have data type.
Argument can be passed to the subprogram by reference and
by value method.
SUB procedure name can't be used as a variable .
SUB procedure is called by CALL statement.
Bhuwan_Bista
Declaring SUB Procedure
 The DECLARE statement is used to declare a SUB procedure.
The syntax for the DECLARE statement is as follows:
DECLARE SUB name(parameter list)
Example:
DECLARE SUB volume(L,B,H)
SUB procedure volume with three parameters L,B and H
Bhuwan_Bista
Defining a SUB Procedure
oThe SUB....END SUB statement is a procedure
statement that marks the beginning and ending of a
subprogram. The syntax is:
SUB Procedure name [parameter, list]
[Statement]
END SUB
Bhuwan_Bista
Call a SUB Procedure
• The CALL statement is used to transfer control to another procedure,
a BASIC SUB program.
• The syntax is
CALL name(argument list)
Example:
CALL circumference(r)
Bhuwan_Bista
Example
• Write a program to create a sub-procedure to input the value of length,
breadth and height of a cuboid. The program should calculate the diagonal,
volume and of a cuboid.
FUNCTION Procedure
 A function is a small manageable and functional part of a
program that performs specific task and returns a value to the
main program or calling module.
 It is written with FUNCTON.....END FUNCTON Statements.
Bhuwan_Bista
Features of FUNCTION Procedure
⮚ FUNCTON procedure are used in expressions and can directly
returns a single value.
⮚ FUNCTION procedure have a data type which is the return
value of the function.
⮚ The parameters can be passed by reference or by value.
⮚ FUNCTION procedure can be recursive.
Bhuwan_Bista
Example
• Write a program to declare a user defined function using FUNCTION.....END
FUNCTION to print the area of a triangle by using expression method.
Bhuwan_Bista
The difference between Function procedure and SUB
procedure
SUB Procedure FUNCTION Procedure
The block of statement Is placed with a pair of
a SUB/END SUB statement and be called by
name.
The block of statement is placed with a pair of
FUNCTION/END FUNCTION statements and be
invoked from the reference of the function
name.
It dies nit return any value . It directly returns a single value
It does not have a data type It has a data type which is the return value of
the function.
Bhuwan_Bista
What are parameters?
Parameters are variables that receives data (argument values)
and the procedure (SUB/FUNCTION procedure)
Arguments: The constant and variable enclosed in the
parentheses of procedure call statement and that are supplied
to a procedure and known as arguments.
Bhuwan_Bista
Thank You

Modular programming

  • 1.
    Modular Programming Chapter-9 Class-10 Presenter By:Bhuwan Bist Computer Teacher, Adarah Vidya Niketan Secondary School Bhuwan_Bista
  • 2.
    Overview • Modular programmingis a technique used to divide our program into many small, manageable and functional module or block. • Every modular program has one main module and many sub module. The sub module of a program is also called as a procedure. • Main module is the top level module in which program entry and exit takes place. •Sub-Module is a block of statement that is used for specific task and controlled by main module. Click to adBhuwan_Bista
  • 3.
    Structure of ModularProgramming Main Program-M1 Module-M2 Module-M6 Module-M7 Module-M3 Module-M4 Module-M5 Module-M8 Bhuwan_Bista
  • 4.
    Advantages of Modularprogram It reduces program codes.  Increases the readability of program.  Easy to debug program.  Program maintenance become easier. Module can be tested independently Saving the time during project development. Click tm Bhuwan_Bista
  • 5.
    Types of Procedurein Qbasic Program In Qbasic, a programmer can name a block of code can be executed by simple calling out that name. These name block of code are called procedures. The two types of procedures are: 1. SUB Procedure 2. FUNCTION Procedure Click t oBhuwan_Bista add text
  • 6.
    SUB Procedure  ASUB Procedure is a small manageable and functional part of program that performs specific task and does not return any value to the calling module.  The block of statements is placed with a pair of SUB/END SUB statement and can be called by its name. Bhuwan_Bista
  • 7.
    Features of SUBProcedure SUB procedure cannot be a part of an expression and does not return any value. SUB procedure do not have data type. Argument can be passed to the subprogram by reference and by value method. SUB procedure name can't be used as a variable . SUB procedure is called by CALL statement. Bhuwan_Bista
  • 8.
    Declaring SUB Procedure The DECLARE statement is used to declare a SUB procedure. The syntax for the DECLARE statement is as follows: DECLARE SUB name(parameter list) Example: DECLARE SUB volume(L,B,H) SUB procedure volume with three parameters L,B and H Bhuwan_Bista
  • 9.
    Defining a SUBProcedure oThe SUB....END SUB statement is a procedure statement that marks the beginning and ending of a subprogram. The syntax is: SUB Procedure name [parameter, list] [Statement] END SUB Bhuwan_Bista
  • 10.
    Call a SUBProcedure • The CALL statement is used to transfer control to another procedure, a BASIC SUB program. • The syntax is CALL name(argument list) Example: CALL circumference(r) Bhuwan_Bista
  • 11.
    Example • Write aprogram to create a sub-procedure to input the value of length, breadth and height of a cuboid. The program should calculate the diagonal, volume and of a cuboid.
  • 12.
    FUNCTION Procedure  Afunction is a small manageable and functional part of a program that performs specific task and returns a value to the main program or calling module.  It is written with FUNCTON.....END FUNCTON Statements. Bhuwan_Bista
  • 13.
    Features of FUNCTIONProcedure ⮚ FUNCTON procedure are used in expressions and can directly returns a single value. ⮚ FUNCTION procedure have a data type which is the return value of the function. ⮚ The parameters can be passed by reference or by value. ⮚ FUNCTION procedure can be recursive. Bhuwan_Bista
  • 14.
    Example • Write aprogram to declare a user defined function using FUNCTION.....END FUNCTION to print the area of a triangle by using expression method. Bhuwan_Bista
  • 15.
    The difference betweenFunction procedure and SUB procedure SUB Procedure FUNCTION Procedure The block of statement Is placed with a pair of a SUB/END SUB statement and be called by name. The block of statement is placed with a pair of FUNCTION/END FUNCTION statements and be invoked from the reference of the function name. It dies nit return any value . It directly returns a single value It does not have a data type It has a data type which is the return value of the function. Bhuwan_Bista
  • 16.
    What are parameters? Parametersare variables that receives data (argument values) and the procedure (SUB/FUNCTION procedure) Arguments: The constant and variable enclosed in the parentheses of procedure call statement and that are supplied to a procedure and known as arguments. Bhuwan_Bista
  • 17.