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

 

 

3.2.1. QBASIC File Handling Programming Solutions - SEE COMPUTER SCIENCE 2080

3.2.1. QBASIC File Handling Programming  Solutions - SEE COMPUTER SCIENCE 2080




 1. Write a program to store Roll no., Name, Class and Address of any five students. [SEE 2074]

OPEN "Student.dat" FOR OUTPUT AS #1

FOR I = 1 TO 5
INPUT "Enter Roll No."; r
INPUT "Enter Name"; n$
INPUT "Enter Class"; c
INPUT "Enter Address"; a$
WRITE #1, r, n$, c, a$
NEXT I
CLOSE #1
END

 

2. A sequential data file called “student.dat” contains same records under the field’s name, english, nepali and computer. Write a program to add some more records in the same sequential data file. [SLC 2068]

OPEN “student.dat” FOR APPEND AS #1

DO

CLS

INPUT “ENTER NAME”; N$

INPUT “ENTER MARKS IN ENGLISH”; E

INPUT “ENTER MARKS IN NEPALI”; N

INPUT “ENTER MARKS IN COMPUTER”; C

WRITE #1, N$, E, N, C

INPUT “DO YOU WANT TO CONTINUE”; CH$

LOOP WHILE UCASE$(CH$) = “Y”

CLOSE #1

END

 

3. A sequential data file “RECORD.DAT” and store Name, Address and Salary of employees of an office. WAP to add some more records in the data file “RECODR.DAT”. The program should terminate with user choice.

OPEN “RECORD.DAT” FOR APPEND AS #1

DO

CLS

INPUT “ENTER NAME”; N$

INPUT “ENTER MARKS IN ENGLISH”; E

INPUT “ENTER MARKS IN NEPALI”; N

INPUT “ENTER MARKS IN COMPUTER”; C

WRITE #1, N$, E, N, C

INPUT “DO YOU WANT TO CONTINUE”; CH$

LOOP WHILE UCASE$(CH$) = “Y”

CLOSE #1

END

 

4. Create a data file to store the records of few employees having Name, Address, Post, Gender and Salary fields. [SEE 2073]

OPEN “std.rec” FOR OUTPUT AS #1

TOP:

CLS

INPUT “Enter Name”; N$

INPUT “Enter Address”; A$

INPUT “Enter Post”; P$

INPUT “Enter gender”; G$

INPUT “Enter Salary”; S

WRITE #1, N$, A$, P$, G$, S

INPUT “Do you want to continue”; CH$

IF UCASE$(CH$)=”Y” THEN GOTO TOP

CLOSE #1

END

 

5. Create a sequential data file ’Price.dat’ to store item name, quantity and Rate also calculate total amount(total=Quantity X Rate).Program should terminate according to the user’s choice. 

OPEN “price.dat” FOR OUTPUT AS #1

TOP:

CLS

INPUT “Enter Item Name”; N$

INPUT “Enter Quantity”; Q

INPUT “Enter Rate”; R

T = Q * R

WRITE #1, N$, Q, R, T

INPUT “Do you want to continue”; CH$

IF CH$=”Y” OR CH$ = “y” THEN GOTO TOP

CLOSE #1

END

 

6. Create a sequential data file’post.dat’ to store name and marks of any three subjects also calculate total and percentages only for 15 students.

OPEN "post.dat" FOR OUTPUT AS #1

FOR I = 1 TO 15
INPUT "Enter Name"; n$
INPUT "Enter marks in any three subjects”; A, B, C
T = A + B + C

P = T / 3

WRITE #1, n$, A, B, C, T, P

NEXT I
CLOSE #1
END

 

7. Store SIDNO, name, address and Telephone number of five students and display the records on monitor in sequential data file “STDINFO”

OPEN "STDINFO.DAT" FOR OUTPUT AS #1

FOR I = 1 TO 5

    CLS

    INPUT "ENTER NAME"; N$

    INPUT "ENTER ADDRESS"; A$

    INPUT "ENTER TELEPHONE"; T#

    WRITE #1, N$, A$, T#

NEXT I

CLOSE #1

OPEN "STDINFO.DAT" FOR INPUT AS #1

CLS

FOR I = 1 TO 5

    INPUT #1, N$, A$, T#

    PRINT N$, A$, T#

NEXT I

CLOSE #1

END

 

8. A sequential data file “Address.inf” contains serial no, name, address, telephone and email_id.WAP to record as many records as the user wants. The serial number should be generated automatically like 5001,5003,5005.

OPEN " Address.inf " FOR OUTPUT AS #1

DO

CLS

C = 5001

INPUT “ENTER NAME”; N$

INPUT “ENTER ADDRESS”; A$

INPUT “ENTER TELEPHONE”; T#

INPUT “ENTER EMAIL”; E$

    WRITE #1, C, N$, A$, T$, E$

C = C + 2

INPUT “DO YOU WANT TO CONTINUE (Y / N)”; CH$

LOOP WHILE UCASE$(CH$) = “Y”

CLOSE #1

END

 

9. A Sequential data file called "SEE.DAT" has stored data under the field heading Symbol No., Name, English, Nepali, and Computer. Write a program to display all the information of those students whose marks in Computer is more than 80.

OPEN "SEE.DAT" FOR INPUT AS #1

CLS

WHILE NOT EOF (1)

    INPUT #1, A, B$, C, D, E

    IF E > 80 THEN PRINT A, B$, C, D, E

WEND

CLOSE #1

END

 

10. A sequential data file “STD.TXT” contains name and marks in three different subjects of some students. Write a program to display only fail student’s records assuming pass marks 40.

OPEN "STD.TXT" FOR INPUT AS #1

CLS

WHILE NOT EOF (1)

    INPUT #1, B$, C, D, E

    IF C < 40 AND D <40 AND E <40 THEN PRINT B$, C, D, E

WEND

CLOSE #1

END

 

11.Write a program which reads records from the file ”Result.DAT” having the fields name, and marks of three different subjects and display only those records whose percentage is greater than 60 and less than 80. Also count the total number of records presenting in that data files.

OPEN "STD.TXT" FOR INPUT AS #1

CLS

WHILE NOT EOF (1)

    INPUT #1, B$, C, D, E

A=A+1

T=C+D+E

P=T/3

    IF P > 60 AND P < 80 THEN  PRINT B$, C, D, E

WEND

PRINT “TOTAL NO. OF RECORDS=”; A

CLOSE #1

END

 

12. Write a program to read all the records from the data file “STUDENT.TXT” and display all the records where the fields name are unknown.

 

OPEN "STUDENT.TXT" FOR INPUT AS #1

CLS

WHILE NOT EOF (1)

   LINE INPUT #1, A$

    PRINT A$

WEND

CLOSE #1

END

 

13. A data file "pabson.txt" contains the records composed of the fields like school, principal, address, contact. Write a program in Qbasic to display records of the schools located in either Kathmandu or Palpa

OPEN "PABSON.TXT" FOR INPUT AS #1

CLS

WHILE NOT EOF (1)

  INPUT #1, A$, B$, C$, D

    IF UCASE$(C$) = “KATHMANDU” OR UCASE$(C$) = “PALPA” THEN PRINT A$, B$, C$, D

WEND

CLOSE #1

END

 

14. A data file “INFO.DAT” has numerous records in it with name, address age, and telephone numbers in it. Write a program to read all the records and print those with address “NEPAL” and age >15

OPEN "INFO.DAT" FOR INPUT AS #1

CLS

WHILE NOT EOF (1)

  INPUT #1, A$, B$, C, D

    IF UCASE$(B$) = “NEPAL” AND C >15 THEN PRINT A$, B$, C, D

WEND

CLOSE #1

END

 

15. A sequential data file called 'ADDRESS.DAT' contains NAME, AGE, CITY and TELEPHONE fields. Write a program to display all the contents of that data file.

OPEN "ADDRESS.DAT" FOR INPUT AS #1

CLS

WHILE NOT EOF (1)

  INPUT #1, A$, B, C$, D

    PRINT A$, B, C$, D

WEND

CLOSE #1

END

 

16. A data file “lib.txt” consists of book’s name, author’s name and price of books. Write a program to count and display the total number of records present in the file.

OPEN "LIB.TXT" FOR INPUT AS #1

CLS

WHILE NOT EOF (1)

  INPUT #1, A$, B$, C

D = D + 1

WEND

PRINT “TOTAL NUMBER OF RECORDS=”; D

CLOSE #1

END

 

17. Write a program in QBASIC to open a sequential data file “EMP.DAT”, which contains employees records: Name, address and phone number and display all the records as well as total number of records stored in the file. 

OPEN "LIB.TXT" FOR INPUT AS #1

CLS

WHILE NOT EOF (1)

  INPUT #1, A$, B$, C

PRINT A$, B$, C

D = D + 1

WEND

PRINT “TOTAL NUMBER OF RECORDS=”; D

CLOSE #1

END

 

18. A sequential data file named “nabil.txt” contains record of clients of a bank including depositor’s name, deposited amount, time and rate of interest. Wap to display detail of all depositors including simple interest.

OPEN "NABIL.TXT" FOR INPUT AS #1

CLS

WHILE NOT EOF (1)

  INPUT #1, N$, P, T, R

I=P*T*R/100

PRINT A$, B$, C, I

WEND

CLOSE #1

END

 

19. A sequential data file “SALARY.DAT” contains the information, Employee-Code, Employee-Name, Post, Basic-Salary. Write a program to display those records whose Basic-salary is between 10000 to 15000 and Post is ‘OFFICER’.

OPEN "SALARY.DAT" FOR INPUT AS #1

CLS

WHILE NOT EOF (1)

  INPUT #1, E,, N$, P$, S

    IF UCASE$(P$) = “OFFICER” AND S >= 10000 AND S>= 15000 THEN PRINT A$, B$, C, D

WEND

CLOSE #1

END

 

20. A data file name “EMP.DAT”, contains number of records having fields name, post and salary. Write a program to count total number of “Manager” in the data file. (hint: Manager is a post)

OPEN "EMP.DAT" FOR INPUT AS #1

CLS

WHILE NOT EOF (1)

  INPUT #1, N$, P$, S

    IF UCASE$(P$) = “MANAGER” THEN PRINT C = C + 1

WEND

PRINT “TOTAL NO.OF MANAGERS ARE”; C

CLOSE #1

END

 

21. A sequential data file “emp.dat” contains name, post and salary fields of information about employees. Write a program to display all the information of employees along with tax amount (also tax is 15% of salary).

OPEN "EMP.DAT" FOR INPUT AS #1

CLS

WHILE NOT EOF (1)

  INPUT #1, N$, P$, S

    T = 15 / 100 * S

PRINT N$, P$, S, T

WEND

CLOSE #1

END

 

22. A data file “Salary.Dat” contains the information of employee regarding their name, post and salary. Write a program to display all the information of employee whose salary is greater than 15000 and less than 40000.

OPEN "EMP.DAT" FOR INPUT AS #1

CLS

WHILE NOT EOF (1)

  INPUT #1, N$, P$, S

    IF S >= 15000 AND S <= 40000 THEN PRINT N$, P$, S

WEND

CLOSE #1

END

 

23. Write a program that reads the ”INFO.DAT” file that has several record such as name, address, gender, post, and salary .The program display those record whose sex is male and salary more than 10,000 and also the program counts the total number of records in that file.

OPEN "INFO.DAT" FOR INPUT AS #1

CLS

WHILE NOT EOF (1)

  INPUT #1, N$, A$, G$, P$, S

C = C + 1   

IF UCASE$(G$)=”M” AND S >= 10000 THEN PRINT N$, A$, G$, P$, S

WEND

PRINT “TOTAL NUMBER OF RECORDS=”; C

CLOSE #1

END

 

24. A sequential data file’post.dat’ has few records related to name, address, salary.WAP to display the records whose address begins with ‘S’ or ‘D’

OPEN "POST.DAT" FOR INPUT AS #1

CLS

WHILE NOT EOF (1)

  INPUT #1, N$, P$, S

A$ = UCASE$(LEFT$(N$,1))   

IF A$ = “S” OR A$ = “D” THEN PRINT N$, P$, S

WEND

CLOSE #1

END

 

25. Write a program to open a data file “record.dat” that contains name, address, date of birth, email and telephone number of some employees. Now display all those records whose date of birth is in current month.

 

OPEN "birth.dat" FOR INPUT AS #1

CLS

WHILE NOT EOF(1)

    INPUT #1, n$, d$, a$

    b$ = LEFT$(DATE$, 2)

    c = VAL(b$)

    e$ = LEFT$(d$, 2)

    f = VAL(e$)

    IF c = f THEN PRINT n$, d$, a$

WEND

CLOSE #1

END

 

26. A sequential data file “Record.dat” has few records related to name, address, post and DOB(mm/dd/yyyy). WAP to display the records of all those who were born between 1971 to 1999.

 

OPEN "RECORD.dat" FOR INPUT AS #1

CLS

WHILE NOT EOF(1)

    INPUT #1, n$, a$, p$, d$

    d$ = RIGHT$(d$, 4)

    c = VAL(b$)

        IF c >= 1971 and c<=1999 THEN PRINT n$, d$, a$

WEND

CLOSE #1

END

 

27. Write a Qbasic program that read the "EMP.DAT" file with Name, Address, Post and Salary columns from E: drive that has 500 records of employees and displays only its last 50 records.

OPEN "E:\EMP.DAT" FOR INPUT AS #1

CLS

FOR i = 1 TO 500

    INPUT #1, n$, a$, p$, s

    IF i >= 450 AND i <= 500 THEN PRINT n$, a$, p$, s

NEXT i

CLOSE #1

END

 

28. A sequential data file has 100 records having field name, class and roll number. Write a program to display from 50th to 60th records.

 

OPEN "ABC.DAT" FOR INPUT AS #1

CLS

WHILE NOT EOF (1)

  INPUT #1, N$, C, R

D = D + 1   

IF D >= 50 AND D <= 60 THEN PRINT N$, C, R

WEND

CLOSE #1

END

 

29. Write a program to display the first 10 records from a file named “resource.dat” having fields name, phone and email.

 

OPEN "RESOURCE.DAT" FOR INPUT AS #1

CLS

FOR I = 1 TO 10

  INPUT #1, N$, C, R

PRINT N$, C, R

NEXT I

CLOSE #1

END

 

30. A data file named “EMP.DAT” contains some records with the fields Code, Name, Post and Salary. Write a program to print odd position records of the data file.

OPEN "EMP.DAT" FOR INPUT AS #1

CLS

WHILE NOT EOF (1)

  INPUT #1, C, N$, P$, S

D = D + 1   

IF MOD 2 = 1 THEN PRINT C, N$, P$, S

WEND

CLOSE #1

END

 

31. A sequential data file named “abc.dat” has several records having fields name, roll and class. Write a program to copy all the records of class 10 into a newly created file new.dat.

 

OPEN "ABC.DAT" FOR INPUT AS #1

OPEN "COPY.DAT" FOR OUTPUT AS #1

CLS

WHILE NOT EOF (1)

  INPUT #1, N$, R, C

IF C = 10 THEN WRITE #2, N$, R, C   

WEND

CLOSE #1, #2

END

 

32. A data file named “record.dat” contains name, age and salary for n number of persons. Write a program to input a name to search data from a data file. If the data is not found, then display the message “Data not found in the list”.

OPEN “RECORD.DAT” FOR INPUT AS #1

CLS

INPUT “Enter name to be searched”; S$

FLAG=0

WHILE NOT EOF(1)

INPUT #1, N$, A$, S

IF UCASE$(S$)=UCASE$(N$) THEN

PRINT N$, A$, S

FLAG=1

END IF

WEND

IF FLAG=0 THEN PRINT “Data not found”

CLOSE #1

END

33. A sequential data file 'Student.dat' contains registration number, student name, address and date of birth of some students. Write a program that asks a user to input a registration number and displays the record of the particular registration if present.

OPEN “STUDENT.DAT” FOR INPUT AS #1

CLS

INPUT “Enter registration no. to be searched”; S

FLAG=0

WHILE NOT EOF(1)

INPUT #1, R, N$, A$, D$

IF S = R THEN

PRINT R, N$, A$, D$

FLAG=1

END IF

WEND

IF FLAG=0 THEN PRINT “Data not found”

CLOSE #1

END

 

34. WAP that asks a post of the employee and displays his/her records from the sequential data file “XYZ.REC” having fields Name, Post, Dept and Salary.

OPEN “XYZ.REC” FOR INPUT AS #1

CLS

INPUT “Enter post to be searched”; S$

FLAG=0

WHILE NOT EOF(1)

INPUT #1, N$, P$, D$, S

IF UCASE$(S$)=UCASE$(P$) THEN

PRINT N$, P$, D$, S

FLAG=1

END IF

WEND

IF FLAG=0 THEN PRINT “Data not found”

CLOSE #1

END

 

35. Delete some records from “neps.dat” file where computer ask user to enter the record, which is to be deleted. (Fields are name, address, and telephone number)

 

OPEN “NEPS.DAT” FOR INPUT AS #1

OPEN “TEMP.DAT” FOR OUTPUT AS #1

CLS

INPUT “Enter name which is to be deleted”; D$

WHILE NOT EOF(1)

INPUT #1, N$, A$, T#

IF UCASE$(D$)<>UCASE$(N$) THEN

WRITE #2, N$, A$, T#

ELSE

PRINT “Deleted data=”; N$, A$, T#

END IF

WEND

CLOSE #1, #2

 KILL “NEPS.DAT”

NAME “TEMP.DAT” AS “NEPS.DAT”

END

 

36. A sequential data file “marks.dat” contains information such as student’s name, marks obtained in math, science and computer. Write a program that increase the marks of computer by 10 of those student who secured less than 40

OPEN "D:\PATIENT.DAT" FOR INPUT AS #1

OPEN "d:\TEMP.DAT" FOR OUTPUT AS #2

CLS

WHILE NOT EOF(1)

    INPUT #1, N$, A, B, C

    IF C > 40 THEN

        WRITE #2, N$, A, B, C

    ELSE

        C = C + 10

        WRITE #2, N$, A, B, C

         END IF

WEND

CLOSE

KILL "D:\PATIENT.DAT"

NAME "D:\TEMP.DAT" AS "D:\PATIENT.DAT"

END

 

37. A sequential data file “RECORD.DAT” contains different records under fields: name rollno., name, address and percentage. Write a program to edit a record and display both edited and unedited records on the screen to compare them side by side.

OPEN "D:\RECORD" FOR INPUT AS #1
OPEN "d:\TEMP.DAT" FOR OUTPUT AS #2
CLS
INPUT "ENTER ROLL NUMBER TO EDIT DATA"; E
FLAG = 0
WHILE NOT EOF(1)
INPUT #1, R, N$, A$, P
IF E <> R THEN
WRITE #2, R, N$, A$, P
ELSE
INPUT "ENTER ROLL NUMBER"; ER
INPUT "ENTER NAME"; EN$
INPUT "ENTER ADDRESS"; EA$
INPUT "ENTER PERCENTAGE"; EP
WRITE #2, ER, EN$, EA$, EP
FLAG = 1
END IF
WEND
IF FLAG = 0 THEN
PRINT "DATA NOT FOUND"
ELSE
PRINT "NON EDITED DATA"
PRINT "ROLL NUMBER= "; R
PRINT "NAME= "; N$
PRINT "ADDRESS= "; A$
PRINT "PERCENTAGE= "; P
PRINT "---------------"
PRINT "EDITED DATA"
PRINT "ROLL NUMBER: "; ER
PRINT "NAME: "; EN$
PRINT "ADDRESS: "; EA$
PRINT "PERCENTAGE: "; EP
END IF
CLOSE
KILL "D:\SALARY.DAT"
NAME "D:\TEMP.DAT" AS "D:\SALARY.DAT"
END