Saturday, October 1, 2022

3.1 Modular Programming

 3.1 Modular Programming

 

Modular programming
Modular programming is a technique used to divide program into many small, manageable, logical and functional modules or blocks.

 

Qbasic is called Modular Programming QBasic is called modular programming because it divides program into many small, manageable, logical and functional modules or blocks.

 

Advantages of modular programming

i) Different programmers can design different program modules independently, which is required in a large and complex program.
ii) It is easy to design code and test the program modules independently.
iii) It is possible to use a single module in different places which reduces program codes.

 

Main module
The top level controlling section or the entry point in modular programming is called main module.

Sub module
Module is a block of statement that solves a particular problem. Sub module is a program which is written under the main module. A program may have one or more sub modules under main module.

 

Procedure

Procedure is a block of statements that solves a particular program.

There are two types of procedure – SUB Procedure and FUNCTION procedure

SUB procedure
A SUB procedure is a small, logical and manageable functional part of program which prefers specific task and does not return any value.

SUB-procedure is called by CALL statement. SUB-procedure’s name does not accept data type symbol because it does not need to return a value.

FUNCTION procedure
A FUNCTION procedure is a small, logical and manageable functional part of a program which performs specific task and returns single value to the main program or calling module. FUNCTION-procedure is called by statement and expression method.

FUNCTION-procedure’s name accepts data type symbols such as $, %, !, #, &, etc. and it depends on the type of value to be returned. E.g.: FUNCTION REV$ returns string.

String function [SEE 2074 U]

String function is used with string it returns string value.

Numeric function [SEE 2074 U]

Numeric function is used with number it returns numeric value.

Library functions [SQE 2074K]
Library functions are built-in or readymade functions provided by QBASIC. E.g. MID$( ), LEN( ), SQR( ) etc.

User defined function
Function which is defined by the user according to the need is called user defined function.

 

Parameters [SEE 2074]

Parameters are variables that will receive data (arguments value) sent to the procedures (SUB program and FUNCTION). Formal parameters are called parameter.

 

Arguments
Arguments are the values that are sent to the procedures (SUB program and FUNCTION). Actual or real parameters are called arguments.

 

CALL statement [SLC 2071] [PMT 2075K]
The function of CALL statement is to transfer the control to another procedure.

 

DECLARE statement
The function of DECLARE statement is to declare procedure such as FUNCTION or SUB in modular programming.

 

DIM SHARED statement
i) It makes variable accessible to all modules.
ii) It appears in main module/ program.

 

 

 

SHARED [SLC 2071]

It is used in the sub program to share the values of certain variables between main module and sub program

 

COMMON SHARED [SEE 2074 U]

It is used in the main program to share variable list between main module and all sub programs. This statement is used to declared variable global.

 

Local Variable [SEE 2075 S2]

Variables which are declared inside the procedure are called local variables.

Local variables are not visible to other modules or functions.

Its value is protected from outside interference and has no effect on the variables outside the procedures.

Local variable can access only in its own module.

 

Global Variable [SEE 2075 S2]

Variables which are declared outside the procedure are called global variables. 

Global variables are visible to other modules or functions.

Its values can be accessed from any procedure or module.

Global variable can be access throughout the program

 

 

 

 

Passing arguments by value

When arguments are passed by value it makes a duplicate copy of arguments and their values (constants) are used directly in parameter. It doesn’t make any effect on values of variable which are passed to a procedure even they are changed in the procedure. To pass the argument by value, variable is enclosed in parenthesis.

 

Passing arguments by reference

When arguments are passed by reference the address of the variables are passed to the procedure. The changes made in the procedure’s variable will affect the variables used at calling module. By default the value is passed by reference.

 

Qbasic Operators [MFT 2075] [SQE 2074K]

Operators are special symbols that are meant for specific tasks or operators.

i) Arithmetic operators

ii) Relational operators

iii) Logical Operators

iv) String operator

 

Static variable

The variable which is declared by using the “STATIC” keyword is called static variable.

 

 

 

 

 

 

 

Comparing C and QBASIC language

 

QBASIC

C

It is a high level language without feature of low level language.

It is a high level language with some features of low level language.

It is mostly used to design application software.

It is mostly used to prepare system software.

It supports structure programming with sub and function procedure.

It is a structured programming language with function procedure.

It is not case sensitive

It is case sensitive

IBM PC version of BASIC has around 159 keywords.

It has only 32 keywords.

 

 

 


No comments:

Post a Comment