Question and Answer on Modular Programming

xTechKR
Xorionic
4 min readJul 27, 2021

--

You might want to know what modular programming is, what are its different types, features, uses, and many more. If you’ve come here seeking answers to these questions then you have come to the right place. So without any further ado, let’s start discussing Question and Answer on Modular Programming right away.

1. What is modular programming?

Answer: Modular programming is a technique used to divide our program into many small logical, manageable, and functional modules or blocks. Every modular program has a main module with one or many sub-modules. The sub-module of a program is also called a procedure.

2. Write some advantages of modular programming.

Answer: The advantages of modular programming are:

  1. It makes writing programs easy for programmers as they can write the block or modules of the program independently.
  2. It reduces program codes and the same procedures can be used in different numbers of places at any time.
  3. It Increases the readability of the program.
  4. Programs written on Modular programming are easy to debug.
  5. Programs written on Modular programming are easy to design.

3. Why is QBasic called a modular programming language?

Answer: QBasic is called a modular programming language as It allows programmers to divide the program into manageable and functional modules with the help of SUB procedure and FUNCTION procedure.

4. What is a procedure in QBasic? List its types.

Answer: Procedure is an independent manageable and functional part or block which solves a particular problem given by the user independently. It is also known as Sub Module or a Sub Program.

The types of SUB modules in QBasic are:

SUB Procedure
FUNCTION Procedure

5. Define SUB Procedure with some of its important features.

Answer: A sub procedure is a small manageable and functional part of the program that performs specific tasks and does not return any value to the calling module. A CALL statement is used to call the sub procedure module. A SUB program is written with the SUB … END SUB statements.

Some of the important features of SUB Procedure are:

  1. It does not return any value.
  2. SUB procedure name can’t have a type declaration characters.
  3. SUB procedure name can’t be used as a variable.
  4. SUB procedure is called by the CALL statement.
  5. Arguments can be passed to the subprogram by reference and by the value method.

6. Define FUNCTION Procedure with some of its important features.

Answer: A FUNCTION procedure is a small manageable and functional part of a program that performs specific tasks and returns a value to the main program or calling module. A FUNCTION procedure is written with Function….END FUNCTION statements.

Some of the important features of FUNCTION Procedure are:

  1. Function procedure returns a value.
  2. Function procedure name has type declaration characters.
  3. A function name can be used in an expression.
  4. Function procedure can be recursive.
  5. Arguments can be passed to the sub procedure by reference or by value method.

7. Write the difference between SUB and FUNCTION procedure.

Answer:

SUB Procedure:

  1. SUB procedure does not return value to the calling module.
  2. SUB procedure name can’t be used in an expression.
  3. SUB procedure is called using the CALL statement

Function Procedure:

  1. A FUNCTION procedure returns a value to the calling module.
  2. FUNCTION name can be used in an expression.
  3. FUNCTION procedure can be called by statement method using print statement or expression method.

8. What are Arguments and Parameters?

Answer:

The consonant and variable enclosed in parenthesis of procedure call statement and that are supplied to a procedure are known as arguments. It is also known as actual parameters.

Variables in a sub module or a procedure module declaration that accept data or variables passed to them from the calling module are known as parameters. It is also known as formal parameters.

9. Write short notes on:

A. Arguments passing by reference.

Answer: Arguments are passed to a sub module by a reference which gives procedure access to the actual variable. In this method, the address of each variable is passed to the procedure. The changes made in the procedures variable will affect the value of arguments. It is the default mode of passing arguments.

Example: CALL TEST(A, B)

B. Passing by value method.

Answer: Arguments passed by the value method does not make any effect on the value of the variable which is passed to the procedure even they are changed in the procedure. To pass an argument by value method each argument is enclosed in individual parenthesis in the calling statements.

Example: CALL TEST ((A),(B))

C. Main Module and Sub Module.

Answer:

The top-level module which is located at the top of all the procedures is known as the main module.

Sub Module is a program that is written under the main module. A program may have one or more than one sub-modules.

D. Formal and Actual Parameters

Answer: Formal parameters are variables that are used to specify or declare types of data to be passed to the sub procedure either SUB or FUNCTION. Example: SUB VAR(A, B) or DECLARE SUB VAR(A, B)

Actual or real parameters are arguments that are used to pass the real value to the procedure. Actual parameters may be variables or consonants. Example: CALL VAR(A, B)

E. Local Variable and Global Variable

Answer: A variable that is defined in a module and is not accessible to any other modules is known as local variables. It is only accessible to the module where it is defined.

A variable in the main module which can be accessed from any module or procedure of a program is known as a global variable. Variables can be made global by declaring them with DIM SHARED, COMMON SHARED, or SHARED attribute.

--

--

xTechKR
Xorionic
Editor for

xTechKR is one of the emerging and leading consumer technology websites which has a mission to help people understand and use technology in a better way.