Computer for SEE and NEB

It is a complete SEE and NEB solution for computer science. It includes Computer Fundamentals, Database (SQL), Programming in C QBASIC, CSS, JavaScript, and PHP for beginners.

Breaking

Post Top Ad

Your Ad Spot

Friday, February 4, 2022

Sequence Program using SUB....END SUB

 

Modular programming


Modular programming is the process of subdividing a computer program into separate subroutines.

The modules are also called procedures. Procedures are useful for implementation of the repeated tasks such as frequently used calculations. Using modules in the program, the coding is clean and easier to understand and maintain. QBASIC supports a modular programming. A module is an individual page or file which can be separately compiled.

Modules in Modular programming:

The modules are also called procedure in QBASIC. A program may have a number of modules used. There are two kinds of module in QBASIC modular programming. They are:

Main Module

Sub module


Procedures

Procedure is a independent manageable and block or part which is used to solve the specific problem. They are also called sub modules or sub-programs. Every procedure can be used to break program codes into manageable parts. Every procedure has a unique name and the list of variables that exchange the values from main module to the sub modules. Using of the procedure in any part of the program is called calling a procedure.

There are two types of procedures used in QBASIC. They are:

SUB procedure (SUB....END SUB)

FUNCTION procedure (FUNCTION......END FUNCTION)

 

SUB…….END SUB

Structure of SUB…..END SUB

DECLARE SUB sub_name(parameter)

Statement

…………..

CALL sub_name(parameter)

END

 

SUB sub_name(parameter)

Statement

………..

END SUB

 

Example:

WAP to input any two numbers in main module and display the average of given two numbers in sub module.

     




Sequence structure programming using SUB...........END SUB 

 1. WAP to input any two numbers and display their sum.

By calling parameter

Without calling parameter

DECLARE SUB add(a,b)

CLS

INPUT "Enter first no:-";a

INPUT "Enter second no:-";b

CALL add(a,b)

END

SUB add(a,b)

s=a+b

PRINT "Sum=";s

END SUB

 

DECALRE SUB add()

CLS

CALL add

END

 

SUB add

INPUT “Enter two no”;a,b

S=a+b

PRINT “Sum=”;s

END SUB

 

 2. WAP to get radius of circle and then print its area.  (SLC supplementary 2065)

DECLARE SUB area( )

CLS

CALL area

END

 

SUB area

INPUT "Enter the radius=";r

a=22/7*r^2

PRINT "Area of circle=";a

END SUB

 

3. WAP to input length and breadth from the user, calculate area and display it.

DECLARE SUB area(l,b)

INPUT "Enter length:-";l

INPUT "Enter breadth:-";b

CALL area(l,b)

END

SUB area (l,b)

a=l*b

PRINT "Area=";a

END SUB

 

4. WAP to input length, breadth, height. Calculate the area and volume and display them.

DECLARE SUB av(l,b,h)

CLS

INPUT "Enter length, breadth, height:";l,b,h

CALL av(l,b,h)

END

SUB av(l,b,h)

a=l*b

v=l*b*h

PRINT "Area:-";a

PRINT "Volume:-";v

END SUB

 

5. WAP to calculate the area of four walls. (SLC 2068) [Hints: area=2h(l+b)

DECLARE SUB area( )

CLS

CALL area

END

SUB area

INPUT “Enter length=”;l

INPUT “Enter breadth=”;b

INPUT “Enter height=”;h

A=2*h*(l+b)

PRINT “Area of four walls=”;a

END SUB

 

6. WAP to get radius of a circle and then print its circumference. (SLC 2067 Supp.)

DECLARE SUB cur ()

CLS

CALL cur

END

SUB cur

INPUT "Enter radius of circle"; r

cu = (22 / 7) * 2 * r

PRINT "Circumference of the circle is="; cu

END SUB

 

7. Write a program to calculate the area of four walls. [Hint: Area=2H(L+B) (SEE 2073)

DECLARE SUB AREA (L, B, H)

CLS

INPUT “ENTER LENGTH”; L

INPUT “ENTER BREADTH”; B

INPUT “ENTER HEIGHT”; H

CALL AREA (L, B, H)

END

 

SUB AREA (L, B, H)

A = 2 * H * (L + B)

PRINT “AREA OF FOUR WALLS”; A

END SUB

 

8. WAP to find the area of circle. [Hints: Area =Ï€r2] (SLC 2071)

DECLARE SUB area()

CLS

CALL area

END

SUB area

INPUT “Enter a radous”;r

A=(22/7*r^2

PRINT “Area of circle”;a

END SUB

 

 

9. WAP to input temperature in centigrade and convert it into Fahrenheit. (Note: F=(9/5)*(c+32)

DECLARE SUB temp(c)

CLS

INPUT "Enter temperature in centigrade:-";c

CALL temp(c)

END

SUB temp(c)

f=((9/5)*(c+32)

PRINT "Temperature in Fahrenheit:-";f

END SUB

 

10. WAP  to calculate the area of four walls [Hint: Area=2h(l+b)]  

DECLARE SUB area( )

CLS

CALL area

END

SUB area

INPUT “Enter length=”;l

INPUT “Enter breadth=”;b

INPUT “Enter height=”;h

A=2*h*(l+b)

PRINT “Area of four walls=”;a

END SUB

 

11. WAP to calculate total surface area of a cube. Hints: TSA = 6L2

DECLARE SUB tsa()

CLS

CALL tsa

END

 

SUB tsa

INPUT “Enter length”;l

Ta=6*l*l

PRINT “Total surface area”;ta

END SUB

 

12. WAP to convert KM into to meter.

DECLARE SUB co ()

CLS

CALL co

END

 

SUB co

INPUT " Enter distance in KM"; km

m = km * 100

PRINT "Distance in Meter"; m

END SUB

 

13. WAP to convert dollar into Nepali currency.

DECLARE SUB rs ()

CLS

CALL rs

END

 

SUB rs

INPUT "Enter currency in doller "; d

r = d * 120

PRINT "Currency in nepali"; r

END SUB

 

 

 14. WAP to input seconds and convert it into hour, minutes and seconds.

DECLARE SUB time ()

CLS

CALL time

END

 

SUB time

INPUT "Enter time in seconds"; s

h = s \ 3600

mi = s MOD 3600

m = mi \ 60

s = mi MOD 60

PRINT "Hours", "Minutes", "Seconds"

PRINT h, m, s

END SUB

 

15. WAP to calculate the average of three numbers.

DECLARE SUB avg()

CLS

CALL avg

END

 

SUB AVG

INPUT “Enter three numbers”;a,b,c

Av=(a+b+c)/3

PRINT “Average”;av

END SUB

 

Also Read: Actual and formal parameters in modular programming of QBASIC for class 10 and SEE


16. WAP to calculate distance traveled by a body.  Where u is initial velocity t is time, s is distance and a is acceleration. (Hints: ut+1/2at2)

 

 DECLARE SUB dist ()

 CLS

 CALL dist

 END

SUB dist

INPUT "Enter initial velocity"; u

INPUT "Enter time"; t

INPUT "Enter Acceleration"; a

d = u * t + 1 / 2 * at ^ 2

PRINT "Distance="; d

END SUB


 

No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages