Modular
programming
Modular
programming
Modular
programming is a technique which divides program into many small logical,
manageable and functional modules or blocks.
Advantages of modular programming
v
Coding
the program and testing is very easy.
v Different
programmers can write different modules separately.
v Debugging of the
program becomes easier and faster.
v
Possible
to use single module in different places.
Main Module
The top-level module is called main module which is
located at the top of all procedures such as sub procedure or function
procedure.
Sub module
Sub-module is a program which is written under main
module.
Procedure / Sub
Routine / Module
A procedure is a block of statement that solves a
particular problem given by user.
Types of Procedure in Modular Programming
v Sub-procedure
v Function-procedure
SUB procedure
A
sub-procedure is a small manageable and functional part of a program that
performs specific tasks and does not return any value to the calling
module.
Features of sub procedure
v It is called by
using CALL statement.
v It cannot be used
as a variable.
v It doesn't return
value to the calling module.
v Sub procedure name
cannot have type declaration sign.
FUNCTION procedure
A function-procedure is a small manageable and
functional part of a program that performs specific tasks and returns a value
to the calling module.
Features of function procedure
v It returns value
to the calling module.
v Function procedure
name have type declaration sign.
v A function name
can be used as an expression.
v Variables used
inside a sub program are local by default.
Difference between sub and function
procedure.
Sub procedure |
Function procedure |
Sub procedure name cannot have type declaration sign |
Function procedure name not have type declaration
sign |
Sub procedure does not return value to calling
module |
Function procedure returns value to the calling
module |
DECLARE statement
The DECLARE statement is a non- executable statement
that declares references to QBASIC sub-program.
CALL statement
The CALL statement is a statement that transfers
control to another sub procedure.
Which statement is used to call sub-procedure?
CALL statement is used to call
sub-procedure.
Formal parameter (Parameter)
Formal parameter are variables which are used to
specify or declare types of data to be passed to the procedure either sub or
function. A formal parameter is always variable(s).
Actual parameter (Real parameter/argument)
Actual parameter is argument which is used to pass
real value or data to the procedure.
Actual parameters may be variables or constant values
or can also be in the form of expression.
What
is passing argument by value in QBasic?
Call by
value is a method of calling a procedure in which actual data are passed to the
calling procedure module. It is done by enclosing each parameter by a separate
parenthesis ( ).
What
is passing argument by reference in QBasic?
Call by
reference is a method of calling a procedure in which the reference (address)
of parameters are passed to the calling procedure module instead of actual
value. By default, the parameters are passed using call by reference method
Difference between passing argument by
Reference and passing argument by value methods
Passing argument by reference |
Passing argument by value |
When arguments are passed by reference, the address
of the variable are passed to the procedure. |
When arguments are passed by value, it makes a
duplicate copy of arguments and their values are used directly in the
parameter. |
The changes made in the procedure’s variable will
affect the variables used at calling module. |
It does not make any effect on values of variable
which are passed to a procedure even they are changing in the procedure. |
By default, the value is passed by reference. |
To pass the argument by value, variable is enclosed
in parenthesis |
Local Variable
A variable which is defined in a module and is not
accessible to any other module is called local variable.
The value of local variable is destroyed when
execution of module is over.
Global variable
Variables
which are declared outside the procedure and whose values can be accessed from
any procedure or module are called global variables.
The value of global variable is not destroyed during
the execution of program.
DIM SHARED, COMMON SHARED statement is used to declare
global variable.
DIM SHARED statement
The DIM SHARED statement makes the variable accessible
or global to all the modules. It is used in the main module.
COMMON SHARED statement
The COMMON SHARED
statement is a non executable statement that declares variables as global, so
that they can be shared between main module and sub modules. It appears only in
the main module.
SHARED
The SHARED statement is used to share variables or
part of a module among a module without making the variables global. It appears
only in the sub module.
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
/ Built-in Function [SQE 2074K]
Library
functions are built-in or readymade functions provided by QBASIC. E.g. MID$( ),
LEN( ), SQR( ) etc.
LEN ( )
function returns the number of characters in a string or the number of bytes
required to store a variable.
What is the function of MOD in Qbasic.
Ans: MOD returns
the remainder of a division between two numbers.
What is the function of INT() in QBASIC
programming?
Ans: The INT()
function in QBASIC returns the integer portion of a number by removing the
decimal part.
User defined
function
Function
which is defined by the user according to the need is called user defined
function.
(3.2) File
processing (file handling)
File
The collection of different data or information or
instructions, which is stored in secondary storage devices under a unique file
name, is known as file
File handling
File handling is a process to create a data file,
write data to the data file and read data from the specified data file.
Data file
Data file is a collection of data such as name, address,
class, etc. required for data processing.
The different types of
data file are:
a)
Sequential Access files - Sequential Access to a data files means
that the computer system reads or writes information to the file sequentially,
starting from the beginning of the file and proceeding step by step.
b)
Random access files - Random Access to a file means that the
computer system can read or write information anywhere in the data file.
Program
File
The set of instruction written in a computer language
for data processing under unique file name is known as program file.
Mode of data file
Mode
of data file means opening a sequential file for one of the three modes of
operation like output mode, input mode and append mode.
Modes
of operation for opening a sequential file
a)
Output Mode: It is used to create a new
sequential data file and write data in it.
If the file already exists its current contents will be destroyed. It starts writing
data always from the beginning of the file (BOF).
b)
Input Mode: It is used to read / display
data or information from the existing sequential data file.
c)
Append Mode: It is used to add more records
in the existing sequential file..
If the specified file does not exist APPEND mode creates it. It starts adding
of data always from the end of the file (EOF).
Which
mode is used to add data items into the already existed data file in QBASIC?
APPEND mode
is used to add data items into the already existed data file in QBASIC
Which
mode is used to read and display data from an existing sequential data file?
-Input Mode
File number
The number assigned to a
file in order to identify it during processing is called file number.
Write
down the functions of:
OPEN
statement: It opens a sequential file for one
of the three possible operations (reading, writing, appending).
WRITE
statement: It writes data to a sequential file. It inserts commas between the data items. It encloses strings
in double quotation marks.
PRINT#: It writes data to a sequential
file It adds spaces between data items while storing data. It
does not enclose strings in double quotation marks.
CLOSE
statement : It
closes one or all open files.
INPUT#
statement: It reads data items from a sequential
file and assigns them to variables.
EOF(
) function: It is used to check whether the
record pointer reaches at end of file or not.
LINE
INPUT statement: It reads an entire line without
delimiters from a sequential file to a string variable.
INPUT$
function: It returns a string of characters read
from the specified file.
NAME
statement : The NAME
statement changes the name
of a disk file or directory
KILL
statement : The KILL
statement deletes a file.
MKDIR
statement : It
creates
a new directory..
CHDIR
statement: It changes the current default
directory for the specified drive.
RMDIR
statement : It remove an existing empty directory.
FILES
statement: The FILES statement displays the list of files
residing on the specified disk.
SHELL: The SHELL statement executes a DOS
command.
SYSTEM : This command is used to close
QBASIC program window
INT
( ) : It rounds and returns the largest
integer less than or equal to a numeric expression.
PRINT
: Display result on screen.
MID$ ( )
: t is a string function
that returns the specified number of characters from the specified location of
string.
LEN ( ): Returns the number of characters in a string or
the number of bytes required to store a variable.
SQR ( )
: Returns the square root of a
numeric expression.
Qbasic Operators
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. |
What is the function of SQR in
Q-Basic?
The function of SQR in Q-Basic us to
calculate the square root of a given number.
No comments:
Post a Comment