SLC COMPUTER SCIENCE FILE HANDLING QBASIC

1.        A sequential data file named”rec.dat”contains name,post and salary.  Write a program to display all the records for the employees whose Salary is more than 8000. [MAAF PRE SEND UP 2069 SET B]

è  OPEN “REC.DAT” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, N$, P$, S
IF S>8000 THEN PRINT N$, P$, S
WEND
CLOSE #1
END

2.        A sequential data file named “record.dat” contains first name, last name and age. Write a program to display all the records whose age is more than 60. [MAAF PRE SEND UP 2069 SET A]
è  OPEN “RECORD.DAT” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, FN$, LN$, A
IF A>60 THEN PRINT FN$, LN$, A
WEND
CLOSE #1
END

3.        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. [PABSON PRE SEND UP 2070]
è  OPEN “RECORD.DAT” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, N$, A$, D$, E$, T#
B$=LEFT$(D$, 2)
C=VAL(B$)
E$=LEFT$(DATE$, 2)
F=VAL(E$)
IF C=F THEN PRINT N$, A$, D$, E$, T#
WEND
CLOSE #1
END

4.        Write a program to display all records having salary less than 2500 from the data file “ADD.INF” having the field’s name, post and salary. [PABSON
PRE SEND UP 2066]
è  OPEN “ADD.INF” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, N$, P$, S
IF S<2500 THEN PRINT N$, P$, S
WEND
CLOSE #1
END

5.        WAP to 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). [NEPS PRE SEND UP 2066]
è  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

6.        Write a program to open a data file “STUDENT.DAT” that contains Name, Address, Telephone number and Parent’s Name of some students. Now display all those records whose Address is “LALITPUR”. [PABSON PRE SEND UP 2064]
è  OPEN “STUDENT.DAT” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, N$, A$, T#, PN$
IF UCASE$(A$) =”LALITPUR” THEN PRINT N$, A$, T#, PN$
WEND
CLOSE #1
END

7.        Create a sequential data file “std.dat” to store name and marks obtain in English, Maths and Science for a few students. [SLC MODEL QUESTION 2065]
è  OPEN “STD.DAT” FOR OUTPUT AS #1
DO
CLS
INPUT “Enter name”; N$
INPUT “Enter marks in English”; E
INPUT “Enter marks in Maths”; 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

8.        Create a sequential data file “HOTEL.DAT” to store customers name, address, and phone number. Program should terminate with user’s choice. [SLC MODEL QUESTION 2]
è  OPEN “HOTEL.DAT” FOR OUTPUT AS #1
DO
CLS
INPUT “Enter customers name”; CN$
INPUT “Enter address”; A$
INPUT “Enter phone number”; P#
WRITE #1, CN$, A$, P#
INPUT “Do you want to continue(Y/N)”; CH$
LOOP WHILE UCASE$(CH$) = “Y”
CLOSE #1
END

9.        A sequential data file “SALARY.DAT” contains the information, Employee-Code, Employee-Name, Post, and Basic-Salary. Write a program to display those records whose Basic-salary is in between 10000 to 15000 and Post is ‘OFFICER’. [SLC MODEL QUESTION 1]
è  OPEN “SALARY.DAT” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, EC, EN$, P$, S
IF B$>=10000 AND B$<=15000 AND UCASE$(P$)= “OFFICER” THEN
PRINT EC, EN$, P$, S
END IF
WEND
CLOSE #1
END

10.     A data file named “Staff.dat” contains staff name, Department, Post and Salary  of some staffs. Write a program to count and display total number of records    in a file. [PABSON SLC Q.EXAM 2069]
è  OPEN “STAFF.DAT” FOR INPUT AS #1
CLS
C=0
WHILE NOT EOF(1)
INPUT #1, N$, D$, P$, S
C=C+1
WEND
PRINT “Total number of records=”; C
CLOSE #1
END

11.     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. [SLC Q. PABSON 2070]
è  OPEN “NABIL.TXT” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, N$, A, T, R
I=(A*T*R)/100
PRINT N$, A, T, R, I
WEND
CLOSE #1
END

12.     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. [SLC P.QUAL. PABSON 2069]
è  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


Sunday, August 24, 2014

QBASIC FILE HANDLING PROGRAMS COMPUTER SCIENCE FOR SLC STUDENTS [COLLECTION]



[SPECIAL THANKS TO SARIKA SHRESTHA FOR SOLVING]

1.       Write a program to create a sequential data file “RESULT.DAT” to store name, address and marks obtained in 3 different subjects of students. [PABSON SEND UP 2066]
-          OPEN “RESULT.DAT” FOR OUTPUT AS #1
DO
CLS
INPUT “Enter name”; N$
INPUT “Enter address”; A$
INPUT “Enter marks in three different subjects”; M1, M2, M3
WRITE #1, N$, A$, M1, M2, M3
INPUT” Do you want to continue(Y/N)”;CH$
LOOP WHILE UCASE$(CH$)=”Y”
CLOSE #1
END

2.       Write a program to search and display only those record whose percentage is more than 60% from the data “RESULT.DAT” which contain Student’s Symbol number, Date of birth, Total Marks, Percentage and Division. [PABSON SEND UP 2067]
-          OPEN “RESULT.DAT” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, SN, D$, T, P, DA$
IF P>60 THEN PRINT SN, D$, T, P, DA$
WEND
CLOSE #1
END

3.       A data file name “STUDENT.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) [SLC SEND UP 2067]
-          OPEN “STUDENT.DAT” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, N$, P$, S
IF UCASE$(P$)=”MANAGER” THEN
C=C+1
END IF
WEND
PRINT “The total numbers of managers are”; C
CLOSE #1
END

4.       WAP to create sequential file “Person.DAT” containing information like Name, age, DOB and sex. Add records in this data file as per the users choice. [PABSON SLC 2064]
-          OPEN “PERSON.DAT” FOR OUTPUT AS #1
DO
CLS
INPUT” Enter name”; N$
 INPUT” Enter age”; A$
INPUT” Enter date of birth”; D$
INPUT” Enter Sex”; S$
WRITE #1, N$, A$, D$, S$
INPUT “Do you want to continue(Y/N)”; CH$
LOOP WHILE UCASE$(CH$)=”Y”
CLOSE #1
END

5.       Write a program to store SIDNO, name, address and Telephone number of five students and display the records on monitor in sequential data file “STDINFO”. [MAAF SLC SEND UP 2068]
-          OPEN “ STDINFO.DAT” FOR OUTPUT AS #1
DO
CLS
INPUT “Enter SID NO. “; N
INPUT “Enter name”; N$
INPUT “Enter address”; A$
INPUT “Enter telephone number”; T#
WRITE #1, N, N$, A$, T#
INPUT “Do you want to continue(Y/N)”; CH$
LOOP WHILE UCASE$(CH$)=”Y”
CLOSE #1
END

6.       Write a program to create a data file “SLC.dat” to store Name,Class,and marks in three subjects of 15 students. [PABSON SLC SEND UP 2068]
-          OPEN “SLC.DAT” FOR OUTPUT AS #1
FOR I = 1 TO 15
CLS
INPUT “Enter name”; N$
INPUT “Enter class”; C
INPUT “Enter marks in three different subjects”; M1, M2, M3
WRITE #1, N$,C,M1,M2,M3
NEXT I
CLOSE #1
END

7.       Write a program to create a data file “result.dat” to store name, address and obt. Marks in three different subjects of students. [SLC SEND UP 2069]
-          OPEN “RESULT.DAT” FOR OUTPUT AS #1
DO
CLS
INPUT “Enter name”; N$
INPUT “Enter address”; A$
INPUT “Enter marks in three different subjects”; M1, M2, M3
WRITE #1, N$, A$, M1, M2, M3
INPUT “Do you want to continue(Y/N)”; CH$
LOOP WHILE UCASE$(CH$)=”Y”
CLOSE #1
END

8.       Write a program to open a data file “STUDENT.DAT”that contains Name, Address, Telephone number and Parent’s Name of some students. Now display all those records whose address is “LALITPUR”. [JM SECOND TERM 2068]
-          OPEN “STUDENT.DAT” FOR INPUT AS #1
CLS
WHILE OT EOF(1)
INPUT #1, N$, A$, T#, PN$
IF UCASE$(A$)=”LALITPUR” THEN PRINT N$, A$, T#, PN$
WEND
CLOSE #1
END

9.       A data file”STUDENT.DAT” has several records in it.Write a program to read existing record from the file and display the total number or records.
-          OPEN “STUDENT.DAT” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
LINE INPUT #1, R$
C=C+1
WEND
PRINT “Total number of records=”; C
CLOSE #1
END

10.    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
DO
CLS
INPUT “Enter item name”; N$
INPUT “Enter quantity”; Q
INPUT “Enter rate”; R
T= Q*R
WRITE #1, N$, Q, R
INPUT “Do you want to continue(Y/N)”;CH$
LOOP WHILE UCASE$(CH$)=”Y”
CLOSE #1
END

11.    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
CLS
INPUT “Enter your name”; N$
INPUT “Enter marks in three different subjects”; M1, M2, M3
T=M1+M2+M3
P= T/3
WRITE #1, N$, M1, M2, M3, T, P
NEXT I
CLOSE #1
END

12.    A sequential data file’post.dat’ has few records related to name,address,salary and DOB (mm/dd/yyyy).WAP to:
                                             i.            Display all the records as well as count and display he total number of records also.
                                            ii.            Display the records whose address begins with ‘S’ or ‘D’

-          i)
-          OPEN “POST.DAT” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, N$, A$, S, D$
PRINT N$, A$, S, D$
C=C+1
WEND
PRINT “Total number of records=”; C
CLOSE #1
END
-           
-          ii)
-          OPEN “POST.DAT” FOR INPUT AS #1
CLS
WHILE NOT EOF(1)
INPUT #1, N$, A$, S, D$
B$=LEFT$(A$,1)
IF UCASE$(B$)=”S” OR UCASE$(B$)=”D” THEN PRINT N$, A$, S, D$
WEND
CLOSE #1
END

Comments

Write a menu drive QBASIC program to handle the following cases:
Case 1: to enter the data refer to Name, Address and telephone number tor 10 persons into a sequential data file " Address.Dat"
Case 2: to display the records from "addreess.dat"
Case 3: to quit the program
Unknown said…
A sequential data file called "patient.dat" that contains the patient's name, age, address, and phone number. WAP that count the total numbers of patients and display the total number.

Popular posts from this blog

PROGRAM TO FIND SQUARE, CUBE, SQUARE ROOT AND CUBE ROOT OF GIVEN NUMBER

PROGRAM TO DISPLAY SUM, PRODUCT, DIFFERENCE AND PRODUCT OF TWO / THREE NUMBERS

PALINDROME AND ARMSTRONG PROGRAMS