0% found this document useful (0 votes)
15 views

Qbasic Solution

The document contains multiple QBASIC programming tasks that involve user-defined functions and subroutines for various calculations, such as area, volume, perimeter, and reading from data files. Each task includes specific instructions for input and output, as well as hints for formulas to use. Additionally, there are examples of reading and filtering data from sequential files based on certain conditions.

Uploaded by

hw110988
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)
15 views

Qbasic Solution

The document contains multiple QBASIC programming tasks that involve user-defined functions and subroutines for various calculations, such as area, volume, perimeter, and reading from data files. Each task includes specific instructions for input and output, as well as hints for formulas to use. Additionally, there are examples of reading and filtering data from sequential files based on certain conditions.

Uploaded by

hw110988
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
You are on page 1/ 14

9. a.

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
b. A sequential data file called “Record.txt” has stored data under the field heading Roll No.,
Name, Gender, English, Nepali, Maths and Computer. Write a program to display all the
information of those students whose gender is “F” and obtained marks in computer is more
than 90.
OPEN “Record.txt” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, R, N$, G$, E, N, M, C
IF UCASE$(G$)=”F” AND C>=90 THEN
PRINT R; N$; G$; E; N; M; C
END IF
WEND
CLOSE #1
END
a) 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
b) Write a program to create a sequential data file “salary.dat” to store programmer’s name, salary
and post according to the need of the user.

OPEN “salary.dat” FOR OUTPUT AS #1


DO
CLS
INPUT “Enter name”; N$
INPUT “Enter Salary”; S
INPUT “Enter Post”; P$
WRITE #1, N$, S, P$
INPUT “Do you want to continue(Y/N)”; CH$
LOOP WHILE UCASE$(CH$)=”Y”
CLOSE #1
END
a) Write a program to calculate Area of circle using Function procedure and use SUB procedure to
calculate its circumference in Q-Basic. [Hint: [A= r2], [C=2 r]
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(R)
C=2*22/7*R
PRINT “Circumference of circle=”; C
END SUB

b) Students Name, Class, Section and Address are stored in a data file called “STUDENT.dat”. Write
a program to print all the records of students.

OPEN “student.dat” FOR INPUT AS #1


CLS
PRINT “Name”, “Class”, “Section”, “Address”
WHILE NOT EOF(1)
INPUT #1, N$, C, S$, A$
PRINT N$, C, S$, A$
WEND
CLOSE #1
END
a) 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 FUNCTION
b) A sequential data file called “Record.dat” has stored data under the field heading Roll No.,
Name, Gender, English, Nepali, Maths and Computer. Write a program to display all the
information of those students whose marks in English is more than 40.

OPEN "Record.dat" FOR INPUT AS #1


CLS
WHILE NOT EOF (1)
INPUT #1, R, N$, G$, E, NP, M, C
IF E > 40 THEN PRINT R, N$, G$, E, NP, M, C
WEND
CLOSE #1
END
9. ) Write a program in QBASIC that asks radius of a circle to calculate its area and circumference.
Create a user defined function to calculate area and sub program to calculate circumference.
2
[Hint A= r , C= 2 r]

DECLARE FUNCTION AREA (R)


DECLARE SUB CIR (R)
CLS
INPUT “ENTER RADIUS”; R
PRINT “AREA OF SQUARE ”; 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 OF CIRCLE”; C
END SUB
b) A sequential data file called “Record.dat” has stored data under the field headings: Roll No., Name,
Gender, English, Nepali, Maths and Computer. Write a program to display all the information
of those students whose marks in English is more than 40.

OPEN "Record.dat" FOR INPUT AS #1


CLS
WHILE NOT EOF (1)
INPUT #1, R, N$, G$, E, NP, M, C
IF E > 40 THEN PRINT R, N$, G$, E, NP, M, C
WEND
CLOSE #1
END

Write a program in Q-BASIC that asks length and 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: A=L×B,
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 A ROOM=”; AREA(L,B)
CALL PER(L,B)
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
Students' name, class, section and address are stored in a data file called "STUDENT.DAT" Write a program
to print all the records of students.
OPEN “STUDENT.DAT” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, N$, C, S$, A$
PRINT N$, C, S$, A$
WEND
CLOSE #1
END
1. 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
WHILEN<>0
R=NMOD10
S=S+R
N=N\10
WEND
SUM=S
END FUNCTION
2. Write a program in QBASIC to create a file "EMP.DAT" and store employees Name, Address, Salary
and Telephone number on the basis of user choice. [4]
OPEN “EMP.DAT” FOR OUPUT AS #1
DO
CLS
INPUT “ENTER NAME”; N$
INPUT “ENTER ADDRESS”; A$
INPUT “ENTER SALARY”; S
INPUT “ENTER TELEPHONE NUMBER”; T
WRITE #1, N$, A$, S, T
INPUT “DO YOU WANT TO CONTINUE”; CH$
LOOP WHILE UCASE$(CH$) = “Y”
CLOSE #1
END
9. Write a program to find area of four walls using FUNCTION... END perimeter of rectangle using
SUB...END SUB.
DECLARE FUNCTION AREA (L,B, H)
DECLARE SUB PER(L,B)
CLS
INPUT “Enter Length”; L
INPUT “Enter Breadth”; B
INPUT “Enter Height”; H
PRINT “Area of four walls=”; AREA(L,B, H)
CALL PER(L,B)
END
FUNCTION AREA(L,B, H)
AREA = 2*H*(L+B)
END FUNCTION
SUB PER(L,B)
P=2*(L+B)
PRINT “Perimeter of rectangle=”; P
END SUB

10. Write a program to read the data from the file "empinfo.txt" and display their NAME, EMPID, POST
whose POST is Clerk.

OPEN "empinfo.txt" FOR INPUT AS #1


CLS
WHILE NOT EOF (1)
INPUT #1, N$, E, P$
IF UCASE$(P$) = “CLERK” THEN PRINT N$, E, P$
WEND
CLOSE #1
END
9. a) Write a program in QBASIC to find out sum of three numbers using SUB procedure and average of
three numbers using FUNCTION procedure.
DECLARE SUB SUM(A, B, C)
DECLARE FUNCTION AVG(A, B, C) CLS
INPUT “Enter first number”; A INPUT
“Enter second number”; B INPUT
“Enter third number”; C CALL
SUM(A, B, C)
PRINT Average of three numbers=”; AVG(A, B, C)
END
SUB SUM(A, B, C)
S=A+B+C
PRINT “Sum of three numbers=”; S
END SUB
FUNCTION AVG(A, B, C)
AVG=(A+B+C)/3
END FUNCTION
(b) A sequential data file, "record.dat." contains several records with data items name, address, age, and
phone number. Write a program to display the records of students whose age is greater than or equal to 18.

OPEN “record.dat” FOR INPUT AS #1


CLS
PRINT “NAME”, “ADDRESS”, “AGE”, “PHONE NUMBER”
WHILE NOT EOF(1)
INPUT #1, N$, A$, AG, PN
IF AG>=18 THEN PRINT N$, A$, AG, PN
WEND
CLOSE #1
END
9. a. 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

b. Create a sequential data file to store name and mark obtained in English, Math and Science
subjects for few students.
OPEN “std.dat” FOR OUTPUT AS #1
DO
CLS
INPUT “Enter name”; N$

INPUT “Enter marks in English”; E INPUT “Enter marks in math”; M INPUT “Enter marks in science”; S
WRITE #1, N$, E, M, S

INPUT “Do you want to continue(Y/N)”; CH$


LOOP WHILE UCASE$(CH$)=”Y”
CLOSE #1
END
9. Write a program in QBASIC to input length and breadth of room and calculate its area using function
and perimeter using sub procedure. [Hint: Area = lxb.
Perimeter = 2(l+b)]

DECLARE FUNCTION AREA (L,B)


DECLARE SUB PERI(L,B)
CLS
INPUT “ENTER LENGTH”;L
INPUT “ENTER BREADTH”; B
PRINT “AREA OF RECTANGLE=”; AREA(L,B)
CALL PERI(L,B)
END
FUNCTION AREA(L,B)
AREA=L*B
END FUNCTION
SUB PERI(L,B)
P=2*(L+B)
PRINT “PERIMETER OF RECTANGLE=”; P
END SUB
b) A sequential data file called "Records.dat" has stored data under the field heading Roll No., Name, Gender, English,
Nepali, Maths and Computer. Write a program to display all the records of students whose marks in computer is more
than 90.
OPEN “Records.dat” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, R, N$, G$, E, N, M, C
IF C>90 THEN PRINT R; N$; G$; E; N; M; C
WEND
CLOSE #1
END
. 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=πr2 h, 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

b. A sequential data file called "Emp.dat" has stored data under the field heading name, post and salary. Write a
program to display the records of those employees whose salary is more than Rs. 25000.
Ans.
OPEN “Emp.dat” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1,N$,P$,S
IF S > 25000 THEN PRINT N$,P$,S
WEND
CLOSE #1
END
9) 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= r 2 v= r2h]
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

10) A sequential data file “emp.dat” contains employee’s name, address, gender and salary. WAP to display all the information
of employees whose salary is more than Rs. 20,000
OPEN “emp.dat” FOR INPUT AS #1
CLS
WHILE NOT EOF(1) INPUT
#1, N$, A$, G$, S
IF S>20000 then PRINT N$, A$, G$, S WEND
CLOSE #1
END
a) WAP in QBASIC to print circumference of a circle using SUB and volume of a cylinder using FUNCTION (4)

DECLARE SUB CIR (R)


DECLARE FUNCTION VC (R, H)
CLS
INPUT "Enter radius"; R
INPUT "Enter Height"; H
CALL CIR(R)
X=VC (R, H)
PRINT "Volume of cylinder is "; X
END
SUB CIR(R)
C=2*22/7 R
PRINT "Circumference of a circle is"; C
END SUB
FUNCTION VC(R, H)
VC=22/7*R^2*H
END FUNCTION
A sequential data file “Employee.dat” has some records with fields serial number, name, Address, post and
salary for the number of employees. Write a program to display all the records of those employee's whose
salary is more than Rs 50000.

OPEN "Employee.dat" FOR INPUT AS #1


CLS
WHILE NOT EOF (1)
INPUT #1, SN, N$, AD$, P$, S
IF S > 50000 THEN
PRINT SN, N$, AD$, P$, S
END IF
WEND
CLOSE #1
END
10. Write a program to update the rate by increasing 10% from a sequential data file
"Data.dat" that store item name, rate and quantity.
OPEN "DATA.DAT" FOR INPUT AS#1
OPEN "TEMP.DAT" FOR OUTPUT AS #2
CLS
PRINT "DATA UPDATED BY INCREASING 10%" PRINT "ITEM NAME", "RATE", "QUANTITY"
WHILE NOT EOF (1) INPUT #1, N$, R, Q

R1=R+10/100*R WRITE #2, N$, R1, Q


WEND CLOSE #1, #2 KILL "DATA.DAT"
NAME "TEMP.DAT" AS "DATA.DAT"
END
11. a) 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
b) A sequential data file" records.dat" contains S.NO., Name, Address, Telephone No and
Email Address. WAP to count and display those records whose email address ends in "yahoo.com"
domain. Your display should be in tabular format having the fields Name, Address and Email
address only.

OPEN "records.dat" FOR INPUT AS #1


CLS
WHILE NOT EOF(1) INPUT #1, SN, N$, A$, T, E$
IF LCASE$(RIGHT$(E$,9))="yahoo.com" THEN PRINT N$,A$,E$
C=C+1
WEND

PRINT "TOTAL NO. OF HAVING YAHOO EMAIL ADDRESS ARE"; C


CLOSE #1
END
9 a) Write a QBASIC program that asks radius and calculate Area of Sphere and Volume of
Sphere. Create a USER DEFINED FUNCTION to calculate Volume of Sphere and SUB-
PROGRAM to calculate Area of Sphere. [Hint: AOS-4pir2 and VOS-4/3pir3
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
b) Write a QBASIC program that asks for Employee name and stores its reverse form into a
sequential data file "Reverse Txt". Make a provision so that user can input 10 records at each
program execution.
OPEN "REVERSE.TXT" FOR OUTPUT AS #1
CLS
FOR J=1 TO 10
INPUT "ENTER EMPLOYEE'S NAME"; N$
B$=" "
FOR I = LEN(N$) TO 1 STEP -1
B$ = B$ + MID$(N$, I, 1)
NEXT I
WRITE #1, B$
NEXT J
CLOSE #1
END
a) 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: [SI=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)
I=P*T*R/100
END FUNCTION
SUB AMOUNT (P, I)
A=P+I
PRINT "AMOUNT="; A
END SUB
) Write a sequential data file called "abc.dat" has stored data under the field heading Roll
No., Name, English, Nepali and Computer. Write a program to display all the information
of those students whose marks in computer is more than 45.
OPEN “abc.dat” FOR INPUT AS #1
CLS
WHILE NOT
EOF(1)
INPUT #1,
R,N$,E,NE,C
IF C>45 THEN PRINT R,
N$, E, NE, C WEND
CLOSE #1
END
9. Write a program in Q-BASIC that asks length, breadth & height of cuboid & calculate its
TSA & Volume. Create a Sub procedure to calculate TSA and function procedure to calculate
2
volume.) [ Hint:- TSA =2pr (r + h) & V= pr h]
DECLARE SUB TSA (R, H)
DECLARE FUNCTION VOL(R, H)
CLS
INPUT “Enter Radius”; R
INPUT “Enter Height”; H
CALL TSA(R, H)
PRINT “Volume of cuboid=”; VOL(R, H)
END

SUB TSA(R, H)
T=2*3.14*R*(R+H)
PRINT “Total Surface Area of Cuboid=”; T
END SUB

FUNCTION VOL(R, H)
VOL=3.14*R^2*H
END FUNCTION
b) A sequential datafile called 'STUDENT.DAT' contains NAME, CLASS,SECTION & ADDRESS
fields. Write a program to display all the contents of that datafile.

OPEN “STUDENT.DAT” FOR INPUT AS #1


CLS
PRINT “NAME”, “CLASS”, “SECTION”, “ADDRESS”

WHILE NOT EOF(1) INPUT #1, N$, C, S$, A$ PRINT N$, C, S$, A$

WEND CLOSE #1
END
9. a. 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
b. A sequential data file 'PRODUCT.DAT contains the information regarding product Id, Product
name, Date of manufacturing and Price of some products. Write a program to display all the
records deducting the price by 20%, where price is greater than or equal to Rs.1000. [4]

OPEN “PRODUCT.DAT” FOR INPUT AS #1


CLS
WHILE NOT EOF(1)
INPUT #1, I, N$, D$, P
IF P>=1000 THEN P=P-20/100*P
PRINT I, N$, D$, P
WEND
CLOSE #1
END
a) 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
b) Write a program to open data file tmp.dat which may contain name, address, phone no. and
salary. The program should allow user to add few records on it. (4)

OPEN “tmp.dat” FOR APPEND AS #1


DO
CLS
INPUT “Enter name”; N$
INPUT “Enter address”: A$
INPUT “Enter phone number”; P
INPUT “Enter salary”; S
WRITE #1, N$, A$, P, S
INPUT “Do you want to add more records(Y/N)”; CH$
LOOP WHILE UCASE$(CH$) = ”Y”
CLOSE #1
END
9. a) Write a program in QBASIC that asks for the length, breadth and height of a box. Create a user
defined function to find the volume of the box and sub procedure to find the total surface area of the
box. [Hint:
Vol=l x b x h ; Area=2(lb+bh+lh) [4]

DECLARE SUB TSAREA (L, B, H)


DECLARE FUNCTION VOLUME (L, B, H)
CLS
INPUT “ENTER LENGTH”; L
INPUT “ENTER BREADTH”; B
INPUT “ENTER HEIGHT”; H
CALL TSAREA(L, B, H)
PRINT “VOLUME OF CUBOID ”; VOLUME(L, B, H)
END

SUB TSAREA (L, B, H)


T=2*(L*B+B*H+H*L)
PRINT “TOTAL SURFACE AREA OF CUBOID ”; T
END SUB

FUNCTION VOLUME (L, B, H)


VOLUME=L*B*H
END FUNCTION
. Write a program to open a data file “Record.dat” which contains student’s name, class and address and
print only those students’ records whose name starts from an alphabet “A”. [4]

OPEN "Record.dat" FOR INPUT AS #1


CLS
WHILE NOT EOF (1)
INPUT #1, N$, C, A$
A$ = UCASE$(LEFT$(N$,1))
IF A$ = “A” THEN PRINT N$, C, A$
WEND
CLOSE #1
END
9. ) Write a program in QBASIC to input length and breadth of a rectangle and calculate area using
function-procedure and perimeter using sub-procedure.[4]

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

b) A sequential data file named “user.dat” has data under the fields [ Name, Age, Sex, Contact No
and Address ]. Write a program that displays the record of those users whose age is more than 35.
[4]

OPEN “user.dat” FOR INPUT AS #1


CLS
PRINT “Name”, “Age”, “Sex”, “Contact No.”, “Address”
WHILE NOT EOF(1)
INPUT #1, N$, A, S$, C, D$
IF A>35 THEN PRINT N$, A, S$, C, D$
WEND
CLOSE #1
END

You might also like