Sunday, January 14, 2024

3.2.1. QBASIC Modular Programming Solutions - SEE COMPUTER SCIENCE 2080

  3.2.1. QBASIC Modular Programming  Solutions - SEE COMPUTER SCIENCE 2080




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

 

DECLARE FUNCTION AREA(L,B)

DECLARE SUB VOL(L,B,H)

CLS
INPUT “Enter Length”; L

INPUT “Enter Breadth”; B

INPUT “Enter Height”; H

PRINT “Area of room=”; 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 of Room=”; V

END SUB

 

2. Write a program in QBASIC that allows the user to input length, breadth and height and then calculate the area of 4 walls. Hint: [A = 2H(L+B)]

 

DECLARE FUNCTION AREA (L, B, H)

CLS

INPUT “ENTER LENGTH”; L

INPUT “ENTER BREADTH”; B

INPUT “ENTER HEIGHT”; H

PRINT “AREA OF FOUR WALLS”; AREA(L, B, H)

END

 

FUNCTION AREA (L, B, H)

A = 2 * H * (L + B)

AREA = A

END FUNCTION

 

3. Write a program in QBASIC that allows user to enter radius of a circle. Create a user define function to find the area of circle and sub procedure to find volume of a cylinder. Hint: [A= pr2        v= pr2h]

DECLARE FUNCTION AREA (R)

DECLARE SUB VOL(R, H)

CLS
INPUT “Enter Radius”; R

INPUT “Height”; H

PRINT “Area of Circle=”; AREA(R)

CALL VOL(R, H)

END

 

 

FUNCTION AREA(R)

AREA = 3.14 * R ^ 2

END FUNCTION

 

SUB VOL (R, H)

V = 3.14 * R ^ 2 * H

PRINT “Volume of Cylinder=”; V

END SUB

 

4. Write a program in QBASIC that ask the radius of circle. Write a program to calculate the area and circumference of a circle. Create a user defined function first (r) to calculate area and sub procedure second (r) to calculate circumference of a circle.

Ans:

DECLARE FUNCTION FIRST (R)

DECLARE SUB SECOND (R)

CLS

INPUT "ENTER RADIUS"; R

PRINT " AREA OF A CIRCLE="; FIRST (R)

CALL SECOND (R)

END

 

FUNCTION FIRST (R)

FIRST = 3.14 * R ^ 2

END FUNCTION

 

SUB SECOND (R)

C = 2 * 3.14 * R

PRINT " CIRCUMFERENCE OF CIRCLE =" ; C

END SUB

 

5. Write a program in QBASIC to ask a number and display sum of digits by using FUNCTION..END FUNCTION. [4]

DECLARE FUNCTION SUM (N)

CLS

INPUT "ENTER ANY NUMBER"; N

PRINT "SUM OF DIGITS="; SUM(N)

END

 

FUNCTION SUM (N)

S = 0

WHILE N < > 0

R = N MOD 10

S = S + R

N = N \ 10

WEND

SUM = S

END FUNCTION

 

 

 

 

 

6.  Write a program in QBASIC 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=LxB], [p=2(L+B]]

 

DECLARE FUNCTION AREA (L,B)

DECLARE SUB PER(L,B)

CLS

INPUT “Enter Length”; L

INPUT “Enter Breadth”; B

PRINT “Area of rectangle=”; 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 “Perimeter of rectangle=”; P

END SUB

 

7.  Write a program in Q-Basic to find the perimeter of rectangle using Sub…END SUB procedure.

DECLARE SUB PER (L, B)

CLS

INPUT “ENTER LENGTH”; L

INPUT “ENTER BREADTH”; B

CALL PER (L, B)

END

 

SUB PER (L, B)

P = 2 * (L + B)

PRINT “PERIMETER OF RECTANGLE”; P

END SUB

 

8. Write a program in Q-Basic to find the largest among three number using FUNCTION procedure.

DECLARE FUNCTION GREAT (A, B, C)

INPUT “ENTER ANY THREE NUMBERS”; A, B, C

PRINT “THE GREATEST NUMBER IS”; GREAT (A, B, C)

END

FUNCTION GREAT (A, B, C)

IF A > B AND A > C THEN

G = A

ELSEIF B > A AND B > C THEN

G = B

ELSE

G = C

END IF

GREAT = G

END FUNCTION

 

9. Write a program to ask a number and display odd or even using FUNCTION procedure.

DECLARE FUNCTION CHECK$ (N)

CLS

INPUT “ENTER ANY NUMBER”; N

PRINT “THE GIVEN NUMBER IS “; CHECK$(N)

END

 

FUNCTION CHECK$ (N)

IF N MOD 2 = 0 THEN

CHECK$ = “EVEN NUMBER”

ELSE

CHECK$ = “ODD NUMBER”

END IF

END FUNCTION

10. Write a program to calculate Area of circle using Function procedure and use SUB procedure to calculate its circumference in Q-Basic.

[Hint: [A=pr2], [C=2pr]

 

DECLARE FUNCTION AREA (R)

DECLARE SUB CIR(R)

CLS

INPUT “Enter Radius”; R

PRINT “Area of circle=”; AREA(R)

CALL CIR(R)

END

FUNCTION AREA(R)

AREA = 22/7*R^2

END FUNCTION

 SUB CIR(L,B)

C=2*22/7*R

PRINT “Circumference of circle=”; C

END SUB

11. Write a program in QBASIC that will asks the user to input length, breadth and height of a room then use SUB procedure calculate its volume and FUNCTION procedure to calculate its area of four walls.

DECLARE SUB VOL(L,B,H)

DECLARE FUNCTION AREA(L,B,H)

CLS

INPUT “Enter length”; L

INPUT “Enter breadth”; B

INPUT ”Enter height”; H

CALL VOL(L, B, H)

PRINT “Area of four walls=”; AREA(L, B, H)

END
SUB VOL(L, B, H)

V=L*B*H

PRINT “Volume of room”; V

END SUB

 FUNCTION AREA(L, B, H)

AREA=2*H*(L+B)

END

12.  Write a program to check whether input number is negative, positive or zero using FUNCTION procedure. [4]

DECLARE FUNCTION CHECK$ (N)

CLS

INPUT “ENTER ANY NUMBER”; N

PRINT “The given number is “; CHECK$(N)

END

FUNCTION CHECK$ (N)

IF N > 0 THEN

CHECK$ = “POSITIVE NUMBER”

ELSEIF N < 0 THEN

CHECK$ = “NEGATIVE NUMBER”

ELSE

CHECK$ = “ZERO”

END IF

END FUNCTION

 

13. Write a SUB program to print series: 1,1, 2, 3, 5, 8, ........... up to 10th terms.             [4]

DECLARE SUB SERIES ()

CLS

CALL SERIES

END

 

SUB SERIES

A = 1

B = 1

FOR I = 1 TO 10

PRINT A;

C = A + B

A = B

B = C

NEXT I

END SUB

 

14. Write a program to calculate total surface area of a cylinder using function procedure and volume using sub procedure. [Hint: Total surface area-2pr(h+r), Volume=pr2h]   [4]

 DECLARE FUNCTION AREA(R, H)

DECLARE SUB VOL(R,H)

Cls

INPUT "Enter radius"; R

INPUT "Enter height"; H

PRINT AREA(R, H)

Call VOL(R, H)

END

 

FUNCTION AREA (R, H)

    AREA = 2 * 3.14 * R * (R + H)

END FUNCTION

 SUB VOL (R, H)

    V = 3.14 * R ^ 2 * H

    PRINT "Volume of cylinder"; V

END SUB

15. Write a program in QBASIC that asks principal, time and rate of interest and calculate simple interest and amount. Create a user- defined function to calculate simple interest and sub-program to calculate amount. Hint: [S1=P*T*R/1001, (A=P+SI)

DECLARE FUNCTION INTEREST(P,T,R)

DECLARE SUB AMOUNT(P,I)

CLS

INPUT "ENTER PRINCIAL"; P

INPUT "ENTER TIME"; T

INPUT "ENTER RATE"; R

PRINT "SIMPLE INTEREST="; INTEREST(P, T, R)

CALL AMOUNT(P, I)

END

FUNCTION INTEREST (P, T, R)

SHARED I

    I = P * T * R / 100

    INTEREST = I

END FUNCTION

SUB AMOUNT (P, I)

    A = P + I

    PRINT "AMOUNT="; A

END SUB

 

16. Write a program in QBASIC to display greater number using function procedure and smaller number using sub procedure among three numbers.      

 DECLARE FUNCTION GREAT(A,B,C)

DECLARE SUB SMALL(A,B,C)

CLS

INPUT"ENTER FIRST NUMBER";A

INPUT"ENTER SECOND NUMBER";B

INPUT"ENTER THIRD NUMBER";C

PRINT"THE GREATEST NUMBER IS: ";GREAT(A,B,C)

CALL SMALL(A,B,C)

END

 

FUNCTION GREAT(A,B,C)

IF A>B AND A>C THEN

GREAT=A

ELSEIF B>A AND B>C THEN

GREAT=B

ELSE

GREAT=C

END IF

END FUNCTION

 SUB SMALL(A,B,C)

IF A<B AND A<C THEN

PRINT"THE SMALLEST NUMBER IS ";A

ELSEIF B<A AND B<C THEN

PRINT"THE SMALLEST NUMBER IS ";B

ELSE

PRINT"THE SMALLEST NUMBER IS ";C

END IF

END SUB 

 

17. Write a program in QBasic that ask the radius and height of a cylinder and calculate the volume and curve surface area. Create a user-defined function to calculate volume and sub-procedure to calculate curve surface area of a cylinder. [Hints: V=Ï€r2h, CSA=2Ï€rh]

Ans.

DECLARE FUNCTION VOL(R,H)

DECLARE SUB CSA(R,H)

CLS

INPUT “ENTER THE RADIUS”;R

INPUT “ENTER THE HEIGHT”;H

PRINT “THE VOLUME OF CYLINDER IS ”;VOL(R,H)

CALL CSA(R,H)

END

 

FUNCTION VOL(R,H)

VOL = 3.14*R*R*H

END FUNCTION

SUB CSA(R,H)

C = 2*3.14*R*H

PRINT “THE CURVE SURFACE AREA OF CYLINDER IS ”; C

END SUB

 

18.  Write a QBASIC program that asks length, breadth, height and calculate Volume of Cuboid and Total Surface Area. Create a USER DEFINED FINCTION to calculate Volume of Cuboid and SUB-PROGRAM to calculate Total Suface of Area.

DECLARE FUNCTION VOL(L,B,H)

DECLARE SUB TSA(L,B,H)

CLS

INPUT”Enter length”;L

INPUT”Enter breadth”;B

INPUT”Enter height”;H

PRINT”Volume of cuboid= “;VOL(L,B,H)

CALL TSA(L,B,H)

END

 

FUNCTION  VOL(L,B,H)

VOL=L*B*H

END FUNCTION

 

SUB TSA(L,B,H)

T=2*(L*B+B*H+L*H)

PRINT”Total surface area of cuboid=”;T

END SUB

 

 

 

 

 

 

 

 

 

19. Write a program in QBASIC to define a function procedure to display the area of sphere and sub procedure to display the volume of sphere where user need to input radius in main module.

[Hint: Area = 4*3.14*R^2, Volume = 4/3*3.14*R^3]

 

DECLARE SUB AREA (R)

DECLARE FUNCTION VOL(R)

CLS

INPUT “Enter Radius”; R

CALL AREA(R)

PRINT “Volume of sphere=”; VOL(R)

END


SUB AREA(R)

A=4*3.14*R^2

PRINT “Area of sphere=”; A

END SUB

 

FUNCTION VOL(R)

VOL=4/3*3.14*R^3

END FUNCTION

20. Write a program in QBASIC that asks two numbers to find sum of squares of two numbers using SUB....END SUB program and average of two numbers using FUNCTION...END FUNCTION.

 

DECLARE SUB SQU(A, B)

DECLARE FUNCTION AVG(A, B)

CLS

INPUT “Enter first number”; A

INPUT “Enter Second number”; B

CALL SQU(A,B)

PRINT “Average of two numbers=”; AVG(A, B)

END

 

SUB SQU(A, B)

S=A^2 + B^2

PRINT “Sum of squares of two numbers=”; S

END SUB

 

FUNCTION AVG(A, B)

AVG=(A+B)/2

END FUNCTION

21. Write a program in QBASIC that allows user to enter a number and check whether the given number is prime or composite using sub procedure and check given number is even or odd using function procedure

 

DECLARE SUB PRIME (N)

DECLARE FUNCTION CHECKPO$ (N)

CLS
INPUT “Enter any number”; N

CALL PRIME (N)

PRINT “The given number is”; CHECKPO$(N)

END

 

SUB PRIME (N)

C = 0

FOR I = 1 TO N

IF N MOD I = 0 THEN C = C + 1

NEXT I

IF C = 2 THEN

PRINT "PRIME NUMBER"

ELSE

PRINT "COMPOSITE NUMBER"

END IF

END SUB

 

FUNCTION CHECKPO$ (N)

IF N MOD 2 = 0 THEN

CHECKPO$ = “EVEN NUMBER”

ELSE

CHECKPO$ = “ODD NUMBER”

END IF

END FUNCTION

 

 22. WAP to calculate area of rectangle using SUB...END SUB and arca of circle using FUNCTION...END Function.

 

DECLARE SUB AREA (L, B)

DECLARE FUNCTION ARE (R)

CLS

INPUT “ENTER LENGTH”; L

INPUT “ENTER BREADTH”; B

INPUT “ENTER RADIUS”; R

CALL AREA (L, B)

PRINT “AREA OF CIRCLE ”; ARE(R)

END

 

SUB AREA (L, B)

A = L * B

PRINT “AREA OF RECTANGLE=”; A

END SUB

 

FUNCTION ARE (L, B)

ARE = 3.14 * R ^ 2

END FUNCTION


 

 

23. Write a program in Q-BASIC that asks length, breadth and height of cuboid and calculate its lateral surface area and Volume. Create a Function procedure to calculate lateral surface area and sub procedure to calculate volume.) [Hint:- LSA = 2h (I+b) and V=lxbxh]

 

DECLARE FUNCTION LSA(L,B,H)

DECLARE SUB VOL(L,B,H)

CLS
INPUT “Enter Length”; L

INPUT “Enter Breadth”: B

INPUT “Enter Height”: H

PRINT “Lateral Surface Area of Cuboid=”; LSA(L, B, H)

CALL VOL(L, B, H)

END


FUNCTION LSA(L, B, H)

LSA=2*H*(L+B)

END FUNCTION

 

SUB VOL(L,B,H)

V=L*B*H

PRINT “Volume of Cuboid=”; V

END SUB

 

 24. Write a program to define a sub procedure to display the reverse of string input by user. And define function procedure to find out volume of cylinder where the necessary data has to be fed in main module. [Hint volume of Cylinder=pR2H] [4]

DECLARE SUB REV(A$)

DECLARE FUNCTION VOL(R, H)

CLS
INPUT “Enter any string”; A$

INPUT “Enter radius”; R

INPUT “Enter Height”; H

CALL REV(A$)

PRINT “Volume of Cylinder=”; VOL(R, H)

END

 

SUB REV(A$)

FOR I=LEN(A$) TO 1 STEP-1

B$=MID$(A$, I, 1)

C$=C$+B$

NEXT I

PRINT “Reversed String is”; C$

END SUB

 

FUNCTION VOL(R, H)

VOL=22/7*R^2*H

END FUNCTION

 

 

25. Write a program in QBASIC that asks radius of a circle and calculate its curved surface area and volume of hemisphere. Create a user - defined function to calculate volume of hemisphere and sub procedure to calculate curved surface area. [CSA=2pr2, Volume=  ]                                   4

 

DECLARE FUNCTION VOL(R)

DECLARE SUB CSA(R)

CLS

INPUT “Enter Radius”; R

PRINT “Volume of hemisphere=”; VOL(R)

CALL SCA(R)

END


FUNCTION VOL(R)

VOL = 2/3*22/7*R^2

END FUNCTION

 

SUB CSA(R)

C=2*22/7*R^2

PRINT “Curved surface area=”; C

END SUB

 

 

1 comment:

  1. sir i want to copy these and print out on paper please allow me to copy this

    ReplyDelete