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

Saturday, February 24, 2024

QBASIC Long Question on FUNCTION and SUB procedure for SEE and grade 10

QBASIC Long Question on FUNCTION and SUB procedure for SEE and grade 10




Write a QBASIC program using FUNCTION and SUB procedure for SEE and grade 10 (It carries 4 marks)

1. New specification grid 2077

Write a program in QBASIC that asks length, breadth, and height of a room and calculates its area and volume. Create a user-defined function to calculate area and a 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.   Pabson Pre-board Exam 2079

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

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 "Palindrome"

ELSE

PRINT "Not palindrome"

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 the total number of vowel letters by using FUNCTION and count total consonant letters by using the 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 consonant 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 digits by using the SUB procedure and display input digits in reverse order by using the 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

 

17) Write a program in QBasic that ask the radius of a circle to calculate its area and circumference. Create a user-defined function to calculate area and a sub-program to calculate circumference. [Hints: a=Ï€r2, C=2Ï€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 = 3.14 * r ^ 2

END FUNCTION

 

SUB cir (r)

c = 2 * 3.14 * r

PRINT "Circumference: "; c

END SUB

 

 18) SEE 2079 (2023)

Write a program in QBasic that ask the radius of a circle to calculate its area and circumference. Create a user-defined function to calculate area and a sub-program to calculate circumference. [Hints: a=Ï€r2, C=2Ï€r] 4

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 = 3.14 * r ^ 2

END FUNCTION

 

SUB cir (r)

c = 2 * 3.14 * r

PRINT "Circumference: "; c

END SUB

 

19)   SEE Grade Promotion Exam 2079(2023

Write a program in QBASIC that asks length and breadth of a room and calculate its area and perimeter. Create a user-define FUNCTION to calculate area and SUB program to calculate perimeter. [Hint: A=L × B, P=(L+B)]

DECLARE FUNCTION area(L,B)

DECLARE SUB peri(L,B)

CLS

INPUT "Enter length:";l

INPUT "Enter breadth:";b

a=area(L,B)

PRINT "Area of a room:";a

END

 

FUNCTION area(L,B)

area=l*b

END FUNCTION

 

SUB area(L,B)

p=2*(l+b)

PRINT "Perimeter of rectangle:";p

END SUB

 

20)  Npabson Pre-board Exam 2080

Write a program in QBASIC to find out the sum of three numbers using the SUB procedure and the average of three numbers using the FUNCTION procedure.

DECLARE SUB sum (a, b, c)
DECLARE FUNCTION average (a, b, c)
CLS
INPUT "Enter three numbers: "; a, b, c
CALL sum(a, b, c)
PRINT average(a, b, c)
END

FUNCTION average (a, b, c)
average = (a + b + c) / 3
END FUNCTION

SUB sum (a, b, c)
s = a + b + c
PRINT "sum"; s
END SUB

 

21)  Pabson  Pre-board Exam 2080

Write a program in QBASIC to input a radius, and create a user-defined function to calculate the volume of the hemisphere and total surface area (TSA) of the sphere using the SUB procedure. 

DECLARE FUNCTION volume (r)

DECLARE SUB tsa (r)

CLS

INPUT "Enter radius:"; r

PRINT volume(r)

CALL tsa(r)

END

 

SUB tsa (r)

t = 4 * 22 / 7 * r ^ 2

PRINT "Total surface area: "; t

END SUB

 

FUNCTION volume (r)

volume = 2 / 3 * 22 / 7 * r ^ 3

END FUNCTION

 

22) Write a program in QBASIC to check whether the input number is prime or composite by using the FUNCTION procedure and display the factorial of the input number by using the SUB procedure.

DECLARE SUB fact (n)

DECLARE FUNCTION prime$ (n)

CLS

INPUT "Enter any number:"; n

CALL fact(n)

PRINT "The number is : "; prime$(n)

END

 

SUB fact (n)

f = 1

FOR x = 1 TO n

f = f * x

NEXT

PRINT "Factorial no="; f

END SUB

 

FUNCTION prime$ (n)

FOR x = 1 TO n

IF n MOD x = 0 THEN c = c + 1

NEXT

IF c = 2 THEN

prime$ = "prime"

ELSE

prime$ = "composite"

END IF

END FUNCTION


You may also Read:

Exploring Modular Programming in QBasic


 

 

No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages