0% found this document useful (0 votes)
17 views4 pages

QBASIC Modular Programming Exercises

The document contains a series of programming exercises in QBASIC focused on modular programming concepts, including user-defined functions and sub procedures for calculating areas, volumes, and other geometric properties. It also explains the differences between local and global variables, as well as how to pass arguments by value and by reference. Additionally, it defines key programming terms such as parameters, arguments, and the main module in the context of modular programming.

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 DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views4 pages

QBASIC Modular Programming Exercises

The document contains a series of programming exercises in QBASIC focused on modular programming concepts, including user-defined functions and sub procedures for calculating areas, volumes, and other geometric properties. It also explains the differences between local and global variables, as well as how to pass arguments by value and by reference. Additionally, it defines key programming terms such as parameters, arguments, and the main module in the context of modular programming.

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 DOCX, PDF, TXT or read online on Scribd

Modular Programming Questions for Practice

1. WAP in QBASIC that asks the length, and breadth of a room and calculates its area and
perimeter. Create a user defined function to calculate the area and a sub program to calculate
the perimeter.
[Hint: Area = L˟B, p = 2(l+b)]

2. WAP in QBASIC that will ask the user to input the length, breadth and height of a room, then
use the sub procedure to calculate its volume and FUNCTION procedure to calculate its area
of four walls.
[Hint: Area = 2h(l+b), V = l*b*h]

3. WAP to find the average of three numbers by using FUNCTION…. END FUNCTION and
find the greatest number by using the SUB Procedure.

4. WAP to calculate the area of a circle using the function procedure and use the sub procedure
to calculate its circumference in QBASIC.
[Hint: A = ∏r2, C = 2∏r]

5. WAP that asks length, breadth and height of the room and calculates its area and volume.
Create a user defined function to calculate the area and a sub program to calculate volume.
[Hint: A = L*B, V = L*B*H]

6. WAP that allows users to enter the radius of a circle. Create a user defined function to find
area of a circle and sub procedure to find the volume of a cylinder.
[Hint: A = ∏r2, V = ∏r2h].

7. WAP that asks radius and height of a cylinder. Create user defined function to calculate total
surface area and sub program to calculate the volume of a cylinder.
[Hint: TSA = 2∏r(r + h), V = ∏r2h].
Modular Programming Questions for Practice

8. WAP that asks length, breadth of a room and calculate its area and perimeter. Create a user
defined function to calculate area and sub program to calculate perimeter.
[Hint: area = L*B, P = 2(l+b)].

9. WAP that ask the radius of circle. WAP to calculate the area and circumference of a circle.
Create a user defined function to calculate area and sub procedure to calculate circumference
of a circle.
[Hint: Area = ∏r2 , C = 2∏r]

[Link] to define a function procedure to display area of sphere and sub procedure to display
volume of sphere where user has to input the required data in the main module.
[Hint: Area of sphere = 4∏r , Volume = 4/3∏r3]
2
Modular Programming Questions for Practice

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.

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.

Main module
The top level controlling section or the entry point in modular programming is called main
module.
Modular Programming Questions for Practice

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.

You might also like