10.-Modular-Programming-with function and Sub Procedure.pptx

PurnaBahadurRana1 223 views 13 slides Jun 04, 2024
Slide 1
Slide 1 of 13
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13

About This Presentation

Modular Programming


Slide Content

Modular Programming Chapter 10

Modular Programming The process of breaking a large program into small manageable tasks and design them independently is called modular programming. QBASIC is called modular programming because it allows to break the large and complex program into small and manageable part by using sub procedure and functional procedure. A small, manageable and logical part of the program is called MODULE.

Advantages of Modular Programming Debugging of program become easier and faster. Easy to design code It is possible to use a single module in different places, which reduces program codes. The procedure(module) can be tested separately. Many programmers can write different program modules independently. Note: The idea of divide, solve and conquer is what modular programming approach is all about.

MODULE Main Module: The module which comprises of many sub-modules and control the entire module used in that program. It may top of one or more than one sub module Sub Module: It is a program which is written under the main module. It is controlled by main module. It may have one or more sub modules

PROCEDURE A procedure also called a “module” is a “mini-program” or an isolated part inside the program. In other words, it is a collection of commands and can be executed anywhere in the program. It is a block of statements that solves a particular problem given by the user. It is self-contained and independent manageable part of the program. 2 types: Sub procedure Function procedure

SUB PROCEDURE It is a small manageable and functional part of the program that performs specific tasks and does not return any value to the calling module. It is a block of statements (code) that performs specific task in the program Sub procedure is created by: 1 . Declaring a sub procedure 2 . Defining a sub procedure 3 . Calling a sub procedure

SUB PROCEDURE Declaring a sub procedure: Declaring a sub procedure refers to specifying the Sub procedure’s name, the number and type argument that will be used to call the procedure. The DECLARE statement is used to declare a SUB procedure. Syntax: DECLARE SUB procedure name (parameter list) where procedure name – user defined words with 40 characters long parameter list – a list of variables defined in a procedure which refers the number and type of arguments For example: DECLARE SUB SUM (A,B)

SUB PROCEDURE Defining a sub procedure: Defining a SUB Procedure is the main task because it is the main body part of sub procedure. In QBASIC, SUB procedure is defined by SUB… END SUB. SUB indicates the beginning of the sub procedure and END SUB indicates the end of the sub procedure. Syntax : SUB <name of procedure> (parameter list) <statements> END SUB For example: SUB SUM (A,B) <statements> END SUB

SUB PROCEDURE Calling a sub procedure: The CALL statement is used to call (execute) the sub procedure. It passes the control to the procedures that you want to call and once the procedure is executed, the control returns to the calling program. It is used to transfer control to another procedure. Syntax: CALL procedure name <parameter list> where procedure name – name of procedure to be called parameter list – specifies the name of parameter to be sent For example: CALL SUM (A,B)

SUB PROCEDURE Write a program to find the sum of two numbers. The user must pass the input in the main module.

SUB PROCEDURE Write a program to find the area of rectangle. The user must pass the input in the main module. [A = l x b] DECLARE SUB Area (l , b) CLS INPUT “ Enter a length ” ; l INPUT “Enter a breadth” ; b CALL Area (l , b) END SUB Area (l , b) A = l * b PRINT “The area is ”; A END SUB

Thank You!