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

Monday, December 26, 2022

QBASIC program using FUNCTION and SUB Procedure

QBASIC program using FUNCTION and SUB Procedure

 

1. New specification grid  2077

Write a program in QBASIC that asks length, breadth and height of room and calculates its area and volume. Create a user-defined function to calculate area and sub-program to calculate volume. Hint: [A =LxB], [V=LxBxH]

DECLARE FUNCTION area (l, b)

DECLARE SUB vol (l, b, h)

CLS

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

PRINT "Area="; area(l, b)

CALL vol(l, b, h)

END

 

FUNCTION area (l, b)

area = l * b

END FUNCTION

 

SUB vol (l, b, h)

v = l * b * h

PRINT "volume"; v

END SUB

 

2. SEE 2078

Write a program in QBASIC that asks length, breadth of a room and calculates its area and perimeter. Create a user define function to calculate area and sub program to calculate perimeter. [Hint: [Area=L×B], P=2(L+B)]]     

Ans:

DECLARE FUNCTION area(l,b)

DECLARE SUB perimeter(l,b)

CLS

INPUT “Enter length and breadth”;l,b

PRINT area(l,b)

CALL perimeter(l,b)

END

 

FUNCTION area(l,b)

Area=l*b

END FUNCTION

 

SUB perimeter(l,b)

P=2*(l+b)

PRINT p

END SUB

 

3.  SEE Grade Promotion Exam 2078(2022)

Write a program to calculate the area of a circle using the function procedure and use the SUB procedure to calculate its circumference in QBASIC. [Hints: (A=Ï€r2) , (C=2Ï€r)]

DECLARE FUNCTION area(r)

DECLARE SUB cirm(r)

CLS

INPUT "Enter radius";r

PRINT area(r)

CALL cirm(r)

END

 

FUNCTION area(r)

area=3.14*r2

END FUNCTION

 

SUB cirm(r)

c=3.14*2*r

PRINT c

END SUB

 

4.  PABSON SEE Pre Board Examination 2078

Write a program in QBASIC that allows user to enter radius of a circle. Create a user define function to find area of circle and sub procedure to find volume of cylinder.  Hint: [A=Ï€r2, v=Ï€r2h] 

DECLARE FUNCTION area (r)

DECLARE SUB vol (r, h)

CLS

INPUT "Enter radius and height"; r, h

PRINT area(r)

CALL vol(r, h)

END

 

FUNCTION area (r)

a = 22 / 7 * r ^ 2

area = a

END FUNCTION

 

SUB vol (r, h)

v = 22 / 7 * r ^ 2 * h

PRINT v

END SUB

 

5.  Write a program in QBASIC to input radius of circle and calculate its area using function and circumference using sub procedure. [Area=pie×r2 and Circumference=2pie r] 

DECLARE FUNCTION area (r)

DECLARE SUB cir (r)

CLS

INPUT "enter radius"; r

PRINT "area"; area(r)

CALL cir(r)

END

 

FUNCTION area (r)

area = 22 / 7 * r * r

END FUNCTION

 

SUB cir (r)

c = 2 * 22 / 7 * r

PRINT "Circumference"; c

END SUB

 

6.   WAP in QBASIC to input radius of circle and calculate its area using FUNCTION…END FUNCTION and circumference using SUB…END SUB [Area=Ï€×r2 and Circumference=2Ï€r]      

DECLARE FUNCTION area (r)

DECLARE SUB cir (r)

CLS

INPUT "Enter radius"; r

PRINT area(r)

CALL cir(r)

END

 

FUNCTION area (r)

area = 22 / 7 * r ^ 2

END FUNCTION

 

SUB cir (r)

c = 2 * 22 / 7 * r

PRINT c

END SUB

 

7.   Write a program in QBASIC that allow user to enter the length and breadth of rectangle. Create a user define function to find the area of rectangle and sub procedure to find perimeter of rectangle.

DECLARE FUNCTION area (l, b)

DECLARE SUB per (l, b)

CLS

INPUT "enter length and breadth"; l, b

PRINT area(l, b)

CALL per(l, b)

END

 

FUNCTION area (l, b)

area = l * b

END FUNCTION

 

SUB per (l, b)

p = 2 * (l + b)

PRINT p

END SUB

 

8.   WAP to input any three numbers and calculate sum of three numbers by using FUNCTION procedure and average of three numbers by using SUB procedure.

DECLARE FUNCTION sum (a, b, c)

DECLARE SUB avg (a, b, c)

CLS

INPUT "Enter any three numbers"; a, b, c

PRINT "sum of two numbers"; sum(a, b, c)

CALL avg(a, b, c)

END

 

SUB avg (a, b, c)

av = (a + b + c) / 3

PRINT "Average of three numbers"; av

END SUB

 

FUNCTION sum (a, b, c)

sum = a + b + c

END FUNCTION

 

9.   WAP to input any three numbers and display the greatest number by using FUNCTION procedure and smallest number by using SUB procedure.

DECLARE SUB sm (a, b, c)

DECLARE FUNCTION gr (a, b, c)

CLS

INPUT "Enter any three numbers="; a, b, c

CALL sm(a, b, c)

PRINT "Greatest no="; gr(a, b, c)

END

 

FUNCTION gr (a, b, c)

IF a > b AND a > c THEN

g = a

ELSEIF b > c THEN

g = b

ELSE

g = c

END IF

gr = g

END FUNCTION

 

SUB sm (a, b, c)

IF a < b AND a < c THEN

S = a

ELSEIF b < c THEN

S = b

ELSE

S = c

END IF

PRINT "Smallest no="; S

END SUB

 


 

10.  WAP to input any string and display string in reverse order using FUNCTION and check palindrome or not using SUB procedure.

DECLARE SUB pal (w$)

DECLARE FUNCTION rev$ (w$)

CLS

INPUT "Enter any string="; w$

CALL pal(w$)

PRINT rev$(w$)

END

 

SUB pal (w$)

FOR x = LEN(w$) TO 1 STEP -1

m$ = m$ + MID$(w$, x, 1)

NEXT x

IF w$ = m$ THEN

PRINT "Palindrom"

ELSE

PRINT "Not palindrom"

END IF

END SUB

 

FUNCTION rev$ (w$)

FOR x = LEN(w$) TO 1 STEP -1

m$ = m$ + MID$(w$, x, 1)

NEXT x

rev$ = m$

END FUNCTION

 

11. WAP to input any number and check whether input number is odd or even by using SUB and check positive and negative by using FUNCTION.

DECLARE SUB oe (n)

DECLARE FUNCTION po$ (n)

CLS

INPUT "Enter any number="; n

CALL oe(n)

PRINT po$(n)

END

 

SUB oe (n)

IF n MOD 2 = 0 THEN

PRINT "Even number"

ELSE

PRINT "Odd number"

END IF

END SUB

 

FUNCTION po$ (n)

IF n > 0 THEN po$ = "Positive number"

IF n < 0 THEN po$ = "Negative number"

IF n = 0 THEN po$ = "Netural number"

END FUNCTION

12.       WAP to input any string and display vowel letters by using FUNCTION and consonant letters from using SUB procedure.

DECLARE FUNCTION vowel$ (w$)

DECLARE SUB cons (w$)

CLS

INPUT "Enter any string"; w$

PRINT vowel$(w$)

CALL cons(w$)

END

 

SUB cons (w$)

FOR x = 1 TO LEN(w$)

m$ = UCASE$(MID$(w$, x, 1))

SELECT CASE m$

CASE "A", "E", "I", "O", "U"

v = v + 1

CASE ELSE

PRINT m$;

END SELECT

NEXT

END SUB

 

FUNCTION vowel$ (w$)

FOR x = 1 TO LEN(w$)

m$ = UCASE$(MID$(w$, x, 1))

SELECT CASE m$

CASE "A", "E", "I", "O", "U"

v$ = v$ + m$

END SELECT

NEXT x

vowel$ = v$

END FUNCTION

 

13.       WAP to input any string and count total number of vowel letters by using FUNCTION and count total consonant letters  by using SUB procedure.

DECLARE FUNCTION vowel (w$)

DECLARE SUB cons (w$)

CLS

INPUT "Enter any string"; w$

PRINT "Total vowel letters"; vowel(w$)

CALL cons(w$)

END

 

SUB cons (w$)

FOR x = 1 TO LEN(w$)

m$ = UCASE$(MID$(w$, x, 1))

SELECT CASE m$

CASE "A", "E", "I", "O", "U"

v = v + 1

CASE ELSE

c = c + 1

END SELECT

NEXT

PRINT "Total consonent letters"; c

END SUB

 

FUNCTION vowel (w$)

FOR x = 1 TO LEN(w$)

m$ = UCASE$(MID$(w$, x, 1))

SELECT CASE m$

CASE "A", "E", "I", "O", "U"

v$ = v$ + m$

END SELECT

NEXT x

vowel = LEN(v$)

END FUNCTION

 

14.       WAP to calculate the sum of digit by using SUB procedure and display input digit in reverse order by using FUNCTION procedure.

 

DECLARE SUB sum (n)

DECLARE FUNCTION rev (n)

CLS

INPUT "Enter any number"; n

CALL sum(n)

PRINT rev(n)

END

 

FUNCTION rev (n)

s = 0

WHILE n <> 0

r = n MOD 10

s = s * 10 + r

n = n \ 10

WEND

rev = s

END FUNCTION

 

SUB sum (n)

WHILE n <> 0

r = n MOD 10

s = s + r

n = n \ 10

WEND

PRINT "Sum of digit="; s

END SUB

 

15) Write a program in QBASIC that will asks the user to input length, breadth and height. Create a user defined function to calculate surface area of four walls and write sub program to calculate surface area of box. [Hint: surface area of for walls=2H(L+B), surface area of box=lh+bh+lb]

DECLARE FUNCTION wall (l, b, h)

DECLARE SUB box (l, b, h)

CLS

INPUT "Enter length, breadth and height="; l, b, h

PRINT "Surface area of wall="; wall(l, b, h)

CALL box(l, b, h)

END

 

SUB box (l, b, h)

area = l * h + b * h + l * b

PRINT "Surface area of box"; area

END SUB

 

FUNCTION wall (l, b, h)

wall = 2 * h * (l + b)

END FUNCTION

 

16) Write a program 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*PI*R^2, Volume- V =4/3 * π * r3]

DECLARE FUNCTION area (r)

DECLARE SUB vol (r)

CLS

INPUT "Enter radius"; r

PRINT "Area of sphere"; area(r)

CALL vol(r)

END

 

FUNCTION area (r)

area = 4 * 22 / 7 * r ^ 2

END FUNCTION

 

SUB vol (r)

v = 4 / 3 * 22 / 7 * r ^ 3

PRINT "Volume of sphere"; v

END SUB

No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages