Qbasic Solution
Qbasic Solution
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]
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.
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.
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)]
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.
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
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)
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.
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]
CLS
INPUT “ENTER LENGTH”; L
INPUT “ENTER BREADTH”; B
PRINT “AREA OF RECTANGLE=”; AREA(L,B)
CALL PER(L,B)
END
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]