0% found this document useful (0 votes)
72 views

Modular Programming in Qbasic

Modular programming in QBASIC divides programs into smaller subprograms or modules. This makes programs easier to understand, manage, and develop independently. QBASIC supports modular programming through subprograms and functions. Subprograms are created using SUB and END SUB statements, while functions are similar but return a value. Key advantages of modular programming include reusability of modules and independent development by different programmers.

Uploaded by

Desire Maharjan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views

Modular Programming in Qbasic

Modular programming in QBASIC divides programs into smaller subprograms or modules. This makes programs easier to understand, manage, and develop independently. QBASIC supports modular programming through subprograms and functions. Subprograms are created using SUB and END SUB statements, while functions are similar but return a value. Key advantages of modular programming include reusability of modules and independent development by different programmers.

Uploaded by

Desire Maharjan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

MODULAR PROGRAMMING IN QBASIC

1. What are modules?


When program becomes lengthy, its code becomes more and more complicated and difficult
to understand and manage. To remedy this, program is divided into smaller manageable program
blocks, which are called modules. When these modules combined, they form a complete solution to
the problem.
2. What are the two procedures that QBASIC support to divide program?
Two procedure used to divide program in QBASIC are Subprogram and Function.
3. What is modular programming (structured programming)?
Modular programming is a method of writing computer program that divides main program
into modules.
4. What is module?
A module is a block of statement that solves particular problem. A module may contain SUB
and FUNCTION procedure, as well as code not part of SUB or FUNCTION.
In modular programming, program contains main module and sub-modules under main
module.
To create a SUB (or subroutine):
a. Select the "Edit" menu.
b. Choose "New Sub".
c. Enter a name for the subroutine.
d. Type a list of commands between SUB and END SUB
Sample subroutine:
SUB GuessNum
favenum = 7
PRINT "What is my favorite number";
INPUT guess
IF guess = favenum THEN
PRINT "Congratulations, you are correct!”
ELSE
PRINT “Sorry, you’re wrong!”
END IF
END SUB
To use the subroutine:
a. Press F2.
b. Select "Untitled".
c. Press Enter to return to the "main module".
d. Use CALL to execute the subroutine.

A function is the same as a subroutine, except it returns a value. To return a value, set a
variable with the same name as the function.
Sample FUNCTION:
PRINT Add(10, 7)
FUNCTION Add (num1, num2)
Add = num1 + num2
END FUNCTION

ebces08092012 QBASIC Programming Page 1


MODULAR PROGRAMMING IN QBASIC

5. What are the advantages of Modular programming?


a. Single modules can be used in different places.
b. Different programmers can develop different program modules independently.
6. QBASIC is known as modular programming. Why?
QBASIC is known as modular programming because it uses the technique of “Divide and
Conquer” to solve a problem.
7. Differentiate between library function and user defined function
Library functions are functions provided by QBASIC. They are also termed as built-in
functions or standard functions. Two types of library functions are
a. string function
b. numeric function
User – defined functions are functions created by users.
8. Differentiate between Local variable and Global variable.
Local variables are declared inside the procedure are local by default. Their values are
protected from outside interference and have no effect on the variables outside the procedures.
Global variables are variables which can be accessed from any procedures or module.
9. What are parameters and arguments?
Parameters are variables that receive data (argument values) sent to the procedures
(subroutines and functions).
10. Differentiate between SHARED and COMMON SHARED.
SHARED statement is used in the subprogram to share the values of certain variable
between main module and subprogram.
A COMMON SHARED statement is used in main program to share variable list between main
program and all sub programs.
DECLARE - a non-executable statement that declares references to BASIC procedures and
invokes argument type checking
Syntax:
DECLARE {FUNCTION | SUB} name [([parameterlist])]
name is the name that will be used to call the procedure
parameterlist indicates the number and type of arguments that will be used to call the
procedure

ebces08092012 QBASIC Programming Page 2

You might also like